jcass77 / django-apscheduler

APScheduler for Django
MIT License
665 stars 95 forks source link

Scheduler goes idle or does not execute jobs at all #181

Open RJ-Gamer opened 1 year ago

RJ-Gamer commented 1 year ago

I'm using this library for my project. I wanted to execute few jobs at a specific time. For example:

# time at which task should run
auto_denied_at = appointment_at + timedelta(minutes=constants.APPT_AUTO_DENIED_TIME) # lets say 10 min

And here is my task

def auto_denied_appointment(appointment_id, self=None):
    '''
    automatically change the state of the appointment
    '''
    appointment = Appointment.objects.filter(
        id=appointment_id).values("id", "status", "doctor_detail__user__id", "patient_detail__user__id").first()
    if appointment["status"] in ["REQUESTED", "RESCHEDULE_REQUEST"]:
        Appointment.objects.filter(id=appointment_id).update(status="AUTO_DENIED")
        message = constants.MSG_APPT_DENIED
        params = "{" + "\"appointment_id\": {}".format(appointment['id']) + "}"
        send_notification(
            user_id=appointment["doctor_detail__user__id"],
            params=params,
            message=message,
            notification_type="AUTO_CANCELLED",
        )
        send_notification(
            user_id=appointment["patient_detail__user__id"],
            params=params,
            message=message,
            notification_type="AUTO_CANCELLED",
        )

here is the code for add job

scheduler.add_job(
                func=auto_denied_appointment,
                trigger=DateTrigger(run_date=auto_denied_at),
                args=[appointment_data.id],
                replace_existing=True,
                jobstore="default",
                id=str(appointment_data.id) + '_auto_denied_appointment',
                misfire_grace_time=None,
            )

Job should ideally be executed at given time; but when time arrives scheduler do not execute the job or even could not see the logs I even tried with interval trigger but most of the time jobs were missed.

I have 3 jobs similar to auto_denied_appointment that need to execute at specific time.

Undertone0809 commented 1 year ago

I had the same problem.Did you solve the problem?