www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Running task once a day in vibe.d

reply Nick <nickbakkegaard gmail.com> writes:
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
Feb 16 2016
next sibling parent Chris Wright <dhasenan gmail.com> writes:
On Tue, 16 Feb 2016 18:30:43 +0000, 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
http://vibed.org/api/vibe.core.core/runTask http://vibed.org/api/vibe.core.core/sleep Run a task in your application setup. Have it sleep until the appointed time, then execute the job in accordance with the prophecy. I'd have it run your daily job in a separate fiber for error isolation. If you want to run it at particular times of day, run if the application crashed before the appointed time, do the right thing with daylight savings, execute once across multiple processes, etc, I don't think that currently exists for vibe.d. It's a decent chunk of work to make all that happen properly.
Feb 16 2016
prev sibling next sibling parent sigod <sigod.mail gmail.com> writes:
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
You can use `Timer`. See `setTimer`/`createTimer` in http://vibed.org/api/vibe.core.core/
Feb 16 2016
prev sibling next sibling parent Nick <nickbakkegaard gmail.com> writes:
Thank you very much, this was exactly what I was looking for!
Feb 17 2016
prev sibling parent reply Zardoz <luis.panadero gmail.com> writes:
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 ?
Feb 17 2016
parent Chris Wright <dhasenan gmail.com> writes:
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.
Feb 17 2016