[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Task scheduling using Ruby?

nkb

10/11/2004 8:02:00 AM

Hi.
I would like to schedule a task (e.g check if a file exists or if the
date of the files in a diretory are newer than yesterday, etc.) on Linux
using Ruby. Can this be done, if so how? I supposed I would run the
script as root background? Thanks for any pointer!!


3 Answers

Hal E. Fulton

10/11/2004 8:18:00 AM

0

nkb wrote:
> Hi.
> I would like to schedule a task (e.g check if a file exists or if the
> date of the files in a diretory are newer than yesterday, etc.) on Linux
> using Ruby. Can this be done, if so how? I supposed I would run the
> script as root background? Thanks for any pointer!!
>

Gavin Kistner released something two weeks ago that might interest you:

> http://phrogz.net/RubyLibs/rdoc/classes/Dir/DirectoryWa...
>
> A DirectoryWatcher keeps an eye on a certain directory, firing off your own custom
> procs when a file is added to, modified in, or removed from that directory.
>
> See the link above for documentation. Download available from
> http://phrogz.net/RubyLibs/Directory...


If that doesn't get you in the right direction, ask us again...


Hal




Robert Klemme

10/11/2004 8:27:00 AM

0


"nkb" <nkb@pacific.net.sg> schrieb im Newsbeitrag
news:416A3DFF.9010804@pacific.net.sg...
> Hi.
> I would like to schedule a task (e.g check if a file exists or if the
> date of the files in a diretory are newer than yesterday, etc.) on Linux
> using Ruby. Can this be done, if so how? I supposed I would run the
> script as root background? Thanks for any pointer!!

Of course you can do it with ruby. However on a *nix box however the
usual approach is to use cron. There might be reasons why you don't want
to use cron.

If I'd do it in Ruby I probably had a class ScheduledEvent with methods
#next_execution and #execute. I'd then keep a priority queue of
ScheduledEvents sorted by #next_execution. Pick the first, calculate the
difference in seconds from now till then and sleep for that time. Of
course, you'll have to take additional actions if the queue contents
should be able to change at any time (i.e. new events are defined or old
events are deleted).

Kind regards

robert

nkb

10/11/2004 9:27:00 AM

0

Thanks.
I downloaded DirectoryWatcher.rb.
I copied and pasted the codes under the Example: section (uncommented
them) to the end of the DirectoryWatcher.rb. And instead of using
'plugins/devices', I replaced it with 'C:/temp'.
I ran DirectoryWatcher.rb at my command prompt on windowsXP. Nothing
happens when I change or add files to the C:/temp.
What am I missing? Thanks.

Hal Fulton wrote on 2004/10/11 17:18:
> nkb wrote:
>
>> Hi.
>> I would like to schedule a task (e.g check if a file exists or if the
>> date of the files in a diretory are newer than yesterday, etc.) on
>> Linux using Ruby. Can this be done, if so how? I supposed I would run
>> the script as root background? Thanks for any pointer!!
>>
>
> Gavin Kistner released something two weeks ago that might interest you:
>
> > http://phrogz.net/RubyLibs/rdoc/classes/Dir/DirectoryWa...
> >
> > A DirectoryWatcher keeps an eye on a certain directory, firing off
> your own custom > procs when a file is added to, modified in, or removed
> from that directory.
> >
> > See the link above for documentation. Download available from
> > http://phrogz.net/RubyLibs/Directory...
>
>
> If that doesn't get you in the right direction, ask us again...
>
>
> Hal
>
>
>
>