closeio / tasktiger

Python task queue using Redis
MIT License
1.42k stars 80 forks source link

only a single task can execute before tasktiger errors out #83

Closed ancat closed 7 years ago

ancat commented 7 years ago

Hi,

I'm having trouble getting even the basic hello world example running cleanly on my system. The task does execute, but I get a massive stack trace about an exception that occurred in the Lua code. After the exception is printed, the tasktiger process exits. Patching the module to add an exception handler in redis_scripts.py works just fine in that multiple tasks can execute without the main process exiting, but it seems kinda hacky and the console gets flooded with "event": "failing expired task" errors.

Here's my specs (Ubuntu 16.04):

$ pip freeze
...
redis==2.10.6
tasktiger==0.9.1
$ redis-server -v
Redis server v=3.0.6 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=687a2a319020fa42

My code:

# queuer.py
from tasky import my_task
import tasktiger

tiger = tasktiger.TaskTiger()
tiger.delay(my_task)

# tasky.py
def my_task():
    print "HELLO WORLD\ngoodbye"

The error:

$ PYTHONPATH=. tasktiger
{"level": "info", "timestamp": "2017-09-04T00:20:50.817296Z", "queues": [], "pid": 16069, "exclude_queues": [], "event": "ready"}
{"level": "debug", "timestamp": "2017-09-04T00:20:54.226146Z", "pid": 16069, "queue": "default", "params": [{"args": [], "task_id": "ac2ebf92129241a44ea8a91d667cda3cf4d948e50f8ddd45daf638ebb277cab5", "kwargs": {}}], "child_pid": 16076, "func": "tasky:my_task", "event": "processing"}
HELLO WORLD
goodbye
{"exception": "Traceback (most recent call last):\n  File \"/home/ancat/.local/lib/python2.7/site-packages/tasktiger/worker.py\", line 800, in run\n    self._worker_run()\n  File \"/home/ancat/.local/lib/python2.7/site-packages/tasktiger/worker.py\", line 712, in _worker_run\n    if not self._process_from_queue(queue):\n  File \"/home/ancat/.local/lib/python2.7/site-packages/tasktiger/worker.py\", line 519, in _process_from_queue\n    self._finish_task_processing(queue, task, success)\n  File \"/home/ancat/.local/lib/python2.7/site-packages/tasktiger/worker.py\", line 610, in _finish_task_processing\n    _mark_done()\n  File \"/home/ancat/.local/lib/python2.7/site-packages/tasktiger/worker.py\", line 606, in _mark_done\n    task._move(from_state=ACTIVE)\n  File \"/home/ancat/.local/lib/python2.7/site-packages/tasktiger/task.py\", line 240, in _move\n    scripts.execute_pipeline(pipeline)\n  File \"/home/ancat/.local/lib/python2.7/site-packages/tasktiger/redis_scripts.py\", line 495, in execute_pipeline\n    raise e\nResponseError: Error running script (call to f_8c9e36483ae952c86a059230793221dd84b0e9d0): @enable_strict_lua:15: user_script:46: Script attempted to access unexisting global variable 'f_da73dc442ac4ec1343b0cd6eb3af5afe8204adba' ", "pid": 16069, "timestamp": "2017-09-04T00:20:54.237918Z", "level": "error"}
{"timestamp": "2017-09-04T00:20:54.240324Z", "pid": 16069, "event": "done", "level": "info"}
Traceback (most recent call last):
  File "/home/ancat/.local/bin/tasktiger", line 11, in <module>
    sys.exit(run_worker())
  File "/home/ancat/.local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/ancat/.local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/ancat/.local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ancat/.local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/ancat/.local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/ancat/.local/lib/python2.7/site-packages/tasktiger/__init__.py", line 366, in run_worker
    tiger.run_worker(**kwargs)
  File "/home/ancat/.local/lib/python2.7/site-packages/tasktiger/__init__.py", line 296, in run_worker
    worker.run()
  File "/home/ancat/.local/lib/python2.7/site-packages/tasktiger/worker.py", line 800, in run
    self._worker_run()
  File "/home/ancat/.local/lib/python2.7/site-packages/tasktiger/worker.py", line 712, in _worker_run
    if not self._process_from_queue(queue):
  File "/home/ancat/.local/lib/python2.7/site-packages/tasktiger/worker.py", line 519, in _process_from_queue
    self._finish_task_processing(queue, task, success)
  File "/home/ancat/.local/lib/python2.7/site-packages/tasktiger/worker.py", line 610, in _finish_task_processing
    _mark_done()
  File "/home/ancat/.local/lib/python2.7/site-packages/tasktiger/worker.py", line 606, in _mark_done
    task._move(from_state=ACTIVE)
  File "/home/ancat/.local/lib/python2.7/site-packages/tasktiger/task.py", line 240, in _move
    scripts.execute_pipeline(pipeline)
  File "/home/ancat/.local/lib/python2.7/site-packages/tasktiger/redis_scripts.py", line 495, in execute_pipeline
    raise e
redis.exceptions.ResponseError: Error running script (call to f_8c9e36483ae952c86a059230793221dd84b0e9d0): @enable_strict_lua:15: user_script:46: Script attempted to access unexisting global variable 'f_da73dc442ac4ec1343b0cd6eb3af5afe8204adba'
dawncold commented 7 years ago

@ancat it looks like you are calling a script that is not loaded, this commit may help you, https://github.com/closeio/tasktiger/commit/ff42c433fed59e3f5b3e7b11bf8f92c6dcfff14a

If you can't wait Tasktiger next release and don't want modify library directly, you can override Tasktiger and RedisScripts.

Override Tasktiger to use your own RedisScripts.

Override RedisScripts and override execute_pipeline method, load scripts and then call parent execute_pipeline

ancat commented 7 years ago

Thanks for the help @dawncold, I saw that commit but didn't put 2 and 2 together. Applying that patch fixes the issue for me!