Search code examples
pythonarq

How to pass function to arq worker on python


Run arq worker with some function that have some task to do but getting for below one. arq import Worker

w = Worker(functions=[],
    redis_settings=WorkerSettings.redis_settings(),
    max_jobs=1000,
    keep_result_forever=True,
    job_timeout=86000,
    max_tries=1000)
w.run()

Error on missing single function


Solution

  • You need a function that the worker should run. Otherwise the worker would be quite unnecessary.

    For example with the function the_tasks, you add it to the functions argument of the worker:

    arq import Worker
    
    async def the_task(ctx):
        print('running the task')
        return 42
    
    w = Worker(functions=[the_task],
        redis_settings=WorkerSettings.redis_settings(),
        max_jobs=1000,
        keep_result_forever=True,
        job_timeout=86000,
        max_tries=1000)
    w.run()
    

    Maybe start with the demo example: https://arq-docs.helpmanual.io/#simple-usage