talentbox-delayed_job_sequel 4.2.0 → 4.2.1

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: d9df707759cfb493fe5e571ad10821e3506a8462
4
- data.tar.gz: cfede796ece37d2adc97ea8b3f7ac3bb084d1750
3
+ metadata.gz: 4302cd23662982c235f239ad688b7e625590bef5
4
+ data.tar.gz: 216726ccad71885a93664e0478d2f2719d0ae4f0
5
5
  SHA512:
6
- metadata.gz: c20129c55cbc45d31ea37322378957dff34f355d2258bf08c9510e0e648b120cb53b3d1af12a90f321e671ed2a216fdef9e211e38ff1650e2b08680bf8fed815
7
- data.tar.gz: be4523110985804fd3a8ef06746f5a6d43d70f77db5a059c2ebd47436fb5d84a9f537170e1a4627b0304a4d1940fb639c8147b802e9866965206e72cbb7a7e90
6
+ metadata.gz: f124eca09c6ed6276f61c89223cda8509fff8d39019b52b1faca646bd1469c4d649282e4de261f530c17f77e515dfbd37e1a48c70d425c30db2675d584f5490a
7
+ data.tar.gz: 24862b85887f74e7235ae1675f284ea69343840e2634204222c84eba8d9b4d82d677226485cc0eff388ee5b3ec53c8fd67c19689fd642015edf89a10d5caee26
@@ -13,21 +13,26 @@ module Delayed
13
13
  set_default_run_at
14
14
  end
15
15
 
16
- def_dataset_method :ready_to_run do |worker_name, max_run_time|
17
- db_time_now = model.db_time_now
18
- lock_upper_bound = db_time_now - max_run_time
19
- filter do
20
- (
21
- (run_at <= db_time_now) &
22
- ::Sequel.expr(:locked_at => nil) |
23
- (::Sequel.expr(:locked_at) < lock_upper_bound) |
24
- {:locked_by => worker_name}
25
- ) & {:failed_at => nil}
16
+ dataset_module do
17
+ def ready_to_run(worker_name, max_run_time)
18
+ db_time_now = model.db_time_now
19
+ lock_upper_bound = db_time_now - max_run_time
20
+ filter do
21
+ (
22
+ (run_at <= db_time_now) &
23
+ ::Sequel.expr(:locked_at => nil) |
24
+ (::Sequel.expr(:locked_at) < lock_upper_bound) |
25
+ {:locked_by => worker_name}
26
+ ) & {:failed_at => nil}
27
+ end
26
28
  end
27
- end
28
29
 
29
- def_dataset_method :by_priority do
30
- order(::Sequel.expr(:priority).asc, ::Sequel.expr(:run_at).asc)
30
+ def by_priority
31
+ order(
32
+ ::Sequel.expr(:priority).asc,
33
+ ::Sequel.expr(:run_at).asc
34
+ )
35
+ end
31
36
  end
32
37
 
33
38
  def self.before_fork
@@ -41,8 +46,8 @@ module Delayed
41
46
 
42
47
  def self.reserve(worker, max_run_time = Worker.max_run_time)
43
48
  ds = ready_to_run(worker.name, max_run_time)
44
- ds = ds.filter("priority >= ?", Worker.min_priority) if Worker.min_priority
45
- ds = ds.filter("priority <= ?", Worker.max_priority) if Worker.max_priority
49
+ ds = ds.filter(::Sequel.lit("priority >= ?", Worker.min_priority)) if Worker.min_priority
50
+ ds = ds.filter(::Sequel.lit("priority <= ?", Worker.max_priority)) if Worker.max_priority
46
51
  ds = ds.filter(:queue => Worker.queues) if Worker.queues.any?
47
52
  ds = ds.by_priority
48
53
  ds = ds.for_update
@@ -101,7 +106,13 @@ module Delayed
101
106
 
102
107
  def self.count(attrs={})
103
108
  if attrs.respond_to?(:has_key?) && attrs.has_key?(:conditions)
104
- ds = self.where(attrs[:conditions])
109
+ conditions = case attrs[:conditions]
110
+ when Array
111
+ ::Sequel.lit(*attrs[:conditions])
112
+ else
113
+ ::Sequel.lit(attrs[:conditions])
114
+ end
115
+ ds = self.where conditions
105
116
  if attrs.has_key?(:group)
106
117
  column = attrs[:group]
107
118
  group_and_count(column.to_sym).map do |record|
@@ -33,7 +33,7 @@ module Delayed
33
33
  def init_with(coder)
34
34
  @values = coder["values"]
35
35
  reload
36
- rescue Sequel::Error
36
+ rescue ::Sequel::Error
37
37
  raise Delayed::DeserializationError, "Sequel Record not found, class: #{self.class.name} , primary key: #{pk}"
38
38
  end
39
39
  end
@@ -13,7 +13,7 @@ describe Delayed::Backend::Sequel::Job do
13
13
  it_should_behave_like "a delayed_job backend"
14
14
 
15
15
  it "does not allow more than 1 worker to grab the same job" do
16
- expect {
16
+ expect do
17
17
  10.times do
18
18
  described_class.create(payload_object: SimpleJob.new)
19
19
  end
@@ -25,7 +25,7 @@ describe Delayed::Backend::Sequel::Job do
25
25
  worker.work_off(4)
26
26
  end
27
27
  end.map(&:join)
28
- }.not_to raise_error
28
+ end.not_to raise_error
29
29
 
30
30
  expect(Delayed::Job.count).to be < 10
31
31
  end
@@ -35,8 +35,12 @@ describe Delayed::Backend::Sequel::Job do
35
35
  it "allow count with conditions" do
36
36
  described_class.create(failed_at: Time.now)
37
37
  expect do
38
- Delayed::Job.count(:conditions => "failed_at is not NULL").should eq 1
39
- Delayed::Job.count(:conditions => "locked_by is not NULL").should eq 0
38
+ expect(
39
+ Delayed::Job.count(:conditions => "failed_at is not NULL")
40
+ ).to eq 1
41
+ expect(
42
+ Delayed::Job.count(:conditions => "locked_by is not NULL")
43
+ ).to eq 0
40
44
  end.to_not raise_error
41
45
  end
42
46
 
@@ -44,8 +48,12 @@ describe Delayed::Backend::Sequel::Job do
44
48
  described_class.create(queue: "slow", priority: 2)
45
49
  described_class.create(queue: "important", priority: 1)
46
50
  expect do
47
- Delayed::Job.count(:group => "queue", :conditions => ['run_at < ? and failed_at is NULL', Time.now]).should =~ [["slow", 1], ["important", 1]]
48
- Delayed::Job.count(:group => "priority", :conditions => ['run_at < ? and failed_at is NULL', Time.now]).should =~ [[1, 1], [2, 1]]
51
+ expect(
52
+ Delayed::Job.count(:group => "queue", :conditions => ['run_at < ? and failed_at is NULL', Time.now])
53
+ ).to match_array [["slow", 1], ["important", 1]]
54
+ expect(
55
+ Delayed::Job.count(:group => "priority", :conditions => ['run_at < ? and failed_at is NULL', Time.now])
56
+ ).to match_array [[1, 1], [2, 1]]
49
57
  end.to_not raise_error
50
58
  end
51
59
  end
@@ -54,25 +62,31 @@ describe Delayed::Backend::Sequel::Job do
54
62
  context "db_time_now" do
55
63
  it "should return time in current time zone if set" do
56
64
  Time.zone = "Eastern Time (US & Canada)"
57
- %w(EST EDT).should include(Delayed::Job.db_time_now.zone)
65
+ expect(
66
+ %w(EST EDT)
67
+ ).to include(Delayed::Job.db_time_now.zone)
58
68
  end
59
69
 
60
70
  it "should return UTC time if that is the Sequel.database_timezone default" do
61
71
  Time.zone = nil
62
72
  Sequel.database_timezone = :utc
63
- Delayed::Backend::Sequel::Job.db_time_now.zone.should == "UTC"
73
+ expect(
74
+ Delayed::Backend::Sequel::Job.db_time_now.zone
75
+ ).to eql "UTC"
64
76
  end
65
77
 
66
78
  it "should return local time if that is the AR default" do
67
79
  Time.zone = "Central Time (US & Canada)"
68
80
  Sequel.database_timezone = :local
69
- %w(CST CDT).should include(Delayed::Backend::Sequel::Job.db_time_now.zone)
81
+ expect(
82
+ %w(CST CDT)
83
+ ).to include(Delayed::Backend::Sequel::Job.db_time_now.zone)
70
84
  end
71
85
  end
72
86
 
73
87
  describe "before_fork" do
74
88
  it "should call disconnect on the connection" do
75
- Sequel::Model.db.should_receive(:disconnect)
89
+ expect( Sequel::Model.db ).to receive(:disconnect)
76
90
  Delayed::Backend::Sequel::Job.before_fork
77
91
  end
78
92
  end
@@ -81,10 +95,14 @@ describe Delayed::Backend::Sequel::Job do
81
95
  it "should allow enqueue hook to modify job at DB level" do
82
96
  later = described_class.db_time_now + 20.minutes
83
97
  job = Delayed::Backend::Sequel::Job.enqueue :payload_object => EnqueueJobMod.new
84
- Delayed::Backend::Sequel::Job[job.id].run_at.should be_within(1).of(later)
98
+ expect(
99
+ Delayed::Backend::Sequel::Job[job.id].run_at
100
+ ).to be_within(1).of(later)
85
101
  end
86
102
  end
103
+ end
87
104
 
105
+ describe Delayed::Backend::Sequel::Job, "override table name" do
88
106
  it "allows to override the table name" do
89
107
  ::Sequel::Model.db.transaction :rollback => :always do
90
108
  begin
@@ -105,11 +123,11 @@ describe Delayed::Backend::Sequel::Job do
105
123
  end
106
124
  change_table_name :another_delayed_jobs
107
125
 
108
- Delayed::Job.table_name.should == :another_delayed_jobs
126
+ expect( Delayed::Job.table_name ).to eql :another_delayed_jobs
109
127
  ensure
110
128
  change_table_name nil
111
129
  # Replace described_class with reloaded
112
- self.class.metadata[:example_group][:described_class] = ::Delayed::Backend::Sequel::Job
130
+ self.class.metadata[:described_class] = ::Delayed::Backend::Sequel::Job
113
131
  end
114
132
  end
115
133
  end
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe Sequel::Model do
4
4
  it 'should load classes with non-default primary key' do
5
- lambda {
5
+ expect do
6
6
  YAML.load(Story.create.to_yaml)
7
- }.should_not raise_error
7
+ end.not_to raise_error
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: talentbox-delayed_job_sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Tron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-10 00:00:00.000000000 Z
11
+ date: 2017-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -64,14 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '2.13'
67
+ version: 3.6.0
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '2.13'
74
+ version: 3.6.0
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rake
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  requirements: []
129
129
  rubyforge_project:
130
- rubygems_version: 2.4.5.1
130
+ rubygems_version: 2.5.1
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: Sequel backend for DelayedJob