Skip to content

Commit da1b4e7

Browse files
committed
Support service-defined payloads for partial sync triggers
1 parent 1a2275e commit da1b4e7

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

sync_remote_triggers.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,25 @@ def celery_shutdown(**kwargs):
1919
close_connections()
2020

2121
@celery_app.task(acks_late=True)
22-
def trigger_remote(service_id, affected_connection_external_ids):
22+
def trigger_remote(service_id, affected_connection_external_ids_with_payloads):
2323
from tapiriik.auth import User
2424
from tapiriik.services import Service
2525
svc = Service.FromID(service_id)
26-
db.connections.update({"Service": svc.ID, "ExternalID": {"$in": affected_connection_external_ids}}, {"$set":{"TriggerPartialSync": True, "TriggerPartialSyncTimestamp": datetime.utcnow()}}, multi=True, w=MONGO_FULL_WRITE_CONCERN)
27-
affected_connection_ids = db.connections.find({"Service": svc.ID, "ExternalID": {"$in": affected_connection_external_ids}}, {"_id": 1})
28-
affected_connection_ids = [x["_id"] for x in affected_connection_ids]
26+
affected_connection_ids = list()
27+
28+
for item in affected_connection_external_ids_with_payloads:
29+
if isinstance(item, list):
30+
external_id, payload = item
31+
else:
32+
external_id = item
33+
payload = None
34+
update_connection_query = {"$set":{"TriggerPartialSync": True, "TriggerPartialSyncTimestamp": datetime.utcnow()}}
35+
if payload is not None:
36+
update_connection_query.update({"$push": {"TriggerPartialSyncPayloads": payload, "$slice": -90}})
37+
record = db.connections.find_and_modify({"Service": svc.ID, "ExternalID": external_id}, update_connection_query, w=MONGO_FULL_WRITE_CONCERN)
38+
if record:
39+
affected_connection_ids.append(record["_id"])
40+
2941
trigger_users_query = User.PaidUserMongoQuery()
3042
trigger_users_query.update({"ConnectedServices.ID": {"$in": affected_connection_ids}})
3143
trigger_users_query.update({"Config.suppress_auto_sync": {"$ne": True}})

tapiriik/services/Endomondo/endomondo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def UnsubscribeFromPartialSyncTrigger(self, serviceRecord):
244244

245245
def ExternalIDsForPartialSyncTrigger(self, req):
246246
data = json.loads(req.body.decode("UTF-8"))
247-
delta_external_ids = [int(x["id"]) for x in data["data"]]
247+
delta_external_ids = [(int(x["id"]), None) for x in data["data"]]
248248
return delta_external_ids
249249

250250
def DownloadActivity(self, serviceRecord, activity):

tapiriik/services/Strava/strava.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def UnsubscribeFromPartialSyncTrigger(self, serviceRecord):
230230

231231
def ExternalIDsForPartialSyncTrigger(self, req):
232232
data = json.loads(req.body.decode("UTF-8"))
233-
return [data["owner_id"]]
233+
return [(data["owner_id"], None)]
234234

235235
def PartialSyncTriggerGET(self, req):
236236
# Strava requires this endpoint to echo back a challenge.

tapiriik/sync/sync.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def _writeBackSyncErrorsAndExclusions(self):
295295

296296
if not self._isServiceExcluded(conn) and not self._shouldPersistServiceTrigger(conn):
297297
# Only reset the trigger if we succesfully got through the entire sync without bailing on this particular connection
298-
update_values["$unset"] = {"TriggerPartialSync": None}
298+
update_values["$unset"] = {"TriggerPartialSync": None, "TriggerPartialSyncPayloads": None}
299299

300300
try:
301301
db.connections.update({"_id": conn._id}, update_values)

0 commit comments

Comments
 (0)