Schedule Ruby Code!

B

bashar.ayyash

Hello,

I want to build a ruby script that list contents of a folder and put
this list in a generated XML files (actually two files), and I want to
schedule this script to run every 30 minutes.

Pls. if you could tell me where I should start and how to make this
script run every 30 minutes, I'm new to the language I liked it and I
want to learn it more.


Your help is really appreciated,
Regards,
 
M

Mohit Sindhwani

Hello,

I want to build a ruby script that list contents of a folder and put
this list in a generated XML files (actually two files), and I want to
schedule this script to run every 30 minutes.

Pls. if you could tell me where I should start and how to make this
script run every 30 minutes, I'm new to the language I liked it and I
want to learn it more.


Your help is really appreciated,
Regards,
If you're on Linux/ Unix, use cron. If you're on Windows, use PyCron to
schedule your code to run at whatever interval you like.

Cheers,
Mohit.
11/8/2007 | 3:10 PM.
 
J

John Mettraux

Hello,

I want to build a ruby script that list contents of a folder and put
this list in a generated XML files (actually two files), and I want to
schedule this script to run every 30 minutes.

Pls. if you could tell me where I should start and how to make this
script run every 30 minutes, I'm new to the language I liked it and I
want to learn it more.

Hi Bashar,

To list the content of a folder, take a look at the Dir class
(http://corelib.rubyonrails.org/classes/Dir.html), if you need
something a bit more 'recursive', look at Find
(http://stdlib.rubyonrails.org/libdoc/find/rdoc/index.html).

To generate the XML file, have a look at REXML,
http://www.germane-software.com/software/rexml/docs/tutorial.html

Now for the scheduling, as Mohit said, let the "cron" system of your
platform run your job.


If you want to stay Ruby, you can use the OpenWFEru scheduler and
write something like :

---8<---

require 'rubygems'
require 'openwfe/util/scheduler'
# sudo gem install openwferu-scheduler

s = OpenWFE::Scheduler.new
s.start

s.schedule("0,30 * * * *") do
# twice per hour, at minute 0 and at minute 30

generate_xml_file()
# your method
end

--->8---

more info at http://openwferu.rubyforge.org/scheduler.html

If your script is just a sysadmin helper, it's probably wiser to stick
with the cron utility of your platform.


Best regards,
 
B

bashar.ayyash

HiBashar,

To list the content of a folder, take a look at the Dir class
(http://corelib.rubyonrails.org/classes/Dir.html), if you need
something a bit more 'recursive', look at Find
(http://stdlib.rubyonrails.org/libdoc/find/rdoc/index.html).

To generate the XML file, have a look at REXML,http://www.germane-software.com/software/rexml/docs/tutorial.html

Now for the scheduling, as Mohit said, let the "cron" system of your
platform run your job.

If you want to stay Ruby, you can use the OpenWFEru scheduler and
write something like :

---8<---

require 'rubygems'
require 'openwfe/util/scheduler'
# sudo gem install openwferu-scheduler

s = OpenWFE::Scheduler.new
s.start

s.schedule("0,30 * * * *") do
# twice per hour, at minute 0 and at minute 30

generate_xml_file()
# your method
end

--->8---

more info athttp://openwferu.rubyforge.org/scheduler.html

If your script is just a sysadmin helper, it's probably wiser to stick
with the cron utility of your platform.

Best regards,

Thank you very much John for your help and giving me great tips...!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top