示例#1
0
def stop_model(message):
    sid = message.get('sid')
    print(" [*] Message received.")
    if local_redis and sid:
        print(" [*] Stopping {}".format(sid))
        if local_redis.get(sid):
            local_redis.set(sid, ProcessState.CANCELED)
示例#2
0
def message_handler(message):
    if not message:
        return

    data = json.loads(message['data'])
    action = data.get('action')
    sid = data.get('sid')
    if sid and action == 'cancel':
        local_redis.set(sid, ProcessState.CANCELED)
        local_redis.expire(sid, 3600 * 24)
示例#3
0
    def message(self, pubnub, data):
        message = data.message
        if message:
            state = message.get('state')
            sid = data.message.get('sid')
            if sid:
                local_redis.set(sid, state)
                local_redis.expire(sid, 3600 * 24)
                print(sid, state)

        return
示例#4
0
model_key = environ['MODEL_KEY']
queue_name = 'model-{}'.format(model_key)
if run_key:
    queue_name += '-{}'.format(run_key)

broker_url = 'amqp://{username}:{password}@{hostname}/{vhost}'.format(
    username=model_key,
    password=environ.get('RABBITMQ_PASSWORD', 'password'),
    hostname=environ.get('RABBITMQ_HOST', 'localhost'),
    vhost=environ.get('RABBITMQ_VHOST', 'model-run'),
)

redis_host = environ.get('REDIS_HOST', 'localhost')

# test redis
redis.set('test', 1)

app = Celery(
    'tasks',
    broker=broker_url,
    # backend='redis://{}'.format(redis_host),
    include=['waterlp.tasks'],
)

app.conf.update(task_default_queue=queue_name,
                task_default_exchange='tasks',
                broker_heartbeat=10,
                accept_content=['json', 'pickle'],
                result_expires=3600)

# app.config_from_object('waterlp.celeryconfig')
示例#5
0
def run(**kwargs):
    print('xxxxxxxxxxxxxx')
    sid = kwargs.get('sid')
    if local_redis and sid:
        print(' [*] Stopping {}'.format(sid))
        local_redis.set(sid, ProcessState.CANCELED)