rufus-scheduler 2.0.24 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +6 -0
- data/CREDITS.txt +4 -0
- data/README.md +1064 -0
- data/Rakefile +1 -4
- data/TODO.txt +145 -55
- data/lib/rufus/scheduler.rb +502 -26
- data/lib/rufus/{sc → scheduler}/cronline.rb +46 -17
- data/lib/rufus/{sc/version.rb → scheduler/job_array.rb} +56 -4
- data/lib/rufus/scheduler/jobs.rb +548 -0
- data/lib/rufus/scheduler/util.rb +318 -0
- data/rufus-scheduler.gemspec +30 -4
- data/spec/cronline_spec.rb +29 -8
- data/spec/error_spec.rb +116 -0
- data/spec/job_array_spec.rb +39 -0
- data/spec/job_at_spec.rb +58 -0
- data/spec/job_cron_spec.rb +67 -0
- data/spec/job_every_spec.rb +71 -0
- data/spec/job_in_spec.rb +20 -0
- data/spec/job_interval_spec.rb +68 -0
- data/spec/job_repeat_spec.rb +308 -0
- data/spec/job_spec.rb +387 -115
- data/spec/lockfile_spec.rb +61 -0
- data/spec/parse_spec.rb +203 -0
- data/spec/schedule_at_spec.rb +129 -0
- data/spec/schedule_cron_spec.rb +66 -0
- data/spec/schedule_every_spec.rb +109 -0
- data/spec/schedule_in_spec.rb +80 -0
- data/spec/schedule_interval_spec.rb +128 -0
- data/spec/scheduler_spec.rb +831 -124
- data/spec/spec_helper.rb +65 -0
- data/spec/threads_spec.rb +75 -0
- metadata +64 -59
- data/README.rdoc +0 -661
- data/lib/rufus/otime.rb +0 -3
- data/lib/rufus/sc/jobqueues.rb +0 -160
- data/lib/rufus/sc/jobs.rb +0 -471
- data/lib/rufus/sc/rtime.rb +0 -363
- data/lib/rufus/sc/scheduler.rb +0 -636
- data/spec/at_in_spec.rb +0 -47
- data/spec/at_spec.rb +0 -125
- data/spec/blocking_spec.rb +0 -64
- data/spec/cron_spec.rb +0 -134
- data/spec/every_spec.rb +0 -304
- data/spec/exception_spec.rb +0 -113
- data/spec/in_spec.rb +0 -150
- data/spec/mutex_spec.rb +0 -159
- data/spec/rtime_spec.rb +0 -137
- data/spec/schedulable_spec.rb +0 -97
- data/spec/spec_base.rb +0 -87
- data/spec/stress_schedule_unschedule_spec.rb +0 -159
- data/spec/timeout_spec.rb +0 -148
- data/test/kjw.rb +0 -113
- data/test/t.rb +0 -20
data/test/kjw.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
#
|
4
|
-
# A test by http://twitter.com/kjw
|
5
|
-
#
|
6
|
-
|
7
|
-
require 'test/unit'
|
8
|
-
$LOAD_PATH << 'lib'
|
9
|
-
require 'rufus/sc/scheduler'
|
10
|
-
|
11
|
-
require 'rubygems'
|
12
|
-
require 'eventmachine'
|
13
|
-
|
14
|
-
class CronTest < Test::Unit::TestCase
|
15
|
-
|
16
|
-
#
|
17
|
-
# Stress test program for rufus-scheduler
|
18
|
-
#
|
19
|
-
|
20
|
-
SECONDS_FROM_NOW = 30
|
21
|
-
MODE = :cron
|
22
|
-
JOB_COUNT = 1000
|
23
|
-
JOB_IDS = (1..JOB_COUNT).to_a
|
24
|
-
NUM_RESCHEDULES = 20
|
25
|
-
|
26
|
-
def setup
|
27
|
-
@trigger_queue = Queue.new
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_stress_schedule_unschedule_plain_cron
|
31
|
-
stress_schedule_unschedule(:cron, Rufus::Scheduler::PlainScheduler.start_new)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_stress_schedule_unschedule_plain_at
|
35
|
-
stress_schedule_unschedule(:at, Rufus::Scheduler::PlainScheduler.start_new)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_stress_schedule_unschedule_plain_every
|
39
|
-
stress_schedule_unschedule(:every, Rufus::Scheduler::PlainScheduler.start_new)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_stress_schedule_unschedule_em_cron
|
43
|
-
stress_schedule_unschedule(:cron, Rufus::Scheduler::EmScheduler.start_new)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_stress_schedule_unschedule_em_at
|
47
|
-
stress_schedule_unschedule(:at, Rufus::Scheduler::EmScheduler.start_new)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_stress_schedule_unschedule_em_every
|
51
|
-
stress_schedule_unschedule(:every, Rufus::Scheduler::EmScheduler.start_new)
|
52
|
-
end
|
53
|
-
|
54
|
-
protected
|
55
|
-
|
56
|
-
def stress_schedule_unschedule(mode, scheduler)
|
57
|
-
|
58
|
-
# Schedule all jobs, then unschedule and (re)schedule a number of times
|
59
|
-
schedule_unschedule(scheduler, mode, NUM_RESCHEDULES)
|
60
|
-
|
61
|
-
# give scheduler thread 10 seconds to process the schedule and unschedule requests
|
62
|
-
# but don't wait for the jobs to trigger (which is in less than 30 seconds)
|
63
|
-
sleep 10
|
64
|
-
# print_scheduler_counts(scheduler, 10)
|
65
|
-
|
66
|
-
# by now the scheduler should have processed everything, check
|
67
|
-
assert(JOB_IDS.sort == scheduler.find_jobs.map{ |job| job.job_id }.sort)
|
68
|
-
sleep SECONDS_FROM_NOW # wait for jobs to trigger
|
69
|
-
assert(JOB_COUNT == @trigger_queue.size)
|
70
|
-
end
|
71
|
-
|
72
|
-
def schedule_unschedule(scheduler, mode, num_reschedules)
|
73
|
-
schedule_jobs(scheduler, mode)
|
74
|
-
1.upto(num_reschedules) do
|
75
|
-
sleep 0.01 # cause schedule's to happen before unscheduling
|
76
|
-
unschedule_jobs(scheduler)
|
77
|
-
schedule_jobs(scheduler, mode)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def print_scheduler_counts(scheduler, seconds)
|
82
|
-
1.upto(seconds) do
|
83
|
-
puts "all:%d at:%d cron:%d every:%d pending:%d" % [
|
84
|
-
scheduler.all_jobs.size,
|
85
|
-
scheduler.at_job_count,
|
86
|
-
scheduler.cron_job_count,
|
87
|
-
scheduler.every_job_count,
|
88
|
-
scheduler.pending_job_count]
|
89
|
-
sleep 1
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def schedule_jobs(scheduler, mode)
|
94
|
-
trigger_proc = lambda { |params| @trigger_queue << params[:job_id] }
|
95
|
-
JOB_IDS.each do |job_id|
|
96
|
-
case mode
|
97
|
-
when :at
|
98
|
-
scheduler.at(Time.now + SECONDS_FROM_NOW, {:job_id => job_id}, &trigger_proc)
|
99
|
-
when :every
|
100
|
-
scheduler.every("#{SECONDS_FROM_NOW}s", {:job_id => job_id}, &trigger_proc)
|
101
|
-
when :cron
|
102
|
-
scheduler.cron("%d * * * * *" % ((Time.now.to_i%60) + SECONDS_FROM_NOW) % 60,
|
103
|
-
{:job_id => job_id}, &trigger_proc)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def unschedule_jobs(scheduler)
|
109
|
-
JOB_IDS.each { |job_id| scheduler.unschedule(job_id) }
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
data/test/t.rb
DELETED