Exemple #1
0
    def revoke(self, terminate=True, signal='KILL'):
        if self.task_id and self.states in ('PENDING', 'FAILURE', 'STARTED'):
            ret = procedure_run_by_worker.AsyncResult(self.task_id)
            ret.revoke(terminate=terminate, signal=signal)

            # mongodb = spawn()
            my_lock = mongo_lock(mongodb.sqlrun.sqlrun_lock, self.task_id)
            my_lock.acquire()
            my_lock.release()
            # mongodb.close()
        else:
            logging.warning("revoke didn't work for [%s] - states:%s" % (self.task_id, self.states))
Exemple #2
0
def sql_run_by_worker(sqlrunner_data):

    class sqlrun_dummy(sqlrun):
        def __init__(self):
            pass

    ## storage check
    SQLRUN_STORAGE = config.easy_sqlrun_storage
    # if SQLRUN_STORAGE == 'mongodb':
    #     from mongo import spawn
    # elif SQLRUN_STORAGE == 'redis':
    # 	import redis
    #     def spawn(): return redis.Redis()
    # else:
    #     assert SQLRUN_STORAGE in ['mongodb', 'redis']

    mongodb = singleton()

    result = []

    have_lock = False

    if SQLRUN_STORAGE == 'mongodb':
        # mongodb = spawn()
        ldb = config.easy_sqlrun_mongodb_lockdb
        lcol = config.easy_sqlrun_mongodb_lock_coll
        my_lock = mongo_lock(mongodb[ldb][lcol], current_task.request.id)
    else:
        my_lock = spawn().lock(current_task.request.id)
    try:
        if SQLRUN_STORAGE == 'mongodb':
            have_lock = my_lock.acquire()
        else:
            have_lock = my_lock.acquire(blocking=False)

        if have_lock:
            sr = sqlrun_dummy()
            sr.from_json(sqlrunner_data)

            ret = sr.run(current_task.request.id) # local
            ret.task_id = current_task.request.id
            ret.async = True

            # logging.critical(ret)
            ret = ret.to_json()
            logging.critical(ret)
            sql_run_by_worker.ignore_result = False

            logging.critical('sqlrun(%s) done.' % (current_task.request.id))
        else:
            ret = None
            sql_run_by_worker.ignore_result = True
            logging.critical('sqlrun(%s) failed(acquring the lock failed.).' % (current_task.request.id))
    finally:
        if SQLRUN_STORAGE == 'mongodb':
            # mongodb.close()
            pass
        if have_lock:
            my_lock.release()

    mongodb.close()

    if ret:
        return ret
    else:
        raise Exception('Already acquired.')