cenkalti / kuyruk

⚙️ Simple task queue for Python
https://kuyruk.readthedocs.org/
MIT License
234 stars 17 forks source link

AttributeError : 'function' object has no attribute 'apply' #63

Closed nathan30 closed 5 years ago

nathan30 commented 5 years ago

I have an issue with the python worker Kuyruk. Here is the way I call it :

from kuyruk import Kuyruk

OCforInvoices = Kuyruk()

@OCforInvoices.task()
def launch(args):
    # DO SOMETHING

Then I launch the following command to start the worker :

kuyruk --app bin.src.main.OCforInvoices worker

worker is the reference for the worker.py file who handles the arguments when launching the command.

So, when the worker is launched I used the following command to enqueue in worker :

python3 worker.py -c config.ini -f file.pdf

After that Kuyruk return me the following error :


I kuyruk.kuyruk.connection:85 - Connected to RabbitMQ
I kuyruk.kuyruk.channel:60 - Opened new channel
I kuyruk.worker._consume_messages:125 - Consumer started
I kuyruk.worker._process_message:189 - Processing task: {'id': '6f050168f72111e9a4aa00e04c68cd8c', 'args': [{'path': '/home/nathan/PycharmProjects/oc_invoices_flask/instance/upload/', 'config': '/home/nathan/PycharmProjects/oc_invoices_flask/instance/config.ini'}], 'kwargs': {}, 'module': 'bin.src.main', 'function': 'launch', 'sender_hostname': 'nathan', 'sender_pid': 508, 'sender_cmd': 'python3 worker.py -c config.ini -f file.pdf', 'sender_timestamp': '2019-10-25T12:17:38'}

E kuyruk.worker._process_task:248 - Task raised an exception
E kuyruk.worker._process_task:250 - Traceback (most recent call last):
  File "/home/nathan/miniconda3/envs/OC/lib/python3.7/site-packages/kuyruk/worker.py", line 301, in _apply_task
    return task.apply(*args, **kwargs)
AttributeError: 'function' object has no attribute 'apply'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/nathan/miniconda3/envs/OC/lib/python3.7/site-packages/kuyruk/worker.py", line 223, in _process_task
    result = self._run_task(message.channel.connection, task, args, kwargs)
  File "/home/nathan/miniconda3/envs/OC/lib/python3.7/site-packages/kuyruk/worker.py", line 279, in _run_task
    return self._apply_task(task, args, kwargs)
  File "/home/nathan/miniconda3/envs/OC/lib/python3.7/site-packages/kuyruk/worker.py", line 304, in _apply_task
    logger.info("%s finished in %i seconds." % (task.name, delta))
AttributeError: 'function' object has no attribute 'name'

Any ideas ?

Thanks in advance

cenkalti commented 5 years ago

Hello @nathan30

I'm sorry I cannot reproduce the issue. It looks like the function that is being called is not decorated with task decorator. Maybe you have changed the code after you send the task to queue but before running the worker process?

nathan30 commented 5 years ago

Hello @nathan30

I'm sorry I cannot reproduce the issue. It looks like the function that is being called is not decorated with task decorator. Maybe you have changed the code after you send the task to queue but before running the worker process?

Hi,

Thanks for your response. I finally find the solutions. The problem was the worker.py filename causing issue with the name 'worker'. Rename it to 'launch_worker.py', for example, fix the issue. Weird but now it's working :)

cenkalti commented 5 years ago

Oh :)