Skip to content

Commit

Permalink
Use existing enum for sync worker state instead of magic strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpfair committed Oct 5, 2013
1 parent 02fdc7e commit b89f6ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion sync_watchdog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from tapiriik.database import db
from tapiriik.sync import SyncStep
import os
import signal
import socket
Expand All @@ -13,7 +14,7 @@
alive = False

# Has it been stalled for too long?
if worker["State"] == "sync-list":
if worker["State"] == SyncStep.List:
timeout = timedelta(minutes=45) # This can take a loooooooong time
else:
timeout = timedelta(minutes=10) # But everything else shouldn't
Expand Down
11 changes: 5 additions & 6 deletions tapiriik/sync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def PerformUserSync(user, exhaustive=False, null_next_sync_on_unlock=False, hear
continue

if heartbeat_callback:
heartbeat_callback("sync-list")
heartbeat_callback(SyncStep.List)

if svc.ID in DISABLED_SERVICES:
excludedServices.append(conn)
Expand Down Expand Up @@ -351,18 +351,17 @@ def PerformUserSync(user, exhaustive=False, null_next_sync_on_unlock=False, hear
continue

if heartbeat_callback:
heartbeat_callback("sync-download")
# we won't need this now, but maybe later
heartbeat_callback(SyncStep.Download)
db.connections.update({"_id": {"$in": [x["Connection"]._id for x in activity.UploadedTo]}},
{"$addToSet": {"SynchronizedActivities": activity.UID}},
multi=True)

# this is after the above exit point since it's the most frequent case - want to avoid DB churn

if totalActivities <= 0:
syncProgress = 1
else:
syncProgress = max(0, min(1, processedActivities / totalActivities))

# This is after the above exit point since it's the most frequent case - want to avoid DB churn
db.users.update({"_id": user["_id"]}, {"$set": {"SynchronizationProgress": syncProgress}})

# download the full activity record
Expand Down Expand Up @@ -413,7 +412,7 @@ def PerformUserSync(user, exhaustive=False, null_next_sync_on_unlock=False, hear

for destinationSvcRecord in eligibleServices:
if heartbeat_callback:
heartbeat_callback("sync-upload")
heartbeat_callback(SyncStep.Upload)
destSvc = destinationSvcRecord.Service
try:
logger.info("\t\tUploading to " + destSvc.ID)
Expand Down

0 comments on commit b89f6ba

Please sign in to comment.