Question: Can I see currently running jobs?
See original GitHub issueIs there a possibility to differentiate between a taskid that is currently running and just doesn’t exist? While it’s running, the taskid isn’t present in huey.all_results() and get(taskid) returns None. After completion it is present in all_results() and get(taskid) returns the result as expected.
Background: I’m writing an API where a post to endpoint A starts a task and I want to provide an endpoint B that allows polling of the task status. Now I would like to provide different status response for a plain invalid taskid and a currently running taskid.
I’m using sqlite for storage. Is that the cause? Or do I need to use signals and write to the sqlite?
Even more background on what i’m doing:
app.py:
from flask import Flask, url_for
import worker
from huey import SqliteHuey
huey = SqliteHuey(filename='worker.db', fsync=True)
app = Flask(__name__)
@app.route("/create/<a>", methods=["POST"])
def create_task(a):
task = worker.create_hue_task(a)
return task.id, 204
@app.route("/allresults")
def allresults():
return str(huey.all_results())
worker.py:
import time
from huey import SqliteHuey
huey = SqliteHuey(filename='worker.db', fsync=True)
@huey.task()
def create_hue_task(a):
time.sleep(20)
return a+a
and then just start the worker and the app:
huey_consumer worker.huey
# in another shell
flask run
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Oh, I suppose if the operating system kills the worker process for using all the ram…but if that’s the case you’ve got bigger problems.
That’s actually been added. Bear in mind this only occurs if you hard shutdown the consumer. Graceful shutdown finishes all running tasks.
https://huey.readthedocs.io/en/latest/signals.html
See SIGNAL_INTERRUPTED