require ‘rufus/scheduler’
ti= Time.now.strftime(“%Y-%m-%d %a %H:%M:%S”)
puts “[#{ti}],start to test ”
$basic_schedule_workday=”3m”
s = Rufus::Scheduler::PlainScheduler.start_new
s.every ’4m’ do
read_ini=ReadIni.new
read_ini.read ‘cfg.ini’
ti= Time.now.strftime(“%Y-%m-%d %a %H:%M:%S”)
puts ” [#{ti}]every 4m check ini file to get the
$basic_schedule_workday.”
s.every $basic_schedule_workday do
ti= Time.now.strftime(“%Y-%m-%d %a %H:%M:%S”)
puts “[#{ti}],every #{$basic_schedule_workday} print new interval time
from ini.”
end
end
s.join
Hello Edward,
could you please be more specific about how it doesn't work ?
Please find some inspiration at: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
Thanks in advance,
--
John Mettraux - http://lambda.io/processi
ti= Time.now.strftime("%Y-%m-%d %a %H:%M:%S")
puts "[#{ti}],start to test, the initial $basic_schedule_workday=7s"
$basic_schedule_workday="7s"
scheduler1 = Rufus::Scheduler::PlainScheduler.start_new
scheduler1.every '10s' do
read_ini=ReadIni.new
read_ini.read 'cfg2.ini'
ti= Time.now.strftime("%Y-%m-%d %a %H:%M:%S")
puts " [#{ti}]every 10s check ini, the $basic_schedule_workday
is:#{$basic_schedule_workday} ."
end
#scheduler1 = Rufus::Scheduler::PlainScheduler.start_new
scheduler1.every $basic_schedule_workday do
ti= Time.now.strftime("%Y-%m-%d %a %H:%M:%S")
puts "every #{$basic_schedule_workday} interval to print time:
[#{ti}]"
end
scheduler1.join
---------run result--------
[2011-12-02 Fri 10:43:41],start to test, the initial
$basic_schedule_workday=7s ##this interval is right
every 7s interval to print time:[2011-12-02 Fri 10:43:48]
[2011-12-02 Fri 10:43:51]every 10s check ini, the
$basic_schedule_workday is:4s . ##this interval is right,10s
===change the cfg2.ini content, $basic_schedule_workday from 7s to 4s
every 4s interval to print time:[2011-12-02 Fri 10:43:55] ##this
interval is right, 7s
[2011-12-02 Fri 10:44:01]every 10s check ini, the
$basic_schedule_workday is:4s . ##this interval is right,10s
every 4s interval to print time:[2011-12-02 Fri 10:44:02] ##this
interval is not right
every 4s interval to print time:[2011-12-02 Fri 10:44:09] ##this
interval is not right , it is 7s,should be 4s
[2011-12-02 Fri 10:44:11]every 10s check ini, the
$basic_schedule_workday is:5s . ##this interval is right,10s
===change the cfg2.ini content, $basic_schedule_workday from 4s to 5s
every 5s interval to print time:[2011-12-02 Fri 10:44:16] ##this
interval is not right ,it is 7s,should be 5s
[2011-12-02 Fri 10:44:21]every 10s check ini, the
$basic_schedule_workday is:5s . ##this interval is right,10s
every 5s interval to print time:[2011-12-02 Fri 10:44:23] ##this
interval is not right ,it is 7s,should be 5s
every 5s interval to print time:[2011-12-02 Fri 10:44:30] ##this
interval is not right ,it is 7s,should be 5s
[2011-12-02 Fri 10:44:31]every 10s check ini, the
$basic_schedule_workday is:5s . ##this interval is right,10s
every 5s interval to print time:[2011-12-02 Fri 10:44:38] ##this
interval is not right ,it is 8s,should be 5s
[2011-12-02 Fri 10:44:41]every 10s check ini, the
$basic_schedule_workday is:5s . ##this interval is right,10s
every 5s interval to print time:[2011-12-02 Fri 10:44:45] ##this
interval is not right ,it is 7s,should be 5s
every 5s interval to print time:[2011-12-02 Fri 10:44:51] ##this
interval is not right ,it is 6s,should be 5s
[2011-12-02 Fri 10:44:51]every 10s check ini, the
$basic_schedule_workday is:5s . ##this interval is right,10s
every 5s interval to print time:[2011-12-02 Fri 10:44:58]
I guess I know understand what you mean by "it doesn't work".
I have a question for you. Please consider the following program and tell me how many lines it will output. (it's only Ruby, no rufus-scheduler involved).
---8<---
def do_it(i, &block)
return if i <= 0
block.call
do_it(i - 1, &block)
end
$count = 5
do_it($count) do
puts "$count is #{$count}"
$count = $count + 1
end
--->8---
So, how many lines ?
...
The program you're looking for probably looks something like:
---8<---
require 'rufus-scheduler'
$last_time = Time.now
def format(t)
t.strftime("%Y-%m-%d %a %H:%M:%S")
end
scheduler = Rufus::Scheduler.start_new
workday_job = scheduler.every '7s' do |job|
now = Time.now
puts "{#{format(now)}} every #{job.frequency} interval: [#{now - $last_time}]"
$last_time = now
end
scheduler.every '10s' do
workday_job.instance_variable_set(:@frequency, (rand * 10).to_i + 1)
puts "[#{format(Time.now)}] new frequency: #{workday_job.frequency}"
end
scheduler.join
--->8---
Best regards,
--
you received this message because you are subscribed to the "rufus ruby" group.
to post : send email to rufus...@googlegroups.com
to unsubscribe : send email to rufus-ruby+...@googlegroups.com
more options : http://groups.google.com/group/rufus-ruby?hl=en