delayed_job_active_record 4.1.2 → 4.1.3

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
- SHA1:
3
- metadata.gz: 587c2fcfd39aed7965f484c0e9ba9bc94dba926b
4
- data.tar.gz: d71c55d818a0e780d972bb35c0d665195e47467e
2
+ SHA256:
3
+ metadata.gz: 3bdebcffb191581b743a334926d45c01184fbe0a58a906741b0f7f73118375bc
4
+ data.tar.gz: fdc7e1c5c74cd0f5beef00a61d62daaf3bf91d2ca631248a7a2a7382f3d420d9
5
5
  SHA512:
6
- metadata.gz: 123564b7b3f54d4ee8cdd1673e5fb5471f564e1306a69c3fc07e4e6b4ea6608f448f493170840137604705731ba9e5f488c00ed6a1272fd9f263622e83db385e
7
- data.tar.gz: fa7fff077b2f611118b21abf9e106cf8b210c5ad1b9404dc9c6c8c678164f991486bd38f885e062cef233d4a082c03badca4bc333bec92f25d138215b0215184
6
+ metadata.gz: 443633226e38e35bf47be09f548b9bdc1aea188f7c74244b32d8cbbd6b18cac0fd04bffac8540f075e3cc18cd737937f7049a16cc39a363be4fea6cfc9097471
7
+ data.tar.gz: c479df41fa2326aef35d02771336c17ba5ce956aa1c006769b1a67f4282e716c161d723cfd479178f24bbc21b5fdf6183e656a867d3221cf8753d21c7b800cbd
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  **If you're viewing this at https://github.com/collectiveidea/delayed_job_active_record,
2
2
  you're reading the documentation for the master branch.
3
3
  [View documentation for the latest release
4
- (4.1.2).](https://github.com/collectiveidea/delayed_job_active_record/tree/v4.1.2)**
4
+ (4.1.3).](https://github.com/collectiveidea/delayed_job_active_record/tree/v4.1.3)**
5
5
 
6
6
  # DelayedJob ActiveRecord Backend
7
7
 
@@ -1,14 +1,14 @@
1
1
  Gem::Specification.new do |spec|
2
- spec.add_dependency "activerecord", [">= 3.0", "< 5.2"]
2
+ spec.add_dependency "activerecord", [">= 3.0", "< 5.3"]
3
3
  spec.add_dependency "delayed_job", [">= 3.0", "< 5"]
4
4
  spec.authors = ["Brian Ryckbost", "Matt Griffin", "Erik Michaels-Ober"]
5
5
  spec.description = "ActiveRecord backend for Delayed::Job, originally authored by Tobias Lütke"
6
6
  spec.email = ["bryckbost@gmail.com", "matt@griffinonline.org", "sferik@gmail.com"]
7
- spec.files = %w(CONTRIBUTING.md LICENSE.md README.md delayed_job_active_record.gemspec) + Dir["lib/**/*.rb"]
7
+ spec.files = %w[CONTRIBUTING.md LICENSE.md README.md delayed_job_active_record.gemspec] + Dir["lib/**/*.rb"]
8
8
  spec.homepage = "http://github.com/collectiveidea/delayed_job_active_record"
9
9
  spec.licenses = ["MIT"]
10
10
  spec.name = "delayed_job_active_record"
11
11
  spec.require_paths = ["lib"]
12
12
  spec.summary = "ActiveRecord backend for DelayedJob"
13
- spec.version = "4.1.2"
13
+ spec.version = "4.1.3"
14
14
  end
@@ -10,7 +10,9 @@ module Delayed
10
10
  end
11
11
 
12
12
  def reserve_sql_strategy=(val)
13
- raise ArgumentError, "allowed values are :optimized_sql or :default_sql" unless val == :optimized_sql || val == :default_sql
13
+ if !(val == :optimized_sql || val == :default_sql)
14
+ raise ArgumentError, "allowed values are :optimized_sql or :default_sql"
15
+ end
14
16
  @reserve_sql_strategy = val
15
17
  end
16
18
  end
@@ -34,6 +36,9 @@ module Delayed
34
36
  end
35
37
 
36
38
  scope :by_priority, lambda { order("priority ASC, run_at ASC") }
39
+ scope :min_priority, lambda { where("priority >= ?", Worker.min_priority) if Worker.min_priority }
40
+ scope :max_priority, lambda { where("priority <= ?", Worker.max_priority) if Worker.max_priority }
41
+ scope :for_queues, lambda { |queues = Worker.queues| where(queue: queues) if Array(queues).any? }
37
42
 
38
43
  before_save :set_default_run_at
39
44
 
@@ -45,7 +50,12 @@ module Delayed
45
50
  set_delayed_job_table_name
46
51
 
47
52
  def self.ready_to_run(worker_name, max_run_time)
48
- where("(run_at <= ? AND (locked_at IS NULL OR locked_at < ?) OR locked_by = ?) AND failed_at IS NULL", db_time_now, db_time_now - max_run_time, worker_name)
53
+ where(
54
+ "(run_at <= ? AND (locked_at IS NULL OR locked_at < ?) OR locked_by = ?) AND failed_at IS NULL",
55
+ db_time_now,
56
+ db_time_now - max_run_time,
57
+ worker_name
58
+ )
49
59
  end
50
60
 
51
61
  def self.before_fork
@@ -61,15 +71,13 @@ module Delayed
61
71
  where(locked_by: worker_name).update_all(locked_by: nil, locked_at: nil)
62
72
  end
63
73
 
64
- def self.reserve(worker, max_run_time = Worker.max_run_time) # rubocop:disable CyclomaticComplexity
65
- # scope to filter to records that are "ready to run"
66
- ready_scope = ready_to_run(worker.name, max_run_time)
67
-
68
- # scope to filter to the single next eligible job
69
- ready_scope = ready_scope.where("priority >= ?", Worker.min_priority) if Worker.min_priority
70
- ready_scope = ready_scope.where("priority <= ?", Worker.max_priority) if Worker.max_priority
71
- ready_scope = ready_scope.where(queue: Worker.queues) if Worker.queues.any?
72
- ready_scope = ready_scope.by_priority
74
+ def self.reserve(worker, max_run_time = Worker.max_run_time)
75
+ ready_scope =
76
+ ready_to_run(worker.name, max_run_time)
77
+ .min_priority
78
+ .max_priority
79
+ .for_queues
80
+ .by_priority
73
81
 
74
82
  reserve_with_scope(ready_scope, worker, db_time_now)
75
83
  end
@@ -88,41 +96,12 @@ module Delayed
88
96
 
89
97
  def self.reserve_with_scope_using_optimized_sql(ready_scope, worker, now)
90
98
  case connection.adapter_name
91
- when "PostgreSQL"
92
- # Custom SQL required for PostgreSQL because postgres does not support UPDATE...LIMIT
93
- # This locks the single record 'FOR UPDATE' in the subquery
94
- # http://www.postgresql.org/docs/9.0/static/sql-select.html#SQL-FOR-UPDATE-SHARE
95
- # Note: active_record would attempt to generate UPDATE...LIMIT like
96
- # SQL for Postgres if we use a .limit() filter, but it would not
97
- # use 'FOR UPDATE' and we would have many locking conflicts
98
- quoted_table_name = connection.quote_table_name(table_name)
99
- subquery_sql = ready_scope.limit(1).lock(true).select("id").to_sql
100
- reserved = find_by_sql(["UPDATE #{quoted_table_name} SET locked_at = ?, locked_by = ? WHERE id IN (#{subquery_sql}) RETURNING *", now, worker.name])
101
- reserved[0]
99
+ when "PostgreSQL", "PostGIS"
100
+ reserve_with_scope_using_optimized_postgres(ready_scope, worker, now)
102
101
  when "MySQL", "Mysql2"
103
- # Removing the millisecond precision from now(time object)
104
- # MySQL 5.6.4 onwards millisecond precision exists, but the
105
- # datetime object created doesn't have precision, so discarded
106
- # while updating. But during the where clause, for mysql(>=5.6.4),
107
- # it queries with precision as well. So removing the precision
108
- now = now.change(usec: 0)
109
- # This works on MySQL and possibly some other DBs that support
110
- # UPDATE...LIMIT. It uses separate queries to lock and return the job
111
- count = ready_scope.limit(1).update_all(locked_at: now, locked_by: worker.name)
112
- return nil if count == 0
113
- where(locked_at: now, locked_by: worker.name, failed_at: nil).first
102
+ reserve_with_scope_using_optimized_mysql(ready_scope, worker, now)
114
103
  when "MSSQL", "Teradata"
115
- # The MSSQL driver doesn't generate a limit clause when update_all
116
- # is called directly
117
- subsubquery_sql = ready_scope.limit(1).to_sql
118
- # select("id") doesn't generate a subquery, so force a subquery
119
- subquery_sql = "SELECT id FROM (#{subsubquery_sql}) AS x"
120
- quoted_table_name = connection.quote_table_name(table_name)
121
- sql = ["UPDATE #{quoted_table_name} SET locked_at = ?, locked_by = ? WHERE id IN (#{subquery_sql})", now, worker.name]
122
- count = connection.execute(sanitize_sql(sql))
123
- return nil if count == 0
124
- # MSSQL JDBC doesn't support OUTPUT INSERTED.* for returning a result set, so query locked row
125
- where(locked_at: now, locked_by: worker.name, failed_at: nil).first
104
+ reserve_with_scope_using_optimized_mssql(ready_scope, worker, now)
126
105
  # Fallback for unknown / other DBMS
127
106
  else
128
107
  reserve_with_scope_using_default_sql(ready_scope, worker, now)
@@ -137,6 +116,48 @@ module Delayed
137
116
  end
138
117
  end
139
118
 
119
+ def self.reserve_with_scope_using_optimized_postgres(ready_scope, worker, now)
120
+ # Custom SQL required for PostgreSQL because postgres does not support UPDATE...LIMIT
121
+ # This locks the single record 'FOR UPDATE' in the subquery
122
+ # http://www.postgresql.org/docs/9.0/static/sql-select.html#SQL-FOR-UPDATE-SHARE
123
+ # Note: active_record would attempt to generate UPDATE...LIMIT like
124
+ # SQL for Postgres if we use a .limit() filter, but it would not
125
+ # use 'FOR UPDATE' and we would have many locking conflicts
126
+ quoted_name = connection.quote_table_name(table_name)
127
+ subquery = ready_scope.limit(1).lock(true).select("id").to_sql
128
+ sql = "UPDATE #{quoted_name} SET locked_at = ?, locked_by = ? WHERE id IN (#{subquery}) RETURNING *"
129
+ reserved = find_by_sql([sql, now, worker.name])
130
+ reserved[0]
131
+ end
132
+
133
+ def self.reserve_with_scope_using_optimized_mysql(ready_scope, worker, now)
134
+ # Removing the millisecond precision from now(time object)
135
+ # MySQL 5.6.4 onwards millisecond precision exists, but the
136
+ # datetime object created doesn't have precision, so discarded
137
+ # while updating. But during the where clause, for mysql(>=5.6.4),
138
+ # it queries with precision as well. So removing the precision
139
+ now = now.change(usec: 0)
140
+ # This works on MySQL and possibly some other DBs that support
141
+ # UPDATE...LIMIT. It uses separate queries to lock and return the job
142
+ count = ready_scope.limit(1).update_all(locked_at: now, locked_by: worker.name)
143
+ return nil if count == 0
144
+ where(locked_at: now, locked_by: worker.name, failed_at: nil).first
145
+ end
146
+
147
+ def self.reserve_with_scope_using_optimized_mssql(ready_scope, worker, now)
148
+ # The MSSQL driver doesn't generate a limit clause when update_all
149
+ # is called directly
150
+ subsubquery_sql = ready_scope.limit(1).to_sql
151
+ # select("id") doesn't generate a subquery, so force a subquery
152
+ subquery_sql = "SELECT id FROM (#{subsubquery_sql}) AS x"
153
+ quoted_table_name = connection.quote_table_name(table_name)
154
+ sql = "UPDATE #{quoted_table_name} SET locked_at = ?, locked_by = ? WHERE id IN (#{subquery_sql})"
155
+ count = connection.execute(sanitize_sql([sql, now, worker.name]))
156
+ return nil if count == 0
157
+ # MSSQL JDBC doesn't support OUTPUT INSERTED.* for returning a result set, so query locked row
158
+ where(locked_at: now, locked_by: worker.name, failed_at: nil).first
159
+ end
160
+
140
161
  # Get the current time (GMT or local depending on DB)
141
162
  # Note: This does not ping the DB to get the time, so all your clients
142
163
  # must have syncronized clocks.
@@ -146,7 +167,7 @@ module Delayed
146
167
  elsif ::ActiveRecord::Base.default_timezone == :utc
147
168
  Time.now.utc
148
169
  else
149
- Time.now
170
+ Time.now # rubocop:disable Rails/TimeZone
150
171
  end
151
172
  end
152
173
 
@@ -22,9 +22,7 @@ module DelayedJob
22
22
  private
23
23
 
24
24
  def migration_version
25
- if ActiveRecord::VERSION::MAJOR >= 5
26
- "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
27
- end
25
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" if ActiveRecord::VERSION::MAJOR >= 5
28
26
  end
29
27
  end
30
28
  end
@@ -7,7 +7,11 @@ require "rails/generators/active_record"
7
7
  module DelayedJob
8
8
  class UpgradeGenerator < ActiveRecordGenerator
9
9
  def create_migration_file
10
- migration_template "upgrade_migration.rb", "db/migrate/add_queue_to_delayed_jobs.rb", migration_version: migration_version
10
+ migration_template(
11
+ "upgrade_migration.rb",
12
+ "db/migrate/add_queue_to_delayed_jobs.rb",
13
+ migration_version: migration_version
14
+ )
11
15
  end
12
16
  end
13
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_job_active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.2
4
+ version: 4.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Ryckbost
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-05-27 00:00:00.000000000 Z
13
+ date: 2018-04-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '3.0'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '5.2'
24
+ version: '5.3'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +31,7 @@ dependencies:
31
31
  version: '3.0'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '5.2'
34
+ version: '5.3'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: delayed_job
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubyforge_project:
96
- rubygems_version: 2.6.11
96
+ rubygems_version: 2.7.6
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: ActiveRecord backend for DelayedJob