Obviously, scheduling something to happen every foo seconds is easy.
What is a reasonably performant, simple way to schedule an operation to
occur at a particular time of day (preferably specified by a particular
time zone)?
The first thing that comes to my mind is checking Time.now, checking the
time between that and the desired time of day, then spawn a thread that
sleeps for that length of time (because I need the program to do other
things in the meantime). Is there a better way to do this?
On Jun 28, 2011, at 11:58 , Chad P. wrote:
Obviously, scheduling something to happen every foo seconds is easy.
What is a reasonably performant, simple way to schedule an operation to
occur at a particular time of day (preferably specified by a particular
time zone)?
The first thing that comes to my mind is checking Time.now, checking the
time between that and the desired time of day, then spawn a thread that
sleeps for that length of time (because I need the program to do other
things in the meantime). Is there a better way to do this?
cron
On Tue, Jun 28, 2011 at 8:58 PM, Chad P. [email protected] wrote:
The first thing that comes to my mind is checking Time.now, checking the
time between that and the desired time of day, then spawn a thread that
sleeps for that length of time (because I need the program to do other
things in the meantime). Is there a better way to do this?
There is: Cron jobs on *NIX or Task Scheduler on Windows. You have no
guarantee that your program is running, and Cron/Task Scheduler can
run tasks that have to occur, even after the original time has
passed.
–
Phillip G.
A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
– Leibniz
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
On Jun 28, 2011, at 8:58 PM, Chad P. wrote:
Obviously, scheduling something to happen every foo seconds is easy.
What is a reasonably performant, simple way to schedule an operation to
occur at a particular time of day (preferably specified by a particular
time zone)?
The first thing that comes to my mind is checking Time.now, checking the
time between that and the desired time of day, then spawn a thread that
sleeps for that length of time (because I need the program to do other
things in the meantime). Is there a better way to do this?
http://rufus.rubyforge.org/rufus-scheduler/ or as Ryan has written cron
or launchd on osx.
All the best, Sandor Szcs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
iQIcBAEBCgAGBQJOCjJFAAoJEIiuFRwovs5ri0YP/0KMETQUzE07rPvka7yOVtjV
kILhAHMrlh0nuIVxhus7SJbHwmhs4BvrnRoLVh45IO6cdQxb6kZv6Vcvqxg6YQkU
WizA5ungnF7HRj8UkI3EsKGz6gJDFCObsY7eRsz7wLMFHdPpnOoMb4J6NyBCe3eP
Op672nTYs5Un8VQs6FsexOzSj0+jPPO+fu/jbqinfPRkqorl2QeB+1fOniGmRySW
fHsI/vU87wsq9Yb8Qh/wfTqmNhr/ykBi0UXSpOIobkktFIyxY5qZXdloPJTJ/Tj9
FPfFjBW2bQ3PJN/3TxgG2QRFbTgrMnYTVyLPjtqIQYNVMaZwYuDngHcSqLcYoTd3
k3LUrnCdTI2jH4vd95AwO2UX+SE2QtfSa00dV924AbpxMmcLIsQxzZbdtN7rvkJ6
8XPlaKW1X0IVTRQaAUtcl/qipT3JDrOoO7Aybb5DLF23/puKyPGWRHIVA6Ohq/4d
U/sS5S6dl4QY9SGDoSm0hPpr81QO7k98Q60Pkzthodh9UhxefGdNVV07LigNxF5A
wNRcVvqrEY5M0zNPFa/37Dmpk3Q1v+l3EVFg6yZPsJ5qS5ZL/2wvOOP4mIaqkDFn
5sbOGkQQioBdYoRDHPUFx2Mk14+jY1gafSuzhbrQInTl/PU6/EZIdHkoMYrDMK0d
aud/DPOk0mCxXYKnF4Dt
=3LIu
-----END PGP SIGNATURE-----
Chad P. [email protected] wrote:
Obviously, scheduling something to happen every foo seconds is easy.
What is a reasonably performant, simple way to schedule an operation to
occur at a particular time of day (preferably specified by a particular
time zone)?
If it has to be within a long-running program:
You can install a signal handler and have cron signal the process.
I don’t know of anything that takes care of timezones/calculations for
you, but…
The first thing that comes to my mind is checking Time.now, checking the
time between that and the desired time of day, then spawn a thread that
sleeps for that length of time (because I need the program to do other
things in the meantime). Is there a better way to do this?
Cool.io and EventMachine both expose timer functionality which should
be reasonably portable across different *nixes.
If you’re only targetting recent-ish Linux systems, the
sleepy_penguin[1] library exposes TimerFD as an IO object which you can
IO.select/poll/epoll on. This functionality is only lightly-tested,
so feedback is welcome (I’m the maintainer).
[1] sleepy_penguin - Linux I/O events for Ruby
On Wed, Jun 29, 2011 at 04:22:22AM +0900, Eric W. wrote:
[snip]
I need something a little more portable than the options you provided,
though I appreciate the suggestions. Someone else in the thread pointed
me at a gem that seems to do what I need, so I’ll look into that.
On Wed, Jun 29, 2011 at 04:58:09AM +0900, Sandor Szuecs wrote:
http://rufus.rubyforge.org/rufus-scheduler/ or as Ryan has written cron
or launchd on osx.
Thanks. I’ll look into that.