def check_thread(): while True: try: cur_timestamp = utils.now() spec = { 'ttl_timestamp': {'$lt': cur_timestamp}, 'state': {'$ne': COMPLETE}, } for task_item in task.iter_tasks(spec): random_sleep() response = task.Task.collection.update({ '_id': task_item.id, 'state': {'$ne': COMPLETE}, 'ttl_timestamp': {'$lt': cur_timestamp}, }, {'$unset': { 'runner_id': '', }}) if response['updatedExisting']: run_task(task_item) except: logger.exception('Error in task check thread', 'runners') yield interrupter_sleep(settings.mongo.task_ttl)
def check_thread(): while True: try: cur_timestamp = utils.now() spec = { 'ttl_timestamp': { '$lt': cur_timestamp }, 'state': { '$ne': COMPLETE }, } for task_item in task.iter_tasks(spec): random_sleep() response = task.Task.collection.update( { '_id': task_item.id, 'state': { '$ne': COMPLETE }, 'ttl_timestamp': { '$lt': cur_timestamp }, }, {'$unset': { 'runner_id': '', }}) if response['updatedExisting']: run_task(task_item) except: logger.exception('Error in task check thread', 'runners') yield interrupter_sleep(settings.mongo.task_ttl)
def check_thread(): collection = mongo.get_collection('task') while True: cur_timestamp = datetime.datetime.utcnow() spec = { 'ttl_timestamp': {'$lt': cur_timestamp}, } for task_item in task.iter_tasks(spec): random_sleep() response = task.Task.collection.update({ '_id': bson.ObjectId(task_item.id), 'ttl_timestamp': {'$lt': cur_timestamp}, }, {'$unset': { 'runner_id': '', }}) if response['updatedExisting']: run_task(task_item) time.sleep(settings.mongo.task_ttl)