rufus-scheduler 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -2,7 +2,12 @@
2
2
  = rufus-scheduler CHANGELOG.txt
3
3
 
4
4
 
5
- == rufus-scheduler - 2.0.3 not yet released
5
+ == rufus-scheduler - 2.0.4 released 2010/02/12
6
+
7
+ - addressing issue with every and timeout, thanks Tony Day
8
+
9
+
10
+ == rufus-scheduler - 2.0.3 released 2009/11/04
6
11
 
7
12
  - made sure Schedulables with a call(job) method were OK when passed as second
8
13
  parameter (thanks Nate Wiger)
data/CREDITS.txt CHANGED
@@ -10,6 +10,7 @@
10
10
 
11
11
  == Feedback
12
12
 
13
+ - Tony Day - http://github.com/tonyday - every and overlapping timeout issue
13
14
  - Nate Wiger (Schedulable call/trigger issue)
14
15
  - Aldric (readme errors)
15
16
  - Kenneth Kalmer (daemon-kit)
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2005-2009, John Mettraux, jmettraux@gmail.com
2
+ Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
data/Rakefile ADDED
@@ -0,0 +1,82 @@
1
+
2
+ require 'rubygems'
3
+ require 'rake'
4
+
5
+
6
+ load 'lib/rufus/sc/scheduler.rb'
7
+
8
+
9
+ #
10
+ # CLEAN
11
+
12
+ require 'rake/clean'
13
+ CLEAN.include('pkg', 'tmp', 'html')
14
+ task :default => [ :clean ]
15
+
16
+
17
+ #
18
+ # GEM
19
+
20
+ require 'jeweler'
21
+
22
+ Jeweler::Tasks.new do |gem|
23
+
24
+ gem.version = Rufus::Scheduler::VERSION
25
+ gem.name = 'rufus-scheduler'
26
+ gem.summary = 'job scheduler for Ruby (at, cron, in and every jobs)'
27
+
28
+ gem.description = %{
29
+ job scheduler for Ruby (at, cron, in and every jobs).
30
+
31
+ By default uses a Ruby thread, if EventMachine is present, it will rely on it.
32
+ }
33
+ gem.email = 'jmettraux@gmail.com'
34
+ gem.homepage = 'http://github.com/jmettraux/rufus-scheduler/'
35
+ gem.authors = [ 'John Mettraux' ]
36
+ gem.rubyforge_project = 'rufus'
37
+
38
+ gem.test_file = 'spec/spec.rb'
39
+
40
+ #gem.add_dependency 'yajl-ruby'
41
+ gem.add_development_dependency 'yard', '>= 0'
42
+ gem.add_development_dependency 'bacon', '>= 0'
43
+ gem.add_development_dependency 'jeweler', '>= 0'
44
+
45
+ # gemspec spec : http://www.rubygems.org/read/chapter/20
46
+ end
47
+ Jeweler::GemcutterTasks.new
48
+
49
+
50
+ #
51
+ # DOC
52
+
53
+ begin
54
+
55
+ require 'yard'
56
+
57
+ YARD::Rake::YardocTask.new do |doc|
58
+ doc.options = [
59
+ '-o', 'html/rufus-scheduler', '--title',
60
+ "rufus-scheduler #{Rufus::Scheduler::VERSION}"
61
+ ]
62
+ end
63
+
64
+ rescue LoadError
65
+
66
+ task :yard do
67
+ abort "YARD is not available : sudo gem install yard"
68
+ end
69
+ end
70
+
71
+
72
+ #
73
+ # TO THE WEB
74
+
75
+ task :upload_website => [ :clean, :yard ] do
76
+
77
+ account = 'jmettraux@rubyforge.org'
78
+ webdir = '/var/www/gforge-projects/rufus'
79
+
80
+ sh "rsync -azv -e ssh html/rufus-scheduler #{account}:#{webdir}/"
81
+ end
82
+
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2006-2009, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2006-2010, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -97,6 +97,7 @@ module Rufus
97
97
  # Returns the next time that this cron line is supposed to 'fire'
98
98
  #
99
99
  # This is raw, 3 secs to iterate over 1 year on my macbook :( brutal.
100
+ # (Well, I was wrong, takes 0.001 sec on 1.8.7 and 1.9.1)
100
101
  #
101
102
  # This method accepts an optional Time parameter. It's the starting point
102
103
  # for the 'search'. By default, it's Time.now
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2006-2009, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2006-2010, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
data/lib/rufus/sc/jobs.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2006-2009, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2006-2010, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -39,10 +39,10 @@ module Scheduler
39
39
  #
40
40
  attr_reader :t
41
41
 
42
- # When the job is actually running, this attribute will hold the
43
- # thread in which the job is running.
42
+ # Returns the thread instance of the last triggered job.
43
+ # May be null (especially before the first trigger).
44
44
  #
45
- attr_reader :job_thread
45
+ attr_reader :last_job_thread
46
46
 
47
47
  # The job parameters (passed via the schedule method)
48
48
  #
@@ -116,19 +116,21 @@ module Scheduler
116
116
  def trigger (t=Time.now)
117
117
 
118
118
  @last = t
119
+ job_thread = nil
119
120
 
120
121
  @scheduler.send(:trigger_job, @params[:blocking]) do
121
122
  #
122
123
  # Note that #trigger_job is protected, hence the #send
123
124
  # (Only jobs know about this method of the scheduler)
124
125
 
125
- @job_thread = Thread.current
126
+ job_thread = Thread.current
127
+ @last_job_thread = job_thread
126
128
 
127
129
  begin
128
130
 
129
131
  trigger_block
130
132
 
131
- @job_thread = nil
133
+ job_thread = nil
132
134
 
133
135
  rescue Exception => e
134
136
 
@@ -145,8 +147,8 @@ module Scheduler
145
147
 
146
148
  # at this point, @job_thread might be set
147
149
 
148
- @job_thread.raise(Rufus::Scheduler::TimeOutError) \
149
- if @job_thread and @job_thread.alive?
150
+ job_thread.raise(Rufus::Scheduler::TimeOutError) \
151
+ if job_thread && job_thread.alive?
150
152
  end
151
153
  end
152
154
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2005-2009, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2006-2009, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2006-2010, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -33,7 +33,7 @@ module Rufus::Scheduler
33
33
 
34
34
  # This gem's version
35
35
  #
36
- VERSION = '2.0.3'
36
+ VERSION = '2.0.4'
37
37
 
38
38
  #
39
39
  # It's OK to pass an object responding to :trigger when scheduling a job
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2006-2009, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2006-2010, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,14 @@
1
+
2
+ $:.unshift('lib')
3
+ require 'rufus/scheduler'
4
+
5
+ loop do
6
+
7
+ print "> "
8
+ s = gets
9
+
10
+ t = Time.now
11
+ puts Rufus::CronLine.new(s).next_time
12
+ puts "took #{Time.now - t} secs"
13
+ end
14
+
@@ -0,0 +1,87 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rufus-scheduler}
8
+ s.version = "2.0.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["John Mettraux"]
12
+ s.date = %q{2010-02-12}
13
+ s.description = %q{
14
+ job scheduler for Ruby (at, cron, in and every jobs).
15
+
16
+ By default uses a Ruby thread, if EventMachine is present, it will rely on it.
17
+ }
18
+ s.email = %q{jmettraux@gmail.com}
19
+ s.extra_rdoc_files = [
20
+ "LICENSE.txt",
21
+ "README.rdoc"
22
+ ]
23
+ s.files = [
24
+ "CHANGELOG.txt",
25
+ "CREDITS.txt",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "TODO.txt",
30
+ "lib/rufus-scheduler.rb",
31
+ "lib/rufus/otime.rb",
32
+ "lib/rufus/sc/cronline.rb",
33
+ "lib/rufus/sc/jobqueues.rb",
34
+ "lib/rufus/sc/jobs.rb",
35
+ "lib/rufus/sc/rtime.rb",
36
+ "lib/rufus/sc/scheduler.rb",
37
+ "lib/rufus/scheduler.rb",
38
+ "misc/cronline_next_time_cost.rb",
39
+ "rufus-scheduler.gemspec",
40
+ "spec/at_in_spec.rb",
41
+ "spec/at_spec.rb",
42
+ "spec/blocking_spec.rb",
43
+ "spec/cron_spec.rb",
44
+ "spec/cronline_spec.rb",
45
+ "spec/every_spec.rb",
46
+ "spec/exception_spec.rb",
47
+ "spec/in_spec.rb",
48
+ "spec/rtime_spec.rb",
49
+ "spec/schedulable_spec.rb",
50
+ "spec/scheduler_spec.rb",
51
+ "spec/spec.rb",
52
+ "spec/spec_base.rb",
53
+ "spec/stress_schedule_unschedule_spec.rb",
54
+ "spec/timeout_spec.rb",
55
+ "test/kjw.rb",
56
+ "test/t.rb"
57
+ ]
58
+ s.homepage = %q{http://github.com/jmettraux/rufus-scheduler/}
59
+ s.rdoc_options = ["--charset=UTF-8"]
60
+ s.require_paths = ["lib"]
61
+ s.rubyforge_project = %q{rufus}
62
+ s.rubygems_version = %q{1.3.5}
63
+ s.summary = %q{job scheduler for Ruby (at, cron, in and every jobs)}
64
+ s.test_files = [
65
+ "spec/spec.rb"
66
+ ]
67
+
68
+ if s.respond_to? :specification_version then
69
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
70
+ s.specification_version = 3
71
+
72
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
73
+ s.add_development_dependency(%q<yard>, [">= 0"])
74
+ s.add_development_dependency(%q<bacon>, [">= 0"])
75
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
76
+ else
77
+ s.add_dependency(%q<yard>, [">= 0"])
78
+ s.add_dependency(%q<bacon>, [">= 0"])
79
+ s.add_dependency(%q<jeweler>, [">= 0"])
80
+ end
81
+ else
82
+ s.add_dependency(%q<yard>, [">= 0"])
83
+ s.add_dependency(%q<bacon>, [">= 0"])
84
+ s.add_dependency(%q<jeweler>, [">= 0"])
85
+ end
86
+ end
87
+
@@ -0,0 +1,48 @@
1
+
2
+ #
3
+ # Specifying rufus-scheduler
4
+ #
5
+ # Sun Mar 22 16:47:28 JST 2009
6
+ #
7
+
8
+ require File.dirname(__FILE__) + '/spec_base'
9
+
10
+
11
+ describe SCHEDULER_CLASS do
12
+
13
+ before do
14
+ @s = start_scheduler
15
+ end
16
+ after do
17
+ stop_scheduler(@s)
18
+ end
19
+
20
+
21
+ it 'should override jobs with the same id' do
22
+
23
+ hits = []
24
+
25
+ job0 = @s.in '1s', :job_id => 'nada' do
26
+ hits << 0
27
+ end
28
+
29
+ wait_next_tick
30
+
31
+ job1 = @s.in '1s', :job_id => 'nada' do
32
+ hits << 1
33
+ end
34
+
35
+ wait_next_tick
36
+ @s.jobs.size.should.equal(1)
37
+
38
+ hits.should.be.empty
39
+
40
+ sleep 1.5
41
+
42
+ hits.should.equal([ 1 ])
43
+
44
+ @s.jobs.size.should.equal(0)
45
+ end
46
+
47
+ end
48
+
data/spec/at_spec.rb ADDED
@@ -0,0 +1,121 @@
1
+
2
+ #
3
+ # Specifying rufus-scheduler
4
+ #
5
+ # Sat Mar 21 20:19:30 JST 2009
6
+ #
7
+
8
+ require File.dirname(__FILE__) + '/spec_base'
9
+
10
+
11
+ describe "#{SCHEDULER_CLASS}#schedule_at" do
12
+
13
+ before do
14
+ @s = start_scheduler
15
+ end
16
+ after do
17
+ stop_scheduler(@s)
18
+ end
19
+
20
+ it 'should have job ids with the class name in it' do
21
+
22
+ j0 = @s.at(Time.now + 1) {}
23
+ j0.job_id.should.match(/Rufus::Scheduler::AtJob/)
24
+ end
25
+
26
+ it "should accept integers as 'at'" do
27
+
28
+ lambda { @s.at(1) {} }.should.not.raise
29
+ end
30
+
31
+ it "should schedule at 'top + 1'" do
32
+
33
+ var = nil
34
+
35
+ @s.at Time.now + 1 do
36
+ var = true
37
+ end
38
+
39
+ var.should.be.nil
40
+ sleep 1.5
41
+
42
+ var.should.be.true
43
+ @s.jobs.should.be.empty
44
+ end
45
+
46
+ it 'should trigger immediately jobs in the past' do
47
+
48
+ var = nil
49
+
50
+ j = @s.at Time.now - 2 do
51
+ var = true
52
+ end
53
+
54
+ j.should.not.be.nil
55
+
56
+ #wait_next_tick
57
+ sleep 0.500
58
+
59
+ var.should.be.true
60
+ @s.jobs.should.be.empty
61
+ end
62
+
63
+ it 'should unschedule' do
64
+
65
+ job = @s.at Time.now + 3 * 3600 do
66
+ end
67
+
68
+ wait_next_tick
69
+
70
+ @s.jobs.size.should.equal(1)
71
+
72
+ @s.unschedule(job.job_id)
73
+
74
+ @s.jobs.size.should.equal(0)
75
+ end
76
+
77
+ it 'should accept tags for jobs' do
78
+
79
+ job = @s.at Time.now + 3 * 3600, :tags => 'spec' do
80
+ end
81
+
82
+ wait_next_tick
83
+
84
+ @s.find_by_tag('spec').size.should.equal(1)
85
+ @s.find_by_tag('spec').first.job_id.should.equal(job.job_id)
86
+ end
87
+
88
+ end
89
+
90
+ describe Rufus::Scheduler::AtJob do
91
+
92
+ before do
93
+ @s = start_scheduler
94
+ end
95
+ after do
96
+ stop_scheduler(@s)
97
+ end
98
+
99
+ it 'should unschedule itself' do
100
+
101
+ job = @s.at Time.now + 3 * 3600 do
102
+ end
103
+
104
+ wait_next_tick
105
+
106
+ job.unschedule
107
+
108
+ @s.jobs.size.should.equal(0)
109
+ end
110
+
111
+ it 'should respond to #next_time' do
112
+
113
+ t = Time.now + 3 * 3600
114
+
115
+ job = @s.at Time.now + 3 * 3600 do
116
+ end
117
+
118
+ job.next_time.to_i.should.equal(t.to_i)
119
+ end
120
+ end
121
+