Running task once a day in vibe.d

Chris Wright via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 17 11:24:27 PST 2016


On Wed, 17 Feb 2016 18:55:42 +0000, Zardoz wrote:

> On Tuesday, 16 February 2016 at 18:30:43 UTC, Nick wrote:
>> Hey folks
>>
>> I'm making a vibe.d application. Once a day it needs to download some
>> data. How do i get the program to perform this task once a day?
>>
>> Regards, Nick
> 
> Why you not use cron to launch your program at desire time every day ?

Instead of just extracting an archive in a particular directory, you now 
have to edit your crontab. It's another thing that can go wrong outside 
your code.

On the other hand, cron is pretty reliable. More reliable than what I'd 
hack up in a day.

On the *other* other hand, cron is entirely generic. I don't know what it 
will do if, for instance, my server is power cycling when the cron job 
should run. I don't know what will happen if your server is off for three 
whole days and you turn it back on again. What does your application 
require? Does it line up with what cron offers?

But if you write it yourself, you know what your task scheduler will do. 
You know what logs you need to watch.

Also, speaking of logs: if you have a logwatch daemon that's looking for 
problems from your logfile, putting everything in the same process can 
simplify that a bit. Or if you have a webservice that has a status page, 
it might be easier to do if the daily task is executed in-process.

As a compromise, you could have a simple 'curl http://localhost/dailytask/
execute' as a cronjob.


More information about the Digitalmars-d-learn mailing list