Forums

Django-q Queued Task Still Run After Deletion

When starting a task the id is saved to the database, this is used later for getting the user's queued task that is running so it can be deleted, but when it is deleted the task is still running even though the Django-q database is shown to be empty in Django admin. Any help would be greatly appreciated thanks.

function in views for starting task

async_id = async_task("themisapp.bot.custombot",ind, sind, name, coin1, coin2, interval, sender, Key, coin_hash, starting, coin_hash2, user_id)
tx_hash = 'Bot Running'

orm = OrmQ.objects.all()
q_task = orm[len(orm)-1]
task_id = int(q_task.id)

task = Task( user_id = request.user.id, async_id = task_id )
task.save()

Function in Views For deleting queued task

if request.method == 'POST' and request.POST.get('form_type') == 'trade_cancel':
    try:
        live = Live.objects.get(user_id=request.user.id)
        live.delete()

        task_id = request.user.task.async_id

        q = OrmQ.objects.get(id=task_id)
        q.delete()

        task = Task.objects.get(user_id=request.user.id)
        task.delete()

        tx_hash = 'Successfully Stopped Bot'
    except:
        tx_hash = 'No Bot Currently Running'

Q-Cluster Settings

Q_CLUSTER = {
    'name': 'DjangORM',
    'workers': 8,
    'timeout':604800,
    'retry': 604801,
    'queue_limit': 100,
    'bulk': 20,
    'orm': 'default',
}

How are you running the tasks?

Via the django-q module, you can see in views.py code I use the async_task method to start the task.

Async would not work correctly directly in web apps on PythonAnywhere. See https://help.pythonanywhere.com/pages/AsyncInWebApps/

With the django-q module, it works fine just deletion of the queued task doesn't stop it from running, I tried the same code on my local machine and the same problem occurs so it's not a problem with pythonanywhere but rather the way that I'm trying to delete/stop it from running.

All right -- the async code is not likely to run on long terms on PythonAnywhere, since it requries long running processes, and we have 5-min timeout on the requests set.