say_when 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff56cfaa645736fcace3c95f0d9f20a35b7785aa2be6cd544caee8ecb3d0b537
4
- data.tar.gz: e04c3cbf9dfff48405d88a574aab8ebd1bf85bb747f6223efa3df184f9e485bb
3
+ metadata.gz: 39f0c8806fd8c11484d52818cb71a42e71e60b62c8cf19af670f8db7e06d3c17
4
+ data.tar.gz: 2e22ba68d95307e93f019381399ed46b257d5170dc45f5d99fb06d8cb7832b48
5
5
  SHA512:
6
- metadata.gz: 16b737f008959d234f85f9d8100bb5503500c6b0d8acdb5c78f9306e7c7ac7166571d9021a69daba2406e29e112cba8e0b0b27bd222edb7dfae6b2ceb62f8264
7
- data.tar.gz: 020d6842616be2b4984f6f7202279d09660646b112a7d0b24cffad38a6be711a1ee257f12eb4fc64aaa861816e2ba75673f773b4bca54c1af131b91029198ebe
6
+ metadata.gz: 9c11c37dea5355c17ac03ebfd589d769cd5526d11d34864b7890185e89aae593dfa92e58616dfa0305686c8885ac6eaaa65f955bf03d479c49151abe2385286a
7
+ data.tar.gz: 86790a64921d0f8cbbb92a11968bf036a76180c3d9fc40acec3cfd19a5e00e21c5a81f5e7029e3c23f0efbc8febc7bb8c2237f065b83e2788ac20f835e464c83
@@ -77,6 +77,18 @@ module SayWhen
77
77
  logger.info "SayWhen::Scheduler stopped"
78
78
  end
79
79
 
80
+ def process_waiting_jobs(max_jobs=1000)
81
+ jobs_processed = 0
82
+ while(jobs_processed < max_jobs)
83
+ if job = process_jobs
84
+ jobs_processed += 1
85
+ else
86
+ break
87
+ end
88
+ end
89
+ return jobs_processed
90
+ end
91
+
80
92
  def process_jobs
81
93
  job = nil
82
94
  time_now = Time.now
@@ -99,7 +111,7 @@ module SayWhen
99
111
  if job.nil?
100
112
  logger.debug "SayWhen:: no jobs to acquire, sleep"
101
113
  sleep(tick_length)
102
- return
114
+ return job
103
115
  end
104
116
 
105
117
  begin
@@ -115,12 +127,15 @@ module SayWhen
115
127
  job_error("Failure to process", job, ex)
116
128
  end
117
129
 
118
- rescue Interrupt => ex
119
- job_error("Interrupt!", job, ex)
120
- raise ex
130
+ return job
131
+
121
132
  rescue StandardError => ex
122
133
  job_error("Error!", job, ex)
123
134
  sleep(tick_length)
135
+ return job
136
+ rescue Interrupt => ex
137
+ job_error("Interrupt!", job, ex)
138
+ raise ex
124
139
  rescue Exception => ex
125
140
  job_error("Exception!", job, ex)
126
141
  raise ex
@@ -35,7 +35,7 @@ module SayWhen
35
35
  :order => 'next_fire_at ASC',
36
36
  :conditions => ['status = ? and ? >= next_fire_at',
37
37
  STATE_WAITING,
38
- no_later_than.in_time_zone('UTC')])
38
+ no_later_than])
39
39
 
40
40
  # set status to acquired to take it out of rotation
41
41
  @next_job.update_attribute(:status, STATE_ACQUIRED) unless @next_job.nil?
@@ -1,3 +1,3 @@
1
1
  module SayWhen
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -25,6 +25,7 @@ describe SayWhen::Scheduler do
25
25
  scheduler.storage_strategy = :active_record
26
26
  scheduler.processor_class = SayWhen::Test::TestProcessor
27
27
  end
28
+ SayWhen::Storage::ActiveRecord::Job.delete_all
28
29
 
29
30
  job = SayWhen::Scheduler.schedule(
30
31
  :trigger_strategy => 'once',
@@ -35,6 +36,58 @@ describe SayWhen::Scheduler do
35
36
  job.should_not be_nil
36
37
  end
37
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
38
91
  end
39
92
 
40
93
  describe "instance methods" do
@@ -69,8 +122,5 @@ describe SayWhen::Scheduler do
69
122
  # puts 'wait for it'
70
123
  @scheduler.running.should == false
71
124
  end
72
-
73
125
  end
74
-
75
-
76
126
  end
@@ -73,8 +73,7 @@ describe SayWhen::Storage::ActiveRecord::Job do
73
73
 
74
74
  j1 = SayWhen::Storage::ActiveRecord::Job.create(@valid_attributes)
75
75
  j2 = SayWhen::Storage::ActiveRecord::Job.create(j2_opts)
76
- acquire = 1.day.since
77
- next_job = SayWhen::Storage::ActiveRecord::Job.acquire_next(acquire)
76
+ next_job = SayWhen::Storage::ActiveRecord::Job.acquire_next(25.hours.since)
78
77
  next_job.should == j2
79
78
  end
80
79
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: say_when
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
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-04-12 00:00:00.000000000 Z
11
+ date: 2022-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemessaging