Ejemplo n.º 1
0
    def exec_async(self, *args, **kwargs):
        if self.task_id:
            task_id = self.task_id
        else:
            task_id = uuid1()
        print self.func
        args_json = json.dumps(getcallargs(self.func, *args, **kwargs), indent=2)

        redis = create_redis_connection(self.redis_connection)

        task_hash_key = get_task_hash_key(task_id)
        pending_list_key = get_pending_list_key(self.queue)
        results_channel_key = get_results_channel_key()

        pubsub = redis.pubsub(ignore_subscribe_messages=True)
        pubsub.subscribe(results_channel_key)

        pipe = redis.pipeline(transaction=True)

        pipe.lpush(pending_list_key, task_id)

        print self.virtual_memory_limit

        pipe.hmset(task_hash_key,
                   {TASK_HKEY_FUNCTION: self.func.__name__,
                   TASK_HKEY_ARGS: args_json,
                   TASK_HKEY_STATE: STATE_PENDING,
                   TASK_HKEY_USERNAME: self.username,
                   TASK_HKEY_PENDING_CREATED: json.strftime(datetime.utcnow()),
                   TASK_HKEY_VIRTUAL_MEMORY_LIMIT: self.virtual_memory_limit})

        pipe.execute()

        return AsyncResult(redis, pubsub, task_hash_key, task_id)
Ejemplo n.º 2
0
def _get_next_task_id(redis, queue, timeout=1):
    return redis.brpoplpush(get_pending_list_key(queue),
                            get_executing_list_key(queue),
                            timeout=timeout)