Home > other >  Django apschuler timing task of time interval is too long to run
Django apschuler timing task of time interval is too long to run

Time:04-30

I have a Django web application, one of the tasks regularly, is configured to run every day 23 points, the code is as follows:
 try: 
# set the maximum number of threads to 3
Job_defaults={' max_instances: 3}
The scheduler=BackgroundScheduler (timezone=Settings. TIME_ZONE, job_defaults=job_defaults)
# scheduler=BackgroundScheduler ()
The scheduler. Add_jobstore (DjangoJobStore (), "default")


@ register_job (scheduler, 'cron, hour="23", minute="00", id="task_data")
Def countdata () :
"" "
Every night 11:59 timing acquisition data and processing data statistics program
: return:
"" "
Data statistics began to print (" % s "% datetime. The datetime. Now ())
Thread_list=[]
Thread1=threading. Thread (target=Countcjsqldata () countvalue)
Thread2=threading. Thread (target=Countjgsqldata () countvalue)
Thread3=threading. Thread (target=Countjgsqldatacountry () countvalue)
Thread_list. Append (thread1)
Thread_list. Append (thread2)
Thread_list. Append (thread3)
For t in thread_list:
T.s etDaemon (True)
T.s tart ()
For I in thread_list:
I.j oin ()
Statistics over print (" % s "% datetime. The datetime. Now ())

# register_events (scheduler)
The scheduler. The start ()
Print (" the amount of processing data collected statistical timing task start!" )
Except the Exception as e:
Print (" timing service errors, closed: % s "% e)
There is an error in # stop timer
The scheduler. Shutdown ()

But the run time error:
Error getting due jobs from job store 'default' : (0, ' ')
I checked the because my database automatically disconnect the overtime, consult how to solve this problem?

CodePudding user response:

If is the mission of the low frequency, connect to the database, when performing a task performed closes the connection

CodePudding user response:

Based on apschuler timing task sequence will be deposited in the mysql database, to the time to go to the mysql database reads the tasks to perform, I am unable to read from the mysql database directly to the task, connect to the database is not a mission,
  • Related