from django_cron import CronJobBase, Schedule
import django



class InitTaskSync(CronJobBase):
    RUN_AT_TIMES = ['07:00', '19:00']
    RUN_EVERY_MIN = 120

    #schedule = Schedule(run_at_times=RUN_AT_TIMES,)
    schedule = Schedule(run_every_mins=RUN_EVERY_MIN,)
    code = 'reskreen.init_sync_task'    # Un code unique pour votre tâche cron

    def do(self):
        django.setup()

        from mycaldav.models import caldav_sync_manager
        from mycaldav.settings import CALDAV_URL,CALDAV_USER,CALDAV_PASSWORD
        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 !')
