How to run sanic-scheduler on request?

After receiving request I want to run sanic-scheduler function. I want to do something like this:

@app.route("/api/new-answer", methods=["POST"])
def new_answer(request):
	@task(timedelta(seconds=2)) # I want to run this task
	def check_data_status(app):
		print("Do SMTH")

But it does not work. Could anybody help me?

I don’t use this library, but looking at the docs, I think that it’s probably easiest if you set a flag on the route and check for the flag on the tasks.

— though perhaps there is a more elegant way to do this.

run_task = False

@app.route("/api/new-answer", methods=["POST"])
def new_answer(request):
	run_task = True
	return response.json(dict(run_task=run_task))

@task(timedelta(seconds=2)) # I want to run this task
def check_data_status(app):
	if run_task:
		print("Do SMTH")