cron icon indicating copy to clipboard operation
cron copied to clipboard

What is the right way to store a cron in a database

Open siredwin opened this issue 3 years ago • 5 comments

I will be moving to production and I need to save my cron in a database. It looks like it can be saved as gob. I am afraid that the transactions will overlap with multiple readers and writers. What is the best way to do this?

siredwin avatar Nov 15 '21 19:11 siredwin

Can I piggy-back on this by asking the same question of file storage?

My current code will just literally store the contents of cron.Entries() in a gob, which is then buffered and written to a file. Fine. The question then becomes how can I 'inject' that joblist back into cron, I'm thinking along the lines of using cron.Parser but am a little unsure if that's the best way to proceed?

lowlevelcodehustler avatar Nov 18 '21 10:11 lowlevelcodehustler

@lowlevelcodehustler, Turns out you are right. Cron needs to have exported fields to be gob encoded.

siredwin avatar Nov 22 '21 19:11 siredwin

This also answers a lot of my questions. Should I run one cron for all entries? Should I run one cron per entry?

It looks like you need to save/persist the spec and the function(AddFunc) or spec and the job(AddJob) details to be run in a file or database. Cron only cares about what is running now. So if you restart the cron server, all these jobs or funcs need to be restarted with any cron. Am I right?

siredwin avatar Nov 22 '21 19:11 siredwin