Use CronJob or goroutine?

In the past I wrote Python/Django applications.

In the past, if I needed to call some clean up code every hour, I created a command line tool and called it via a CronJob.

Unfortunately there is no global agreement on how to deploy a CronJob (maybe Kubernetes will change this in the long run)… so I would like to avoid the CronJob, if possible.

With Go I could easily write a goroutine which does something every hour. This way I don’t need to configure a CronJob.

What do you think: do you write less CronJobs with Go, or do you still use CronJobs because of … I would be interested why you still use CronJobs.

I do use go cron:

  1. To export changed data from Postgresql every night to a sftp at customer.
  2. Just for fun I created this micro site

I use it most for it is simple and manageable regardless if you dump to disc, export sql or update a web site…

There is a recent discussion on Reddit about task schedulers. The bandwidth is high, from goroutines to workflow orchestration engines. In the end, it depends on the particular use case.

use goroutine if you need more control, and cronjobs in kubernetes you can only from a 1 minute of internal

it’s intersting.
the point is CronJob not resident in memory, but go-cron resident in memory.
if there is a process guard in system, go-cron may be a nice idea.

I thought about this again.

My idea to use a goroutine instead of a cronJob to get easier deployment does not scale. If the code gets executed in 100 containers, then the cronjob will run 100 times. I most cases this is not what you want.

But thank you all for your feedback and links.

you can split the processing between containers, or limit the amount of jobs the same way when you work with cronjob

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.