Django using Celery not performing my task

March 21, 2021, at 03:40 AM

I have been trying for the past 3 days to get django to perfom asynchronous tasks on a periodic schedule. Came across Celery which seemed like a perfect match for my problem but the more I read online the more problems there seemed to exist that I had prepared. Anyway I was able to vaguely glue up together pieces of information to finally come up with a "somewhat solution" because there were so many deprecated modules and methods it was hard to find a working example from start to finish. So I am trying to create a task which will create a certain model object periodically (let's say 30 seconds for sake of the argument). So I installed redis as the "broker", (so I saw fit in other discussions) and managed to set up my task up and running but the problem is that even when it executes, no new model is created, I suspect that it might be cause of maybe a misconfiguration between the local and the settings time-zone but frankly I'm not sure, supposedly it should be able to create new instance when run through django-celery-beat tables in the admin panel

from __future__ import absolute_import, unicode_literals 
from .celery import app as celery_app 
__all__ = ('celery_app',) in the base directory:
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'firstApp.settings')
app = Celery('myProject')


def debug_task(self):
    print('Request: {0!r}'.format(self.request))

my configuration:
BROKER_URL = 'redis://localhost:6379'
    'Every Minute' : {
        'task' : 'main.tasks.Check_State_Up',
        'schedule' : 30,
note, 'main' is the name of my app
my in main app:
from celery import shared_task 
from django.shortcuts import get_object_or_404
import random 
from .models import CheckUp, Company

def Check_State_Up():
    parentInstance = get_object_or_404(ParentModel, symbol='Symbol')
    def create(parent):
        Widget.objects.create(parent=parent, randomValue=random.randint(100,250))
Note, Parent model has a name and symbol value and widget has a parent, (foreign key) and a random value let's keep in mind that this function works totally fine when called in shell, I just posted it for demostration

Can anyone help me understand what is going wrong here?

Also my logs from celery

celery -A myProject beat -l Info 
celery beat v5.0.5 (singularity) is starting.
__    -    ... __   -        _
LocalTime -> 2021-03-20 18:17:58
Configuration ->
    . broker -> redis://localhost:6379//
    . loader ->
    . scheduler -> celery.beat.PersistentScheduler
    . db -> celerybeat-schedule
    . logfile -> [stderr]@%INFO
    . maxinterval -> 5.00 minutes (300s)
[2021-03-20 18:17:58,033: INFO/MainProcess] beat: Starting...
it also stops and starting...

celery -A myProject worker -l info

 -------------- celery@myDevice v5.0.5 (singularity)
--- ***** -----
-- ******* ---- Windows-10-10.0.18362-SP0 2021-03-20 18:17:50
- *** --- * ---
- ** ---------- [config]
- ** ---------- .> app:         myProject:0x1502743f3d0
- ** ---------- .> transport:   redis://localhost:6379//
- ** ---------- .> results:     disabled://
- *** --- * --- .> concurrency: 4 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery

  . myProject.celery.debug_task
  . main.tasks.Check_State_Up
[2021-03-20 18:17:51,102: INFO/MainProcess] Connected to redis://localhost:6379//
[2021-03-20 18:17:51,130: INFO/MainProcess] mingle: searching for neighbors
[2021-03-20 18:17:51,904: INFO/SpawnPoolWorker-1] child process 1852 calling
[2021-03-20 18:17:51,922: INFO/SpawnPoolWorker-3] child process 8424 calling
[2021-03-20 18:17:51,955: INFO/SpawnPoolWorker-2] child process 8600 calling
[2021-03-20 18:17:52,002: INFO/SpawnPoolWorker-4] child process 14840 calling

the child process 1000 calling executes only when initated from the admin panel manually, not when started. I hope this is thorough enough to understand. Thank you.

Nextcloud: upload large files

Nextcloud: upload large files

I have a Nextcloud 18 on Apache/PHP 73, behind a reverse proxy (out of my control)

Getting the contents of more than one DB table in Spring

Getting the contents of more than one DB table in Spring

I'm trying make an endpoint to get the content of two independent tables from my DB using Spring but I've got no idea how to do it

How to rearrange DataTables controls

How to rearrange DataTables controls

Hi I want to rearrange the positions of elements of datatables and also want to add one button