Timer for minimum interval and blcok worker after succesfull run
This commit is contained in:
parent
3fe4599408
commit
41924ef7fc
1 changed files with 14 additions and 0 deletions
|
@ -33,6 +33,7 @@ class CentralManagement():
|
||||||
self.logger = logging.getLogger("sorteerhoed").getChild('management')
|
self.logger = logging.getLogger("sorteerhoed").getChild('management')
|
||||||
self.debug = debug_mode
|
self.debug = debug_mode
|
||||||
self.currentHit = None
|
self.currentHit = None
|
||||||
|
self.lastHitTime = None
|
||||||
|
|
||||||
self.eventQueue = Queue()
|
self.eventQueue = Queue()
|
||||||
self.isRunning = threading.Event()
|
self.isRunning = threading.Event()
|
||||||
|
@ -165,12 +166,21 @@ class CentralManagement():
|
||||||
self.logger.info(f"SIGNAL: {signal}")
|
self.logger.info(f"SIGNAL: {signal}")
|
||||||
if signal.name == 'start':
|
if signal.name == 'start':
|
||||||
self.makeHit()
|
self.makeHit()
|
||||||
|
self.lastHitTime = datetime.datetime.now()
|
||||||
pass
|
pass
|
||||||
elif signal.name == 'hit.scanned':
|
elif signal.name == 'hit.scanned':
|
||||||
# TODO: wrap up hit & make new HIT
|
# TODO: wrap up hit & make new HIT
|
||||||
self.currentHit.scanned_at = datetime.datetime.utcnow()
|
self.currentHit.scanned_at = datetime.datetime.utcnow()
|
||||||
self.server.statusPage.set('state', self.currentHit.getStatus())
|
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.makeHit()
|
||||||
|
self.lastHitTime = datetime.datetime.now()
|
||||||
elif signal.name == 'scan.start':
|
elif signal.name == 'scan.start':
|
||||||
pass
|
pass
|
||||||
elif signal.name == 'scan.finished':
|
elif signal.name == 'scan.finished':
|
||||||
|
@ -261,6 +271,10 @@ class CentralManagement():
|
||||||
self.makeHit()
|
self.makeHit()
|
||||||
else:
|
else:
|
||||||
sqsHit.submit_hit_at = datetime.datetime.strptime(signal.params['event']['EventTimestamp'],"%Y-%m-%dT%H:%M:%SZ")
|
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)
|
self.store.saveHIT(sqsHit)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue