création tâche cron
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
from mycaldav.cron import InitTaskSync
|
||||||
|
|
||||||
|
|
||||||
class CaldavConfig(AppConfig):
|
class CaldavConfig(AppConfig):
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
name = 'mycaldav'
|
name = 'mycaldav'
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
my_cron_job = InitTaskSync()
|
||||||
|
my_cron_job.start()
|
||||||
|
17
mycaldav/cron.py
Normal file
17
mycaldav/cron.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from django_cron import CronJobBase, Schedule
|
||||||
|
|
||||||
|
from mycaldav.models import caldav_sync_manager
|
||||||
|
from mycaldav.settings import CALDAV_URL,CALDAV_USER,CALDAV_PASSWORD
|
||||||
|
|
||||||
|
class InitTaskSync(CronJobBase):
|
||||||
|
RUN_AT_TIMES = [time(hour=7), time(hour=19)]
|
||||||
|
|
||||||
|
schedule = Schedule(run_at_times=RUN_AT_TIMES,)
|
||||||
|
code = 'mycaldav.init_sync_task' # Un code unique pour votre tâche cron
|
||||||
|
|
||||||
|
def do(self):
|
||||||
|
o_caldav_sync_management = caldav_sync_manager()
|
||||||
|
o_caldav_sync_management.init_caldav(caldav_url=CALDAV_URL, caldav_user=CALDAV_USER, caldav_password=CALDAV_PASSWORD)
|
||||||
|
o_caldav_sync_management.init_task_management()
|
||||||
|
|
||||||
|
print('Ma tâche cron s\'exécute !')
|
Reference in New Issue
Block a user