canvas-jobs 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce70c2ee3f74dfa74bfc81867ca03a9464d2b5a3
4
- data.tar.gz: 0b0f5c9037bf93ad1c779ac74745fd5edfdaaa2c
3
+ metadata.gz: 09c716227c64b63dd68ab787a2af74a625f8da29
4
+ data.tar.gz: f7683091496f7afac5085bb7d38d0eac48a810ec
5
5
  SHA512:
6
- metadata.gz: b2370e317be52bd5aa1654138c9d5eb45a8fd2764aa23901590a4c93c02522d1d6c8faaa1f6c43bf6a7c5e03e8c3b2d1b259efbd8a80238541400e469642e53b
7
- data.tar.gz: 8e530206e099787a4c96b57792a74b4ed6a9fc231a8a03d55cf0b00b452384d7e5b0e680c2be0c500b255a8b87ef56d922d876a9fcfa03dc46d8a8bba3bae209
6
+ metadata.gz: 262577e7b68a7bfd44cea42e3d1cacffb0f6bf4caa4df7ac7c230f560bb11e4f333ff0c19688820c8ce7a675638bbb57eb45c7a3e869f2b0d075553c690c6b26
7
+ data.tar.gz: ef2c55f222a31b8a38069cb6177efe339251ed37690633a9f1dda4bded4df89de506169317da6ad2c1d3104b8a9c265c8d9432683b732b32dbec557d09bcb382
@@ -191,8 +191,6 @@ class Job
191
191
  end
192
192
 
193
193
  def self.reconnect!
194
- self.redis ||= Redis.current
195
-
196
194
  # redis cluster responds to reconnect directly,
197
195
  # but individual redis needs it to be called on client
198
196
  redis.respond_to?(:reconnect) ?
@@ -457,7 +455,7 @@ class Job
457
455
  v = send(k)
458
456
  if v.nil?
459
457
  to_delete << k if !new_record? && changed.include?(k.to_s)
460
- elsif v.is_a?(ActiveSupport::TimeWithZone)
458
+ elsif v.is_a?(ActiveSupport::TimeWithZone) || v.is_a?(Time)
461
459
  attrs[k] = v.utc.to_f
462
460
  else
463
461
  attrs[k] = v.as_json
@@ -75,7 +75,7 @@ class Periodic
75
75
  alias_method :display_name, :tag
76
76
 
77
77
  def self.now
78
- Time.now
78
+ Time.zone.now
79
79
  end
80
80
  end
81
81
  end
data/lib/delayed/pool.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'erb'
1
2
  require 'optparse'
2
3
  require 'yaml'
3
4
  require 'fileutils'
@@ -21,10 +22,6 @@ class Pool
21
22
  end
22
23
 
23
24
  def run
24
- if GC.respond_to?(:copy_on_write_friendly=)
25
- GC.copy_on_write_friendly = true
26
- end
27
-
28
25
  op = OptionParser.new do |opts|
29
26
  opts.banner = "Usage #{$0} <command> <options>"
30
27
  opts.separator %{\nWhere <command> is one of:
@@ -309,7 +306,7 @@ class Pool
309
306
  end
310
307
 
311
308
  def read_config(config_filename)
312
- config = YAML.load_file(config_filename)
309
+ config = YAML.load(ERB.new(File.read(config_filename)).result)
313
310
  env = defined?(RAILS_ENV) ? RAILS_ENV : ENV['RAILS_ENV'] || 'development'
314
311
  @config = config[env] || config['default']
315
312
  # Backwards compatibility from when the config was just an array of queues
@@ -0,0 +1,32 @@
1
+ module Delayed
2
+ module Testing
3
+ def self.run_job(job)
4
+ Delayed::Worker.new.perform(job)
5
+ end
6
+
7
+ def self.drain
8
+ while job = Delayed::Job.get_and_lock_next_available(
9
+ 'spec run_jobs',
10
+ Delayed::Settings.queue,
11
+ 0,
12
+ Delayed::MAX_PRIORITY)
13
+ run_job(job)
14
+ end
15
+ end
16
+
17
+ def self.track_created
18
+ job_tracking = JobTracking.track { yield }
19
+ job_tracking.created
20
+ end
21
+
22
+ def self.clear_all!
23
+ case Delayed::Job.name
24
+ when /Redis/
25
+ Delayed::Job.redis.flushdb
26
+ when /ActiveRecord/
27
+ Delayed::Job.delete_all
28
+ Delayed::Job::Failed.delete_all
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Delayed
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
@@ -10,8 +10,7 @@ describe 'Delayed::Backed::ActiveRecord::Job' do
10
10
  end
11
11
 
12
12
  before do
13
- Delayed::Job.delete_all
14
- Delayed::Job::Failed.delete_all
13
+ Delayed::Testing.clear_all!
15
14
  end
16
15
 
17
16
  include_examples 'a delayed_jobs implementation'
@@ -4,3 +4,7 @@ gemspec :path=>"../../"
4
4
 
5
5
  gem "rails", "~> 3.2.19"
6
6
 
7
+ if RUBY_VERSION >= "2.0"
8
+ gem "syck"
9
+ end
10
+
@@ -1,13 +1,12 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- canvas-jobs (0.9.1)
4
+ canvas-jobs (0.9.3)
5
5
  after_transaction_commit (= 1.0.1)
6
6
  rails (>= 3.2)
7
7
  redis (> 3.0)
8
8
  redis-scripting (= 1.0.1)
9
9
  rufus-scheduler (= 2.0.6)
10
- syck
11
10
 
12
11
  GEM
13
12
  remote: https://rubygems.org/
@@ -135,6 +134,7 @@ DEPENDENCIES
135
134
  rails (~> 3.2.19)
136
135
  rake
137
136
  rspec
137
+ syck
138
138
  test_after_commit
139
139
  timecop
140
140
  wwtd
@@ -4,3 +4,6 @@ gemspec :path=>"../../"
4
4
 
5
5
  gem "rails", "~> 4.0.10"
6
6
 
7
+ if RUBY_VERSION >= "2.0"
8
+ gem "syck"
9
+ end
@@ -1,13 +1,12 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- canvas-jobs (0.9.1)
4
+ canvas-jobs (0.9.3)
5
5
  after_transaction_commit (= 1.0.1)
6
6
  rails (>= 3.2)
7
7
  redis (> 3.0)
8
8
  redis-scripting (= 1.0.1)
9
9
  rufus-scheduler (= 2.0.6)
10
- syck
11
10
 
12
11
  GEM
13
12
  remote: https://rubygems.org/
@@ -123,6 +122,7 @@ DEPENDENCIES
123
122
  rails (~> 4.0.10)
124
123
  rake
125
124
  rspec
125
+ syck
126
126
  test_after_commit
127
127
  timecop
128
128
  wwtd
@@ -4,3 +4,6 @@ gemspec :path=>"../../"
4
4
 
5
5
  gem "rails", "~> 4.1.6"
6
6
 
7
+ if RUBY_VERSION >= "2.0"
8
+ gem "syck"
9
+ end
@@ -1,13 +1,12 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- canvas-jobs (0.9.1)
4
+ canvas-jobs (0.9.3)
5
5
  after_transaction_commit (= 1.0.1)
6
6
  rails (>= 3.2)
7
7
  redis (> 3.0)
8
8
  redis-scripting (= 1.0.1)
9
9
  rufus-scheduler (= 2.0.6)
10
- syck
11
10
 
12
11
  GEM
13
12
  remote: https://rubygems.org/
@@ -129,6 +128,7 @@ DEPENDENCIES
129
128
  rails (~> 4.1.6)
130
129
  rake
131
130
  rspec
131
+ syck
132
132
  test_after_commit
133
133
  timecop
134
134
  wwtd
@@ -4,3 +4,6 @@ gemspec :path=>"../../"
4
4
 
5
5
  gem "rails", "~> 4.2.0.beta2"
6
6
 
7
+ if RUBY_VERSION >= "2.0"
8
+ gem "syck"
9
+ end
@@ -1,13 +1,12 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- canvas-jobs (0.9.1)
4
+ canvas-jobs (0.9.3)
5
5
  after_transaction_commit (= 1.0.1)
6
6
  rails (>= 3.2)
7
7
  redis (> 3.0)
8
8
  redis-scripting (= 1.0.1)
9
9
  rufus-scheduler (= 2.0.6)
10
- syck
11
10
 
12
11
  GEM
13
12
  remote: https://rubygems.org/
@@ -154,6 +153,7 @@ DEPENDENCIES
154
153
  rails (~> 4.2.0.beta2)
155
154
  rake
156
155
  rspec
156
+ syck
157
157
  test_after_commit
158
158
  timecop
159
159
  wwtd
@@ -10,7 +10,7 @@ describe 'Delayed::Backend::Redis::Job' do
10
10
  end
11
11
 
12
12
  before do
13
- Delayed::Job.redis.flushdb
13
+ Delayed::Testing.clear_all!
14
14
  end
15
15
 
16
16
  include_examples 'a delayed_jobs implementation'
@@ -0,0 +1,47 @@
1
+ shared_examples_for 'Delayed::Testing' do
2
+ class TestingWorker
3
+ cattr_accessor :runs
4
+
5
+ def self.run
6
+ self.runs += 1
7
+ end
8
+ end
9
+
10
+ before do
11
+ TestingWorker.runs = 0
12
+ end
13
+
14
+ describe '.run_job' do
15
+ it 'should run a single queued job' do
16
+ job = TestingWorker.send_later_enqueue_args(:run, no_delay: true)
17
+ Delayed::Testing.run_job(job)
18
+ expect(TestingWorker.runs).to eq 1
19
+ end
20
+ end
21
+
22
+ describe '.drain' do
23
+ it 'should run all queued jobs' do
24
+ 3.times { TestingWorker.send_later(:run) }
25
+ Delayed::Testing.drain
26
+ expect(TestingWorker.runs).to eq 3
27
+ end
28
+ end
29
+
30
+ describe 'track_created' do
31
+ it 'should return the list of jobs created in the block' do
32
+ 3.times { TestingWorker.send_later(:run) }
33
+ jobs = Delayed::Testing.track_created { 2.times { TestingWorker.send_later(:run) } }
34
+ expect(jobs.size).to eq 2
35
+ expect(jobs.first.tag).to eq "TestingWorker.run"
36
+ end
37
+ end
38
+
39
+ describe 'clear_all!' do
40
+ it 'should delete all queued jobs' do
41
+ 3.times { TestingWorker.send_later(:run) }
42
+ Delayed::Testing.clear_all!
43
+ Delayed::Testing.drain
44
+ expect(TestingWorker.runs).to eq 0
45
+ end
46
+ end
47
+ end
@@ -1,7 +1,8 @@
1
- require File.expand_path('../shared/shared_backend', __FILE__)
2
1
  require File.expand_path('../shared/delayed_batch', __FILE__)
3
2
  require File.expand_path('../shared/delayed_method', __FILE__)
4
3
  require File.expand_path('../shared/performable_method', __FILE__)
4
+ require File.expand_path('../shared/shared_backend', __FILE__)
5
+ require File.expand_path('../shared/testing', __FILE__)
5
6
  require File.expand_path('../shared/worker', __FILE__)
6
7
 
7
8
  shared_examples_for 'a delayed_jobs implementation' do
@@ -10,4 +11,5 @@ shared_examples_for 'a delayed_jobs implementation' do
10
11
  include_examples 'random ruby objects'
11
12
  include_examples 'Delayed::PerformableMethod'
12
13
  include_examples 'Delayed::Worker'
14
+ include_examples 'Delayed::Testing'
13
15
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'delayed_job'
2
+ require 'delayed/testing'
2
3
 
3
4
  require 'database_cleaner'
4
5
  require 'test_after_commit'
@@ -45,6 +46,8 @@ ActiveRecord::Base.establish_connection({
45
46
 
46
47
  ActiveRecord::Migrator.migrate("db/migrate")
47
48
  ActiveRecord::Migrator.migrate("spec/migrate")
49
+ Delayed::Backend::ActiveRecord::Job.reset_column_information
50
+ Delayed::Backend::ActiveRecord::Job::Failed.reset_column_information
48
51
 
49
52
  Time.zone = 'UTC'
50
53
  Rails.logger = Logger.new(nil)
@@ -84,7 +87,7 @@ ensure
84
87
  end
85
88
 
86
89
  def run_job(job)
87
- Delayed::Worker.new.perform(job)
90
+ Delayed::Testing.run_job(job)
88
91
  end
89
92
 
90
93
  require File.expand_path('../sample_jobs', __FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Luetke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-30 00:00:00.000000000 Z
12
+ date: 2014-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: after_transaction_commit
@@ -254,6 +254,7 @@ files:
254
254
  - lib/delayed/periodic.rb
255
255
  - lib/delayed/pool.rb
256
256
  - lib/delayed/settings.rb
257
+ - lib/delayed/testing.rb
257
258
  - lib/delayed/version.rb
258
259
  - lib/delayed/worker.rb
259
260
  - lib/delayed/yaml_extensions.rb
@@ -274,6 +275,7 @@ files:
274
275
  - spec/shared/delayed_method.rb
275
276
  - spec/shared/performable_method.rb
276
277
  - spec/shared/shared_backend.rb
278
+ - spec/shared/testing.rb
277
279
  - spec/shared/worker.rb
278
280
  - spec/shared_jobs_specs.rb
279
281
  - spec/spec_helper.rb
@@ -317,6 +319,7 @@ test_files:
317
319
  - spec/shared/delayed_method.rb
318
320
  - spec/shared/performable_method.rb
319
321
  - spec/shared/shared_backend.rb
322
+ - spec/shared/testing.rb
320
323
  - spec/shared/worker.rb
321
324
  - spec/shared_jobs_specs.rb
322
325
  - spec/spec_helper.rb