Force kill only affects live monkeys, and is reset once a monkey is dead

This commit is contained in:
Itay Mizeretz 2017-10-17 12:13:46 +03:00
parent 57e3677fce
commit c6a5741c96
2 changed files with 10 additions and 3 deletions

View File

@ -29,7 +29,7 @@ class Root(flask_restful.Resource):
ConfigService.init_config() ConfigService.init_config()
return jsonify(status='OK') return jsonify(status='OK')
elif action == "killall": elif action == "killall":
mongo.db.monkey.update({}, {'$set': {'config.alive': False, 'modifytime': datetime.now()}}, upsert=False, mongo.db.monkey.update({'dead': False}, {'$set': {'config.alive': False, 'modifytime': datetime.now()}}, upsert=False,
multi=True) multi=True)
return jsonify(status='OK') return jsonify(status='OK')
else: else:

View File

@ -209,8 +209,14 @@ class NodeService:
@staticmethod @staticmethod
def set_monkey_dead(monkey, is_dead): def set_monkey_dead(monkey, is_dead):
props_to_set = {'dead': is_dead}
# Cancel the force kill once monkey died
if is_dead:
props_to_set['config.alive'] = True
mongo.db.monkey.update({"guid": monkey['guid']}, mongo.db.monkey.update({"guid": monkey['guid']},
{'$set': {'dead': is_dead}}, {'$set': props_to_set},
upsert=False) upsert=False)
@staticmethod @staticmethod
@ -255,9 +261,10 @@ class NodeService:
{'dead': {'$ne': True}, 'keepalive': {'$gte': datetime.now() - timedelta(minutes=10)}}): {'dead': {'$ne': True}, 'keepalive': {'$gte': datetime.now() - timedelta(minutes=10)}}):
return return
# config.alive is changed to true to cancel the force kill of dead monkeys
mongo.db.monkey.update( mongo.db.monkey.update(
{'keepalive': {'$lte': datetime.now() - timedelta(minutes=10)}, 'dead': {'$ne': True}}, {'keepalive': {'$lte': datetime.now() - timedelta(minutes=10)}, 'dead': {'$ne': True}},
{'$set': {'dead': True, 'modifytime': datetime.now()}}, upsert=False, multi=True) {'$set': {'dead': True, 'config.alive': True, 'modifytime': datetime.now()}}, upsert=False, multi=True)
@staticmethod @staticmethod
def is_any_monkey_alive(): def is_any_monkey_alive():