Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions project/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ def startup_task(id_):
return True


async def call_chatgpt_or_whatever():
async def call_chatgpt_or_whatever() -> int:
await asyncio.sleep(10)
return random.randint(5, 20)

# Converts a Celery tasks to an async function
def task_to_async(task):
Expand All @@ -42,23 +43,23 @@ async def wrapper(*args, **kwargs):
def async_parallel_task(id_):
logger.info('-------> parallel task started %s' % id_)
# Deliberately variable to mimic 3rd party API uncertainty
call_chatgpt_or_whatever()
result = call_chatgpt_or_whatever()
logger.info('-------> parallel task complete %s' % id_)
return True
return result


@celery.task()
def sync_parallel_task(id_):
logger.info('-------> parallel task started %s' % id_)
sleep(10)
logger.info('-------> parallel task complete %s' % id_)
return True
return random.randint(5, 20)


@celery.task()
def reducer_task(id_):
def reducer_task(id_, ints_to_average: list[int]):
logger.info('-----> reducer task started')
# Deliberately short - idea being that when parallel task is paused it switches to this.
sleep(0.3)
logger.info('-----> reducer task complete')
return True
return sum(ints_to_average)