Question

Je suis en train d'utiliser le AbortableTask caractéristique de Céleri mais l'exemple de la documentation ne semble pas fonctionner pour moi. L'exemple donné est:

from celery.contrib.abortable import AbortableTask

def MyLongRunningTask(AbortableTask):

    def run(self, **kwargs):
        logger = self.get_logger(**kwargs)
        results = []
        for x in xrange(100):
            # Check after every 5 loops..
            if x % 5 == 0:  # alternatively, check when some timer is due
                if self.is_aborted(**kwargs):
                    # Respect the aborted status and terminate
                    # gracefully
                    logger.warning("Task aborted.")
                    return None
            y = do_something_expensive(x)
            results.append(y)
        logger.info("Task finished.")
        return results

et

from myproject.tasks import MyLongRunningTask

def myview(request):

    async_result = MyLongRunningTask.delay()
    # async_result is of type AbortableAsyncResult

    # After 10 seconds, abort the task
    time.sleep(10)
    async_result.abort()

    ...

Cependant, je reçois l'erreur:

TypeError: MyLongRunningTask() takes exactly 1 argument (0 given)

Qu'est-ce que je fais mal?

Était-ce utile?

La solution

Juste une supposition, mais je pense qu'il devrait être

class MyLongRunningTask(AbortableTask)

et non

def MyLongRunningTask(AbortableTask)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top