Minor docstring updates.

This commit is contained in:
Jannis Leidel 2017-05-10 11:53:33 +02:00
parent 4ae8a39a32
commit 72d895d93b
2 changed files with 4 additions and 2 deletions

View file

@ -71,7 +71,6 @@ class Camera(Polaroid):
def handle_worker(self, hostname_worker):
hostname, worker = hostname_worker
# was there an update in the last n seconds?
return self.WorkerState.objects.update_heartbeat(
hostname,
heartbeat=self.get_heartbeat(worker),

View file

@ -50,14 +50,17 @@ class WorkerStateQuerySet(ExtendedQuerySet):
def update_heartbeat(self, hostname, heartbeat, update_freq):
with transaction.atomic():
# check if there was an update in the last n seconds?
interval = Now() - timedelta(seconds=update_freq)
recent_worker_updates = self.filter(
hostname=hostname,
last_update__gte=interval,
)
if recent_worker_updates.exists():
obj = recent_worker_updates.latest()
# if yes, get the latest update and move on
obj = recent_worker_updates.get()
else:
# if no, update the worker state and move on
obj, _ = self.select_for_update_or_create(
hostname=hostname,
defaults={'last_heartbeat': heartbeat},