Domanda

I have my class inherited from celery.task.PeriodicTask and i want to run this task asynchoronously sometimes.

If it was a usual method task, i did something like:

@periodic_task(run_every=timedelta(minutes=15))
def mytask(additional=False):
    if a==b and not additional:
        # args = [True,] sets additional=True
        mytask.apply_async(args=[True, ], countdown=7*60)

But now i have a class:

from celery.task import PeriodicTask
class MyClassTask(PeriodicTask):
    def run(self, additional=False):
        if a == b and not additional:
            self.apply_async(task_id=self.request.id, args=[True, ], countdown=7*60)

EDIT: CODE IS WORKING OK. I checked and question is no longer needed.

È stato utile?

Soluzione

I double checked manually and my code works, anyone can do like this:

from celery.task import PeriodicTask
class MyClassTask(PeriodicTask):
    def run(self, additional=False):
        if a == b and not additional:
            self.apply_async(task_id=self.request.id, args=[True, ], countdown=7*60)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top