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.
Files changed (53) hide show
  1. data/CHANGELOG.txt +6 -0
  2. data/CREDITS.txt +4 -0
  3. data/README.md +1064 -0
  4. data/Rakefile +1 -4
  5. data/TODO.txt +145 -55
  6. data/lib/rufus/scheduler.rb +502 -26
  7. data/lib/rufus/{sc → scheduler}/cronline.rb +46 -17
  8. data/lib/rufus/{sc/version.rb → scheduler/job_array.rb} +56 -4
  9. data/lib/rufus/scheduler/jobs.rb +548 -0
  10. data/lib/rufus/scheduler/util.rb +318 -0
  11. data/rufus-scheduler.gemspec +30 -4
  12. data/spec/cronline_spec.rb +29 -8
  13. data/spec/error_spec.rb +116 -0
  14. data/spec/job_array_spec.rb +39 -0
  15. data/spec/job_at_spec.rb +58 -0
  16. data/spec/job_cron_spec.rb +67 -0
  17. data/spec/job_every_spec.rb +71 -0
  18. data/spec/job_in_spec.rb +20 -0
  19. data/spec/job_interval_spec.rb +68 -0
  20. data/spec/job_repeat_spec.rb +308 -0
  21. data/spec/job_spec.rb +387 -115
  22. data/spec/lockfile_spec.rb +61 -0
  23. data/spec/parse_spec.rb +203 -0
  24. data/spec/schedule_at_spec.rb +129 -0
  25. data/spec/schedule_cron_spec.rb +66 -0
  26. data/spec/schedule_every_spec.rb +109 -0
  27. data/spec/schedule_in_spec.rb +80 -0
  28. data/spec/schedule_interval_spec.rb +128 -0
  29. data/spec/scheduler_spec.rb +831 -124
  30. data/spec/spec_helper.rb +65 -0
  31. data/spec/threads_spec.rb +75 -0
  32. metadata +64 -59
  33. data/README.rdoc +0 -661
  34. data/lib/rufus/otime.rb +0 -3
  35. data/lib/rufus/sc/jobqueues.rb +0 -160
  36. data/lib/rufus/sc/jobs.rb +0 -471
  37. data/lib/rufus/sc/rtime.rb +0 -363
  38. data/lib/rufus/sc/scheduler.rb +0 -636
  39. data/spec/at_in_spec.rb +0 -47
  40. data/spec/at_spec.rb +0 -125
  41. data/spec/blocking_spec.rb +0 -64
  42. data/spec/cron_spec.rb +0 -134
  43. data/spec/every_spec.rb +0 -304
  44. data/spec/exception_spec.rb +0 -113
  45. data/spec/in_spec.rb +0 -150
  46. data/spec/mutex_spec.rb +0 -159
  47. data/spec/rtime_spec.rb +0 -137
  48. data/spec/schedulable_spec.rb +0 -97
  49. data/spec/spec_base.rb +0 -87
  50. data/spec/stress_schedule_unschedule_spec.rb +0 -159
  51. data/spec/timeout_spec.rb +0 -148
  52. data/test/kjw.rb +0 -113
  53. 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
@@ -1,20 +0,0 @@
1
-
2
- $:.unshift('lib')
3
-
4
- require 'rubygems'
5
- require 'rufus/scheduler/em'
6
-
7
- # scheduler
8
-
9
-
10
- s = Rufus::Scheduler.start_new
11
-
12
- puts Time.now.to_s
13
-
14
- s.in('1s') do
15
- p [ :in, Time.now.to_s ]
16
- exit 0
17
- end
18
-
19
- s.join
20
-