def queuer(text: str): walrus = get_instance('walrus') lock = walrus.lock('runone') with lock: walrus.set('runone', text) sleep(4) walrus.delete('runone')
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) }
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}'
async def runone_get(): walrus = get_instance('walrus') return {"current_task": walrus.get('runone')}
def status(task_id: str): celery = get_instance('celery') task = celery.AsyncResult(task_id) return {'state': task.state, 'result': task.result}
def last_status(): walrus = get_instance('walrus') return json.loads(walrus.get('last_message'))
def celery_on_message(body): walrus = get_instance('walrus') print(f'Got update from task: {body}') walrus.set('last_message', json.dumps(body))
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