Skip to content

Commit 67e1bfa

Browse files
Merge pull request #94 from adorton-adobe/feature/start-end-sync
Add support for start and end sync signals
2 parents e379b4a + 3e42e26 commit 67e1bfa

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "umapi-client"
3-
version = "2.17.1"
3+
version = "2.18"
44
description = "Client for the User Management API (UMAPI) from Adobe - see https://adobe.ly/2h1pHgV"
55
readme = "README.md"
66
authors = ["Andrew Dorton <[email protected]>", "Dan Brotsky", "Danimae Vossen", "Kevin Bhunut"]

umapi_client/connection.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ def __init__(self,
173173
"actions-queued": 0}
174174
self.server_status = {"status": "Never contacted",
175175
"endpoint": self.endpoint}
176+
self.sync_started = False
177+
self.sync_ended = False
176178
if auth:
177179
self.auth = auth
178180
elif auth_dict:
@@ -369,7 +371,7 @@ def execute_multiple(self, actions, immediate=True):
369371
Execute multiple Actions (each containing commands on a single object).
370372
Normally, the actions are sent for execution immediately (possibly preceded
371373
by earlier queued commands), but if you are going for maximum efficiency
372-
you can set immeediate=False which will cause the connection to wait
374+
you can set immediate=False which will cause the connection to wait
373375
and batch as many actions as allowed in each server call.
374376
375377
Since any command can fill the current batch, one or more of your commands may be submitted
@@ -431,6 +433,16 @@ def execute_multiple(self, actions, immediate=True):
431433
raise BatchError(exceptions, queued, sent, completed)
432434
return queued, sent, completed
433435

436+
def start_sync(self):
437+
"""Signal the beginning of a sync operation
438+
Sends a header with the first batch of UMAPI actions"""
439+
self.sync_started = True
440+
441+
def end_sync(self):
442+
"""Signal the end of a sync operation
443+
Sends a header with the next batch of UMAPI actions"""
444+
self.sync_ended = True
445+
434446
def _execute_batch(self, actions):
435447
"""
436448
Execute a single batch of Actions.
@@ -467,10 +479,20 @@ def make_call(self, path, body=None, delete=False):
467479
:return: the requests.result object (on 200 response), raise error otherwise
468480
"""
469481
if body:
482+
extra_headers = {}
483+
# if the sync_started or sync_ended flags are set, send a header on this POST
484+
if self.sync_started:
485+
self.logger.info("Sending start_sync signal")
486+
extra_headers['Pragma'] = 'umapi-sync-start'
487+
self.sync_started = False
488+
elif self.sync_ended:
489+
self.logger.info("Sending end_sync signal")
490+
extra_headers['Pragma'] = 'umapi-sync-end'
491+
self.sync_ended = False
470492
request_body = json.dumps(body)
471493
def call():
472494
return self.session.post(self.endpoint + path, auth=self.auth, data=request_body, timeout=self.timeout,
473-
verify=self.ssl_verify)
495+
verify=self.ssl_verify, headers=extra_headers)
474496
else:
475497
if not delete:
476498
def call():

umapi_client/functional.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ def __init__(self, id_type=IdentityTypes.adobeID, email=None, username=None, dom
113113
else:
114114
Action.__init__(self, user=email, **kwargs)
115115

116+
def __str__(self):
117+
return "UserAction "+str(self.__dict__)
118+
119+
def __repr__(self):
120+
return "UserAction "+str(self.__dict__)
121+
116122
def create(self, first_name=None, last_name=None, country=None, email=None,
117123
on_conflict=IfAlreadyExistsOptions.ignoreIfAlreadyExists):
118124
"""

umapi_client/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
__version__ = "2.17.1"
21+
__version__ = "2.18"

0 commit comments

Comments
 (0)