示例#1
0
def queuer(text: str):
    walrus = get_instance('walrus')
    lock = walrus.lock('runone')

    with lock:
        walrus.set('runone', text)
        sleep(4)
        walrus.delete('runone')
示例#2
0
def counter(background_task: BackgroundTasks, count: int):
    from celerydemo.tasks import counter

    walrus = get_instance('walrus')
    current_count = str(walrus.get('celery'))
    task = counter.delay(count)
    background_task.add_task(background_on_message, task)
    return {
        'status': 'queued',
        'current_count': current_count,
        'task_id': str(task)
    }
示例#3
0
def counter(count: int) -> str:
    walrus = get_instance('walrus')
    for i in range(count):
        sleep(1)
        status = walrus.incr('celery')
        current_task.update_state(
            state='PROGRESS',
            meta={
                'process_percent': i * (100 / count),
                'current_inc': status
            },
        )

    return f'incremented to {status}'
示例#4
0
async def runone_get():
    walrus = get_instance('walrus')
    return {"current_task": walrus.get('runone')}
示例#5
0
def status(task_id: str):
    celery = get_instance('celery')
    task = celery.AsyncResult(task_id)
    return {'state': task.state, 'result': task.result}
示例#6
0
def last_status():
    walrus = get_instance('walrus')
    return json.loads(walrus.get('last_message'))
示例#7
0
def celery_on_message(body):
    walrus = get_instance('walrus')
    print(f'Got update from task: {body}')
    walrus.set('last_message', json.dumps(body))
示例#8
0
from time import sleep

from celery import current_task

from opa import get_instance

celery = get_instance('celery')


@celery.task
def counter(count: int) -> str:
    walrus = get_instance('walrus')
    for i in range(count):
        sleep(1)
        status = walrus.incr('celery')
        current_task.update_state(
            state='PROGRESS',
            meta={
                'process_percent': i * (100 / count),
                'current_inc': status
            },
        )

    return f'incremented to {status}'


@celery.task
def divider(num1, num2) -> str:
    sleep(4)

    result = num1 / num2