M
M
Michael2017-09-22 01:03:07
Django
Michael, 2017-09-22 01:03:07

How to kill task in celery djnago?

There is a task, if there is an exception or a certain condition is not met, you need to kill the task, how to do it?
Example:

@task
def test_task():
    try:
        t = 60*3
        while t > 0:
            r = requests.get \
                    ('url')
            if r.status_code == 200:
                strs = json.loads(r.text)
                bal = float(strs['totalReceived'])
                total = float(strs['totalSent'])
                if bal == total:
                    return "Все ок"
                else:
                    time.sleep(1*60)
                    t -= 1*60
                    continue
            else:
                time.sleep(1*60)
                t -= 1*60
                continue
        if t == 0:
            return "Ошибка"
    except:
        return "Ошибочка"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2017-09-22
@toobinks

Exiting the function closes the task

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question