say_when 0.4.1 → 1.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. checksums.yaml +5 -5
  2. data/.gitignore +13 -4
  3. data/Gemfile +1 -9
  4. data/LICENSE +21 -0
  5. data/README.md +31 -0
  6. data/Rakefile +6 -6
  7. data/lib/generators/say_when/migration/migration_generator.rb +8 -5
  8. data/lib/generators/say_when/migration/templates/migration.rb +8 -7
  9. data/lib/say_when/base_job.rb +2 -0
  10. data/lib/say_when/cron_expression.rb +129 -191
  11. data/lib/say_when/processor/active_messaging.rb +7 -8
  12. data/lib/say_when/processor/base.rb +5 -3
  13. data/lib/say_when/processor/shoryuken.rb +14 -0
  14. data/lib/say_when/processor/simple.rb +2 -0
  15. data/lib/say_when/railtie.rb +9 -0
  16. data/lib/say_when/scheduler.rb +49 -90
  17. data/lib/say_when/storage/active_record/acts.rb +16 -16
  18. data/lib/say_when/storage/active_record/job.rb +17 -24
  19. data/lib/say_when/storage/active_record/job_execution.rb +5 -8
  20. data/lib/say_when/storage/memory/base.rb +3 -1
  21. data/lib/say_when/storage/memory/job.rb +14 -42
  22. data/lib/say_when/tasks.rb +4 -4
  23. data/lib/say_when/triggers/base.rb +4 -3
  24. data/lib/say_when/triggers/cron_strategy.rb +4 -3
  25. data/lib/say_when/triggers/instance_strategy.rb +4 -3
  26. data/lib/say_when/triggers/once_strategy.rb +3 -2
  27. data/lib/say_when/version.rb +3 -1
  28. data/lib/say_when.rb +8 -7
  29. data/lib/tasks/say_when.rake +3 -1
  30. data/say_when.gemspec +26 -19
  31. data/test/active_record_helper.rb +13 -0
  32. data/{spec → test}/db/schema.rb +4 -4
  33. data/{spec/spec_helper.rb → test/minitest_helper.rb} +9 -19
  34. data/test/say_when/cron_expression_spec.rb +74 -0
  35. data/{spec/say_when/processor/active_messaging_spec.rb → test/say_when/processor/active_messaging_test.rb} +17 -13
  36. data/test/say_when/scheduler_test.rb +75 -0
  37. data/test/say_when/storage/active_record/job_test.rb +90 -0
  38. data/test/say_when/storage/memory/job_test.rb +32 -0
  39. data/test/say_when/storage/memory/trigger_test.rb +54 -0
  40. data/test/say_when/triggers/once_strategy_test.rb +23 -0
  41. data/{spec → test}/support/models.rb +5 -3
  42. metadata +97 -54
  43. data/.travis.yml +0 -4
  44. data/generators/say_when_migration/say_when_migration_generator.rb +0 -11
  45. data/generators/say_when_migration/templates/migration.rb +0 -48
  46. data/spec/active_record_spec_helper.rb +0 -9
  47. data/spec/say_when/cron_expression_spec.rb +0 -72
  48. data/spec/say_when/scheduler_spec.rb +0 -126
  49. data/spec/say_when/storage/active_record/job_spec.rb +0 -97
  50. data/spec/say_when/storage/memory/job_spec.rb +0 -45
  51. data/spec/say_when/storage/memory/trigger_spec.rb +0 -54
  52. data/spec/say_when/triggers/once_strategy_spec.rb +0 -22
  53. data/spec/spec.opts +0 -4
metadata CHANGED
@@ -1,59 +1,73 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: say_when
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kuklewicz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-21 00:00:00.000000000 Z
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activemessaging
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
18
32
  - !ruby/object:Gem::Version
19
- version: 0.9.0
33
+ version: '0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - "~>"
38
+ - - ">="
25
39
  - !ruby/object:Gem::Version
26
- version: 0.9.0
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: activesupport
42
+ name: shoryuken
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - "~>"
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: 2.3.14
47
+ version: '0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - "~>"
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: 2.3.14
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: activerecord
56
+ name: activemessaging
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - "~>"
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: 2.3.14
61
+ version: '0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - "~>"
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: 2.3.14
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: rspec
70
+ name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
@@ -70,16 +84,44 @@ dependencies:
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: 10.5.0
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
81
116
  - !ruby/object:Gem::Version
82
- version: 10.5.0
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
83
125
  - !ruby/object:Gem::Dependency
84
126
  name: sqlite3
85
127
  requirement: !ruby/object:Gem::Requirement
@@ -94,19 +136,18 @@ dependencies:
94
136
  - - ">="
95
137
  - !ruby/object:Gem::Version
96
138
  version: '0'
97
- description:
139
+ description: Scheduling system for programmatically defined and stored jobs.
98
140
  email:
99
- - andrew@prx.org
141
+ - andrew@beginsinwonder.com
100
142
  executables: []
101
143
  extensions: []
102
144
  extra_rdoc_files: []
103
145
  files:
104
146
  - ".gitignore"
105
- - ".travis.yml"
106
147
  - Gemfile
148
+ - LICENSE
149
+ - README.md
107
150
  - Rakefile
108
- - generators/say_when_migration/say_when_migration_generator.rb
109
- - generators/say_when_migration/templates/migration.rb
110
151
  - lib/generators/.DS_Store
111
152
  - lib/generators/say_when/migration/migration_generator.rb
112
153
  - lib/generators/say_when/migration/templates/migration.rb
@@ -115,7 +156,9 @@ files:
115
156
  - lib/say_when/cron_expression.rb
116
157
  - lib/say_when/processor/active_messaging.rb
117
158
  - lib/say_when/processor/base.rb
159
+ - lib/say_when/processor/shoryuken.rb
118
160
  - lib/say_when/processor/simple.rb
161
+ - lib/say_when/railtie.rb
119
162
  - lib/say_when/scheduler.rb
120
163
  - lib/say_when/storage/active_record/acts.rb
121
164
  - lib/say_when/storage/active_record/job.rb
@@ -130,20 +173,20 @@ files:
130
173
  - lib/say_when/version.rb
131
174
  - lib/tasks/say_when.rake
132
175
  - say_when.gemspec
133
- - spec/active_record_spec_helper.rb
134
- - spec/db/schema.rb
135
- - spec/say_when/cron_expression_spec.rb
136
- - spec/say_when/processor/active_messaging_spec.rb
137
- - spec/say_when/scheduler_spec.rb
138
- - spec/say_when/storage/active_record/job_spec.rb
139
- - spec/say_when/storage/memory/job_spec.rb
140
- - spec/say_when/storage/memory/trigger_spec.rb
141
- - spec/say_when/triggers/once_strategy_spec.rb
142
- - spec/spec.opts
143
- - spec/spec_helper.rb
144
- - spec/support/models.rb
145
- homepage: http://labs.prx.org
146
- licenses: []
176
+ - test/active_record_helper.rb
177
+ - test/db/schema.rb
178
+ - test/minitest_helper.rb
179
+ - test/say_when/cron_expression_spec.rb
180
+ - test/say_when/processor/active_messaging_test.rb
181
+ - test/say_when/scheduler_test.rb
182
+ - test/say_when/storage/active_record/job_test.rb
183
+ - test/say_when/storage/memory/job_test.rb
184
+ - test/say_when/storage/memory/trigger_test.rb
185
+ - test/say_when/triggers/once_strategy_test.rb
186
+ - test/support/models.rb
187
+ homepage: https://github.com/kookster/say_when
188
+ licenses:
189
+ - MIT
147
190
  metadata: {}
148
191
  post_install_message:
149
192
  rdoc_options: []
@@ -160,20 +203,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
203
  - !ruby/object:Gem::Version
161
204
  version: '0'
162
205
  requirements: []
163
- rubygems_version: 3.1.4
206
+ rubyforge_project:
207
+ rubygems_version: 2.2.2
164
208
  signing_key:
165
209
  specification_version: 4
166
210
  summary: Scheduling system for programmatically defined and stored jobs.
167
211
  test_files:
168
- - spec/active_record_spec_helper.rb
169
- - spec/db/schema.rb
170
- - spec/say_when/cron_expression_spec.rb
171
- - spec/say_when/processor/active_messaging_spec.rb
172
- - spec/say_when/scheduler_spec.rb
173
- - spec/say_when/storage/active_record/job_spec.rb
174
- - spec/say_when/storage/memory/job_spec.rb
175
- - spec/say_when/storage/memory/trigger_spec.rb
176
- - spec/say_when/triggers/once_strategy_spec.rb
177
- - spec/spec.opts
178
- - spec/spec_helper.rb
179
- - spec/support/models.rb
212
+ - test/active_record_helper.rb
213
+ - test/db/schema.rb
214
+ - test/minitest_helper.rb
215
+ - test/say_when/cron_expression_spec.rb
216
+ - test/say_when/processor/active_messaging_test.rb
217
+ - test/say_when/scheduler_test.rb
218
+ - test/say_when/storage/active_record/job_test.rb
219
+ - test/say_when/storage/memory/job_test.rb
220
+ - test/say_when/storage/memory/trigger_test.rb
221
+ - test/say_when/triggers/once_strategy_test.rb
222
+ - test/support/models.rb
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.8.7
4
- script: bundle exec spec spec/
@@ -1,11 +0,0 @@
1
- class SayWhenMigrationGenerator < Rails::Generator::Base
2
- def manifest
3
- record do |m|
4
- m.migration_template 'migration.rb', 'db/migrate'
5
- end
6
- end
7
-
8
- def file_name
9
- "say_when_migration"
10
- end
11
- end
@@ -1,48 +0,0 @@
1
- class SayWhenMigration < ActiveRecord::Migration
2
- def self.up
3
-
4
- create_table :say_when_jobs, :force => true do |t|
5
-
6
- t.string :group
7
- t.string :name
8
-
9
- t.string :status
10
-
11
- t.string :trigger_strategy
12
- t.text :trigger_options
13
-
14
- t.timestamp :last_fire_at
15
- t.timestamp :next_fire_at
16
-
17
- t.timestamp :start_at
18
- t.timestamp :end_at
19
-
20
- t.string :job_class
21
- t.string :job_method
22
- t.text :data
23
-
24
- t.string :scheduled_type
25
- t.integer :scheduled_id
26
-
27
- t.timestamps
28
- end
29
-
30
- create_table :say_when_job_executions, :force => true do |t|
31
- t.integer :job_id
32
- t.string :status
33
- t.text :result
34
- t.datetime :start_at
35
- t.datetime :end_at
36
- end
37
-
38
- add_index :say_when_jobs, :status
39
- add_index :say_when_jobs, :next_fire_at
40
- add_index :say_when_job_executions, :job_id
41
- end
42
-
43
-
44
- def self.down
45
- drop_table :say_when_job_executions
46
- drop_table :say_when_jobs
47
- end
48
- end
@@ -1,9 +0,0 @@
1
- require 'active_record'
2
- require 'sqlite3'
3
-
4
- ActiveRecord::Base.establish_connection(
5
- :adapter => "sqlite3",
6
- :database => (File.dirname(__FILE__) + "/db/test.db")
7
- )
8
-
9
- require (File.dirname(__FILE__) + "/db/schema.rb")
@@ -1,72 +0,0 @@
1
- require_relative '../spec_helper'
2
-
3
- describe SayWhen::CronExpression do
4
-
5
- it "should set the time_zone" do
6
- @ce = SayWhen::CronExpression.new("0 0 12 ? * 1#1 *", 'Pacific Time (US & Canada)')
7
- @ce.time_zone.should == 'Pacific Time (US & Canada)'
8
- end
9
-
10
- describe 'get first sunday in the month with "1#1' do
11
-
12
- before do
13
- @ce = SayWhen::CronExpression.new("0 0 12 ? * 1#1 *", 'Pacific Time (US & Canada)')
14
- end
15
-
16
- it "finds first sunday in the same month" do
17
- @ce.next_fire_at(Time.utc(2008,1,1)).should == Time.parse('2008-01-06 12:00:00 -0800')
18
- end
19
-
20
-
21
- it "finds first sunday in the next month" do
22
- @ce.next_fire_at(Time.utc(2008,1,7)).should == Time.parse('2008-02-03 12:00:00 -0800')
23
- end
24
-
25
- it "finds last sunday in the same month" do
26
- @ce.last_fire_at(Time.utc(2008,1,10)).should == Time.parse('2008-01-06 12:00:00 -0800')
27
- end
28
-
29
- it "finds sundays in the prior months and years" do
30
- @ce.last_fire_at(Time.utc(2008,1,5)).should == Time.parse('2007-12-02 12:00:00 -0800')
31
- @ce.last_fire_at(Time.parse('2007-12-02 12:00:00 -0800') - 1.second).should == Time.parse('2007-11-04 12:00:00 -0800')
32
- @ce.last_fire_at(Time.parse('2007-11-04 12:00:00 -0800') - 1.second).should == Time.parse('2007-10-07 12:00:00 -0700')
33
- @ce.next_fire_at(Time.parse('2007-10-07 12:00:00 -0700') + 1.second).should == Time.parse('2007-11-04 12:00:00 -0800')
34
- end
35
- end
36
-
37
- describe 'get last sunday in the month with "1L"' do
38
- before do
39
- @ce = SayWhen::CronExpression.new("0 0 12 ? * 1L *", 'Pacific Time (US & Canada)')
40
- end
41
-
42
- it "gets next final sunday for same month" do
43
- @ce.next_fire_at(Time.utc(2008,1,1)).should == Time.parse('2008-01-27 12:00:00 -0800')
44
- end
45
-
46
-
47
- it "gets next final sunday for next month" do
48
- @ce.next_fire_at(Time.utc(2008,1,28)).should == Time.parse('2008-02-24 12:00:00 -0800')
49
- end
50
-
51
- it "gets last final sunday for same month" do
52
- @ce.last_fire_at(Time.utc(2008,1,28)).should == Time.parse('2008-01-27 12:00:00 -0800')
53
- end
54
-
55
- it "gets last sunday for prior month and year" do
56
- @ce.last_fire_at(Time.utc(2008,1,1)).should == Time.parse('2007-12-30 12:00:00 -0800')
57
- end
58
-
59
-
60
- it "gets last sunday for prior month and year" do
61
- nfa = @ce.last_fire_at(Time.utc(2007,12,1))
62
- nfa.should == Time.parse('2007-11-25 12:00:00 -0800')
63
-
64
- nfa = @ce.last_fire_at(nfa - 1.second)
65
- nfa.should == Time.parse('2007-10-28 12:00:00 -0700')
66
-
67
- nfa = @ce.next_fire_at(nfa + 1.second)
68
- nfa.should == Time.parse('2007-11-25 12:00:00 -0800')
69
- end
70
-
71
- end
72
- end
@@ -1,126 +0,0 @@
1
- require_relative '../spec_helper'
2
- require_relative '../active_record_spec_helper'
3
-
4
- describe SayWhen::Scheduler do
5
-
6
- describe "class methods" do
7
-
8
- it "can return singleton" do
9
- s = SayWhen::Scheduler.scheduler
10
- s.should_not be_nil
11
- s.should == SayWhen::Scheduler.scheduler
12
- end
13
-
14
- it "can be configured" do
15
- SayWhen::Scheduler.configure do |scheduler|
16
- scheduler.storage_strategy = :active_record
17
- scheduler.processor_class = SayWhen::Test::TestProcessor
18
- end
19
- SayWhen::Scheduler.scheduler.storage_strategy.should == :active_record
20
- SayWhen::Scheduler.scheduler.processor_class.should == SayWhen::Test::TestProcessor
21
- end
22
-
23
- it "can schedule a new job" do
24
- SayWhen::Scheduler.configure do |scheduler|
25
- scheduler.storage_strategy = :active_record
26
- scheduler.processor_class = SayWhen::Test::TestProcessor
27
- end
28
- SayWhen::Storage::ActiveRecord::Job.delete_all
29
-
30
- job = SayWhen::Scheduler.schedule(
31
- :trigger_strategy => 'once',
32
- :trigger_options => {:at => 10.second.since},
33
- :job_class => 'SayWhen::Test::TestTask',
34
- :job_method => 'execute'
35
- )
36
- job.should_not be_nil
37
- end
38
-
39
- it "can process jobs when there are no jobs" do
40
- SayWhen::Storage::ActiveRecord::Job.delete_all
41
-
42
- SayWhen::Scheduler.configure do |scheduler|
43
- scheduler.storage_strategy = :active_record
44
- scheduler.processor_class = SayWhen::Test::TestProcessor
45
- end
46
- job = SayWhen::Scheduler.scheduler.process_jobs
47
- job.should be_nil
48
- end
49
-
50
- it "can process jobs when there is a job" do
51
- SayWhen::Storage::ActiveRecord::Job.delete_all
52
-
53
- SayWhen::Scheduler.configure do |scheduler|
54
- scheduler.storage_strategy = :active_record
55
- scheduler.processor_class = SayWhen::Test::TestProcessor
56
- end
57
-
58
- job = SayWhen::Scheduler.schedule(
59
- :trigger_strategy => 'once',
60
- :trigger_options => {:at => 1.second.since},
61
- :job_class => 'SayWhen::Test::TestTask',
62
- :job_method => 'execute'
63
- )
64
- sleep(1)
65
-
66
- processed_job = SayWhen::Scheduler.scheduler.process_jobs
67
- processed_job.should_not be_nil
68
- processed_job.should == job
69
- end
70
-
71
- it "can process multiple waiting jobs" do
72
- SayWhen::Scheduler.configure do |scheduler|
73
- scheduler.storage_strategy = :active_record
74
- scheduler.processor_class = SayWhen::Test::TestProcessor
75
- end
76
- SayWhen::Storage::ActiveRecord::Job.delete_all
77
-
78
- opts = {
79
- :trigger_strategy => 'once',
80
- :trigger_options => {:at => 1.seconds.since},
81
- :job_class => 'SayWhen::Test::TestTask',
82
- :job_method => 'execute'
83
- }
84
-
85
- 10.times{ SayWhen::Scheduler.schedule(opts) }
86
- sleep(1)
87
-
88
- job_count = SayWhen::Scheduler.scheduler.process_waiting_jobs(100)
89
- job_count.should == 10
90
- end
91
- end
92
-
93
- describe "instance methods" do
94
-
95
- before(:all) do
96
- SayWhen::Scheduler.configure do |scheduler|
97
- scheduler.storage_strategy = :active_record
98
- scheduler.processor_class = SayWhen::Test::TestProcessor
99
- end
100
- @scheduler = SayWhen::Scheduler.scheduler
101
- end
102
-
103
- it "should instantiate the processor from its class" do
104
- @scheduler.processor.should be_a(SayWhen::Test::TestProcessor)
105
- end
106
-
107
- it "should get the job class based on the strategy" do
108
- @scheduler.job_class.should == SayWhen::Storage::ActiveRecord::Job
109
- end
110
-
111
- it "should start the scheduler running and stop it" do
112
- @scheduler.running.should be_false
113
-
114
- # puts 'starting'
115
- scheduler_thread = Thread.start{@scheduler.start}
116
- # puts 'started'
117
- sleep(0.1)
118
- @scheduler.running.should == true
119
-
120
- # puts 'stop'
121
- @scheduler.stop
122
- # puts 'wait for it'
123
- @scheduler.running.should == false
124
- end
125
- end
126
- end
@@ -1,97 +0,0 @@
1
- require_relative '../../../spec_helper'
2
- require_relative '../../../active_record_spec_helper'
3
- require_relative '../../../../lib/say_when/storage/active_record/job'
4
-
5
- describe SayWhen::Storage::ActiveRecord::Job do
6
-
7
- before(:each) do
8
- SayWhen::Storage::ActiveRecord::Job.delete_all
9
-
10
- @valid_attributes = {
11
- :trigger_strategy => :cron,
12
- :trigger_options => {:expression => '0 0 12 ? * * *', :time_zone => 'Pacific Time (US & Canada)'},
13
- :data => {:foo=>'bar', :result=>1},
14
- :job_class => 'SayWhen::Test::TestTask',
15
- :job_method => 'execute'
16
- }
17
- end
18
-
19
- it "can be instantiated" do
20
- j = SayWhen::Storage::ActiveRecord::Job.create!(@valid_attributes)
21
- j.should_not be_nil
22
- end
23
-
24
- it "can execute the task for the job" do
25
- j = SayWhen::Storage::ActiveRecord::Job.create(@valid_attributes)
26
- j.execute_job({:result=>1}).should == 1
27
- end
28
-
29
- it "can execute the job" do
30
- j = SayWhen::Storage::ActiveRecord::Job.create(@valid_attributes)
31
- j.execute.should == 1
32
- end
33
-
34
- it "derives a trigger from the attributes" do
35
- t = SayWhen::Storage::ActiveRecord::Job.create(@valid_attributes)
36
- t.trigger.should_not be_nil
37
- t.trigger.should be_a SayWhen::Triggers::CronStrategy
38
- end
39
-
40
- it "has a waiting state on create" do
41
- t = SayWhen::Storage::ActiveRecord::Job.create(@valid_attributes)
42
- t.status.should == SayWhen::BaseJob::STATE_WAITING
43
- end
44
-
45
- it "has a next fire at set on create" do
46
- opts = @valid_attributes[:trigger_options]
47
- ce = SayWhen::CronExpression.new(opts[:expression], opts[:time_zone])
48
- j = SayWhen::Storage::ActiveRecord::Job.create(@valid_attributes)
49
- j.status.should == SayWhen::BaseJob::STATE_WAITING
50
- j.next_fire_at.should == ce.next_fire_at
51
- end
52
-
53
- it "resets acquired jobs" do
54
- old = 2.hours.ago
55
- j = SayWhen::Storage::ActiveRecord::Job.create!(@valid_attributes.merge({
56
- :status => 'acquired', :updated_at => old, :created_at => old
57
- }))
58
-
59
- SayWhen::Storage::ActiveRecord::Job.reset_acquired(3600)
60
-
61
- j.reload
62
- j.status.should == 'waiting'
63
- end
64
-
65
- it "can find the next job" do
66
- j2_opts = {
67
- :trigger_strategy => :cron,
68
- :trigger_options => {:expression => '0 0 10 ? * * *', :time_zone => 'Pacific Time (US & Canada)'},
69
- :data => {:foo=>'can find the next job - j2', :result=>2},
70
- :job_class => 'SayWhen::Test::TestTask',
71
- :job_method => 'execute'
72
- }
73
-
74
- j1 = SayWhen::Storage::ActiveRecord::Job.create(@valid_attributes)
75
- j2 = SayWhen::Storage::ActiveRecord::Job.create(j2_opts)
76
- next_job = SayWhen::Storage::ActiveRecord::Job.acquire_next(25.hours.since)
77
- next_job.should == j2
78
- end
79
-
80
- it "can be fired" do
81
- opts = @valid_attributes[:trigger_options]
82
- ce = SayWhen::CronExpression.new(opts[:expression], opts[:time_zone])
83
- j = SayWhen::Storage::ActiveRecord::Job.create(@valid_attributes)
84
- nfa = ce.last_fire_at(j.created_at - 1.second)
85
- lfa = ce.last_fire_at(nfa - 1.second)
86
- j.next_fire_at = nfa
87
- j.last_fire_at = lfa
88
-
89
- now = Time.now
90
- Time.stub!(:now).and_return(now)
91
-
92
- j.fired
93
- j.next_fire_at.should == ce.next_fire_at(now)
94
- j.last_fire_at.should == now
95
- j.status.should == SayWhen::BaseJob::STATE_WAITING
96
- end
97
- end
@@ -1,45 +0,0 @@
1
- require_relative '../../../spec_helper'
2
- require_relative '../../../../lib/say_when/storage/memory/job'
3
-
4
- describe SayWhen::Store::Memory::Job do
5
-
6
- before(:each) do
7
- SayWhen::Store::Memory::Job._reset
8
- @valid_attributes = {
9
- :name => 'Memory::Job::Test',
10
- :group => 'Test',
11
- :data => {:foo=>'bar', :result=>1},
12
- :job_class => 'SayWhen::Test::TestTask',
13
- :job_method => 'execute'
14
- }
15
- end
16
-
17
- it "can be instantiated" do
18
- j = SayWhen::Store::Memory::Job.new(@valid_attributes)
19
- j.should_not be_nil
20
- end
21
-
22
- it "can execute the task for the job" do
23
- j = SayWhen::Store::Memory::Job.new(@valid_attributes)
24
- j.execute_job({:result=>1}).should == 1
25
- end
26
-
27
- it "can execute the job" do
28
- j = SayWhen::Store::Memory::Job.new(@valid_attributes)
29
- j.execute.should == 1
30
- end
31
-
32
- it "can reset acquired jobs" do
33
- j = SayWhen::Store::Memory::Job.new(@valid_attributes)
34
- j.status = 'acquired'
35
- j.updated_at = 2.hours.ago
36
- SayWhen::Store::Memory::Job.reset_acquired(3600)
37
- j.status.should == 'waiting'
38
- end
39
-
40
- it "can find the next job" do
41
- j = SayWhen::Store::Memory::Job.new(@valid_attributes)
42
- next_job = SayWhen::Store::Memory::Job.acquire_next(1.day.since)
43
- next_job.should == j
44
- end
45
- end