2

I'm adding a new minutely cron task as follows:

library(cronR)
cron_datamultiple <- cron_rscript("multiple_data.R")
cron_add(command = cron_datamultiple, frequency = 'minutely', id = 'test1', description = 'My process 1', tags = c('test1'), ask=FALSE)

If the task takes more than 1 minute, another task starts so the tasks are gettinmg slower. Finally my Google Cloud virtual machine instance crashes.

How can I write a code for:

  • not start the next scheduled task before the running task finishes. OR
  • kill the running task if it took more than 1 minute.

Thanks.

Serhat Akay
  • 115
  • 10

1 Answers1

1

cron tasks does not have any awareness from each other, so you need to check manualy if your task is still working or idle.

one way for checking this, write the status to a file. (task1_status.txt)

  1. in the beginning of the task, check that status by reading task1_status.txt
  2. if status = idle then
  3. update status = working
  4. continue on task
  5. at the end of the task update status = idle
  6. if status = working then stop the task or wait 5 seconds and re-check the status
Selcuk Akbas
  • 711
  • 1
  • 8
  • 20