scheduled background job issue
Opened this issue · 1 comments
Assalamualikum kang,
saya pernah membuat satu schedule menggunakan cronjob dalam golang service untuk menjalankan sebuah background job (bg job) yang saya jalankan setiap 8 jam (kaya minum obat) mulai dari jam 1 malam, 9 pagi, dan 5 sore.
issue-nya terjadi ketika dalam satu waktu, karena satu dan lain hal, (sebagai contoh) di pukul 1 malam satu bg job running lebih dari 8 jam,,
nah apa yang terjadi dengan bg job di jam 9 pagi,,apakah bg job jam 1 malam akan berhenti? atau bagaimana?
apakah dari kang eko ada insight untuk handle issue tersebut?
terimakasih,,,,
salam ganteng dan intelek
dari chatgpt
Cron jobs are scheduled to run at specific times, regardless of how long previous jobs have taken. If you have a cron job set to run at 8 am every day, it will attempt to run at 8 am every day, even if the previous day’s job is still running.
In your case, if a certain job runs for 25 hours, and you have a cron job set to run at 8 am, the cron job will start a new process at 8 am the next day, even if the previous day’s job hasn’t finished. This could result in two instances of the job running at the same time.
If you want to avoid this, you might need to add some logic to your script to check if an instance of the job is already running and, if so, to not start a new one. Alternatively, you could use a job scheduler that supports job queuing to ensure that jobs do not overlap.
Let me know if you need help with anything else! 😊