Search code examples
pythondjangodjango-rest-frameworkschedulerapscheduler

Apscheduler Job in Django executes twice


The scheduled job executes twice with difference in nanoseconds. I have a task as follows in task.py

def print_hello():
   print("time-->",datetime.datetime.now())
   print("hello")

def print_world():
   print("time-->",datetime.datetime.now())
   print("hello")

scheduler = BackgroundScheduler()
scheduler1 = BackgroundScheduler()

Add in app.py from app folder consist following code line..

from django.apps import AppConfig
from datetime import date
class ExploitDataConfig(AppConfig):
     name = 'exploit_data' 

     def ready(self):
    
         from exploit_data import task   

         task.scheduler.add_job(task.print_hello, 'interval', minutes=5)
         task.scheduler1.add_job(task.print_world, 'interval', minutes=5
         task.scheduler.start()
         task.scheduler1.start()

I want this to execute only once at the interval of 5 minutes. ANY HELP IS APPRECIABLE ..


Solution

  • Maybe this can help for temporary solution:

    python manage.py runserver --noreload