Celery task not running and stuck in PENDING

Asked by Kennedi Chambers on
Tags:
5 Answers

Answer by Clark Horne

Invoking a constructor in a 'with' statement ,I am new to celery and this is a little confusing to me. Thanks in advance for any help.,See if the add method is listed in celery tasks from the following code, How to change Reference image color within blender?

See if the add method is listed in celery tasks from the following code

celery.tasks.keys()

I think the decorator you have to close with parenthesis

@celery.task()
def add(x, y):
    time.sleep(5)
    return x + y

Source: https://stackoverflow.com/questions/46963974/celery-status-stuck-in-pending-status


Answer by Journee Vasquez

Is it safe to run celery worker as root?,Brokers Why is RabbitMQ crashing? Can I use Celery with ActiveMQ/STOMP? What features aren’t supported when not using an AMQP broker? ,What features aren’t supported when not using an AMQP broker?,Can I use Celery with ActiveMQ/STOMP?

[mysqld]
transaction-isolation = READ-COMMITTED

Source: https://docs.celeryproject.org/en/stable/faq.html


Answer by Brielle Newton

You'll find the PID in the second column. For the purposes of this post let's assume that's 1234. You can inspect the full command in the process list to make sure you've identified the right celery worker.,Celery is a great tool for background task processing in Django. We use it in a lot of the custom web apps we build at Caktus, and it's quickly becoming the standard for all variety of task scheduling work loads, from simple to highly complex.,While there may have been other ways to fix the underlying issue, strace and lsof were crucial in helping us figure out the problem. One might be able to accomplish the same thing with a lot of logging, but if your code is stuck in a system call and doesn't appear to be showing any noticeable CPU usage in top, strace can take you immediately to the root of the problem.,We recently ran into this issue at Caktus, and in our case the stuck worker process wasn't processing any new tasks and wasn't showing any CPU activity in top. That seemed a bit odd, so I thought I'd make an attempt to discover what that process was actually doing at the time that it became non-responsive. Enter strace.

ps auxww|grep celery

Source: https://www.caktusgroup.com/blog/2013/10/30/using-strace-debug-stuck-celery-tasks/


Answer by Travis Peralta

Capsule sync is stucked at 1% and is not progressing. Current running tasks shows:,Cancel running CapsuleSync and related tasks:,Stop all capsule sync tasks including remove_orphan tasks running on the Capsule.,qpid-stat in the capsule shows that pulp_workers are not picking up the tasks:

Capsule sync is stucked at 1% and is not progressing. Current running tasks shows:

# sudo su - postgres -c "psql -d foreman -c 'select label,count(label),state,result from foreman_tasks_tasks where state <> '\''stopped'\'' group by label,state,result ORDER BY label;'"
                     label                      | count |   state   | result
------------------------------------------------+-------+-----------+---------
 Actions::Katello::CapsuleContent::Sync         |     1 | running   | pending
 Actions::Katello::OrphanCleanup::RemoveOrphans |     1 | running   | pending
 CreatePulpDiskSpaceNotifications               |     1 | scheduled | pending
 CreateRssNotifications                         |     1 | scheduled | pending
 SendExpireSoonNotifications                    |     1 | scheduled | pending
 StoredValuesCleanupJob                         |     1 | scheduled | pending
(6 rows)

Source: https://access.redhat.com/solutions/5249121


Answer by Brooks Calderon

Can you post the request code too?,This is the output of my celery worker. It shows that the work is completed . But on the celery_progress.js where the request is being made response is always pending,This is the request url. Also if you want to look at the url,You can use flower to monitor celery tasks if that's your goal

I am trying to use celery to keep track of progress of the process. I am very new to it I was following multiple tutorials but now I am stuck in a problem.

[2021-06-26 17:07:19,143: INFO/ForkPoolWorker-6] Task web.tasks.my_task[70ce295c-148b-4a55-8d47-bc86c04fea58] succeeded in 10.486046889000136s: 45

This is the output of my celery worker. It shows that the work is completed . But on the celery_progress.js where the request is being made response is always pending

 if (response.status === 200) {
            let data;
            try {
                data = await response.json();
            } catch (parsingError) {
                this.onDataError(this.progressBarElement, this.progressBarMessageElement, "Parsing Error")
                throw parsingError;
            }
            console.log(data);
            const complete = this.onData(data);

            if (complete === false) {
                setTimeout(this.connect.bind(this), this.pollInterval);
            }

This gives output

state: "PENDING", complete: false, success: null, progress: {…}

I am new to this so I don't know what to post for more information but this is what I added in my settings.py

INSTALLED_APPS = [
    ...
    'django_celery_results',
    'celery_progress',    
]
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'

CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'

Source: https://www.reddit.com/r/django/comments/o8ez4y/django_celery_is_sending_wor_status_pending_even/


Related