- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.1k
 
Description
This has been an issue for all of our projects for three years, but I've finally decided to write about it. It's more of a visual inconvenience.
Our projects have the same setup of: Django - Celery - Redis - Flower.
Celery is run with
/bin/sh -c /home/django/.local/bin/celery multi start worker1 -A project --pidfile=/home/django/celery/%n.pid --concurrency=5 --logfile=/home/django/celery/%n%I.log --loglevel=DEBUG
Flower is run with
/bin/python /home/django/.local/bin/celery -A project flower --port=8787 --log-file-prefix=/home/django/celery/flower.log --loglevel=DEBUG
Broker string: redis://127.0.0.1:6379/0
celery.py:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
app: Celery = Celery('project')
app.config_from_object(settings, namespace='CELERY')
app.autodiscover_tasks()
If a background function is created through Celery's .delay(), it shows up in Flower just fine. But if it's called from within a Signal (ex. inside a function with @worker_ready.connect or through a app.conf.beat_schedule config), it does not show up in Flower's dashboard.
- My background tasks run just fine, so I doubt it's Django's problem.
 - My background tasks can print themselves with @app.task(bind=True) and are visible with app.control.inspect().active(), so I doubt it's Celery's problem.
 - redis-cli MONITOR shows that Redis is receiving tasks, so I doubt it's Redis's problem.
 - I can see IDs of my background tasks in Flower's "Workers - Worker - Tasks - Active tasks" tab. The IDs are consistent with previous steps...
 - But when I click on any of them (of signal-created), the web says: "Unknown task 'id'" The global list of tasks also says "No data available in table" (unless there were non-signal-created tasks).
 - But most curiously, if I kill Celery process, now Flower can see those tasks, which are marked as Failed by raising
 
celery.exceptions.WorkerShutdown: 0
billiard.exceptions.WorkerLostError: Worker exited prematurely: signal 15 (SIGTERM) Job: 1
So this tells me that Flower can see them, but decides to not display them for whatever reason.
I've looked at what Celery Worker is receiving, and both normal and invisible background tasks look identical aside of IDs, which as far as I can tell matches with what Redis is getting. Meaning that functionally, there should be no difference with how the task is created..
TaskPool: Apply < function fast_trace_task at 0x7f243de709d0 > (
args: ('... .background_task', '8c68b20f-d5b4-4c56-823d-892783a0dd83', {
		'lang': 'py',
		'task': '... .background_task',
		'id': '8c68b20f-d5b4-4c56-823d-892783a0dd83',
		'shadow': None,
		'eta': None,
		'expires': None,
		'group': None,
		'group_index': None,
		'retries': 0,
		'timelimit': [None, None],
		'root_id': '8c68b20f-d5b4-4c56-823d-892783a0dd83',
		'parent_id': None,
		'argsrepr': '()',
		'kwargsrepr': '{}',
		'origin': 'gen1460173@hostname',
		'ignore_result': False,
		'replaced_task_nesting': 0,
		'stamped_headers': None,
		'stamps': {},
		'properties': {
			'correlation_id': '8c68b20f-d5b4-4c56-823d-892783a0dd83',
			'reply_to': 'e5baa096-2704-3459-9c6b-6dd75c07f1a3',
			'delivery_mode': 2,
			'delivery_info': {
				'exchange': '',
				'routing_key': 'celery'
			},
			'priority': 0,
			'body_encoding': 'base64',
			'delivery_tag': '7075234a-bbae-442a-95fb-38d5f6ef9f2e'
		},
		'reply_to': 'e5baa096-2704-3459-9c6b-6dd75c07f1a3',
		'correlation_id': '8c68b20f-d5b4-4c56-823d-892783a0dd83',
		'hostname': 'worker1@hostname',
		'delivery_info': {
			'exchange': '',
			...kwargs: {})
Would appreciate some suggestions, because not seeing background tasks in a web client for viewing background tasks is pretty weird.