Timer for minimum interval and blcok worker after succesfull run

This commit is contained in:
mt 2019-11-05 10:47:23 +01:00
parent 3fe4599408
commit 41924ef7fc

View file

@ -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)