From 41924ef7fc543b11ab770047d439652d94fd4936 Mon Sep 17 00:00:00 2001 From: mt Date: Tue, 5 Nov 2019 10:47:23 +0100 Subject: [PATCH] Timer for minimum interval and blcok worker after succesfull run --- sorteerhoed/central_management.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sorteerhoed/central_management.py b/sorteerhoed/central_management.py index 4299371..c851b41 100644 --- a/sorteerhoed/central_management.py +++ b/sorteerhoed/central_management.py @@ -33,6 +33,7 @@ class CentralManagement(): self.logger = logging.getLogger("sorteerhoed").getChild('management') self.debug = debug_mode self.currentHit = None + self.lastHitTime = None self.eventQueue = Queue() self.isRunning = threading.Event() @@ -165,12 +166,21 @@ class CentralManagement(): self.logger.info(f"SIGNAL: {signal}") if signal.name == 'start': self.makeHit() + self.lastHitTime = datetime.datetime.now() pass elif signal.name == 'hit.scanned': # TODO: wrap up hit & make new HIT self.currentHit.scanned_at = datetime.datetime.utcnow() self.server.statusPage.set('state', self.currentHit.getStatus()) + time_diff = datetime.datetime.now() - self.lastHitTime + to_wait = 150 - time_diff.total_seconds() + if to_wait > 0: + self.logger.warn(f"Sleep until next hit: {to_wait}s") + time.sleep(to_wait) + else: + self.logger.info(f"No need to wait: {to_wait}s") self.makeHit() + self.lastHitTime = datetime.datetime.now() elif signal.name == 'scan.start': pass elif signal.name == 'scan.finished': @@ -261,6 +271,10 @@ class CentralManagement(): self.makeHit() else: sqsHit.submit_hit_at = datetime.datetime.strptime(signal.params['event']['EventTimestamp'],"%Y-%m-%dT%H:%M:%SZ") + # Merijn: hier block ik de worker na succesvolle submit, om dubbele workers te voorkomen + self.mturk.create_worker_block(WorkerId=signal.params['event']['WorkerId'], Reason='Every worker can only work once on the taks.') + self.logger.warn("Block worker after submission") + self.store.saveHIT(sqsHit)