delayed 2.0.2 → 2.1.0
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 +4 -4
- data/lib/delayed/monitor.rb +77 -21
- data/lib/delayed/tasks.rb +31 -11
- data/lib/delayed/version.rb +1 -1
- data/spec/delayed/__snapshots__/monitor_spec.rb.snap +681 -303
- data/spec/delayed/job_spec.rb +0 -6
- data/spec/delayed/monitor_spec.rb +292 -221
- data/spec/helper.rb +21 -11
- metadata +2 -2
data/spec/helper.rb
CHANGED
|
@@ -38,13 +38,12 @@ end
|
|
|
38
38
|
|
|
39
39
|
ENV['RAILS_ENV'] = 'test'
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
db_adapter ||= "sqlite3"
|
|
41
|
+
def current_adapter
|
|
42
|
+
ENV.fetch('ADAPTER', 'sqlite3')
|
|
43
|
+
end
|
|
45
44
|
|
|
46
45
|
config = YAML.load(ERB.new(File.read("spec/database.yml")).result)
|
|
47
|
-
ActiveRecord::Base.establish_connection config[
|
|
46
|
+
ActiveRecord::Base.establish_connection config[current_adapter]
|
|
48
47
|
ActiveRecord::Base.logger = Delayed.logger
|
|
49
48
|
ActiveJob::Base.logger = Delayed.logger
|
|
50
49
|
ActiveRecord::Migration.verbose = false
|
|
@@ -58,7 +57,7 @@ end
|
|
|
58
57
|
# MySQL 5.7 no longer supports null default values for the primary key
|
|
59
58
|
# Override the default primary key type in Rails <= 4.0
|
|
60
59
|
# https://stackoverflow.com/a/34555109
|
|
61
|
-
if
|
|
60
|
+
if current_adapter == "mysql2"
|
|
62
61
|
types = if defined?(ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter)
|
|
63
62
|
# ActiveRecord 3.2+
|
|
64
63
|
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::NATIVE_DATABASE_TYPES
|
|
@@ -208,6 +207,14 @@ else
|
|
|
208
207
|
ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__)
|
|
209
208
|
end
|
|
210
209
|
|
|
210
|
+
def default_timezone=(zone)
|
|
211
|
+
if ActiveRecord::VERSION::MAJOR >= 7
|
|
212
|
+
ActiveRecord.default_timezone = zone
|
|
213
|
+
else
|
|
214
|
+
ActiveRecord::Base.default_timezone = zone
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
211
218
|
RSpec::Matchers.define :emit_notification do |expected_event_name|
|
|
212
219
|
attr_reader :actual, :expected
|
|
213
220
|
|
|
@@ -217,10 +224,15 @@ RSpec::Matchers.define :emit_notification do |expected_event_name|
|
|
|
217
224
|
|
|
218
225
|
chain :with_payload, :expected_payload
|
|
219
226
|
chain :with_value, :expected_value
|
|
227
|
+
chain(:approximately) { @approximately = true }
|
|
220
228
|
diffable
|
|
221
229
|
|
|
222
230
|
match do |block|
|
|
223
|
-
@
|
|
231
|
+
if @approximately && current_adapter != 'postgresql'
|
|
232
|
+
@expected_value = a_value_within([2, @expected_value.abs * 0.05].max).of(@expected_value)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
@expected = { event_name: expected_event_name, payload: expected_payload, value: @expected_value }
|
|
224
236
|
@actuals = []
|
|
225
237
|
callback = ->(name, _started, _finished, _unique_id, payload) do
|
|
226
238
|
@actuals << { event_name: name, payload: payload.except(:value), value: payload[:value] }
|
|
@@ -249,10 +261,6 @@ RSpec::Matchers.define :emit_notification do |expected_event_name|
|
|
|
249
261
|
end
|
|
250
262
|
end
|
|
251
263
|
|
|
252
|
-
def current_adapter
|
|
253
|
-
ENV.fetch('ADAPTER', 'sqlite3')
|
|
254
|
-
end
|
|
255
|
-
|
|
256
264
|
def current_database
|
|
257
265
|
if current_adapter == 'sqlite3'
|
|
258
266
|
a_string_ending_with('tmp/database.sqlite')
|
|
@@ -279,6 +287,8 @@ QueryUnderTest = Struct.new(:sql, :connection) do
|
|
|
279
287
|
.gsub(/ (AND|OR) /) { "\n #{Regexp.last_match(1).strip} " }
|
|
280
288
|
# normalize and truncate 'AS' names/aliases (changes across Rails versions)
|
|
281
289
|
.gsub(/AS ("|`)?(\w+)("|`)?/) { "AS #{Regexp.last_match(2)[0...63]}" }
|
|
290
|
+
# remove quotes around column names in aggregate functions
|
|
291
|
+
.gsub(/(MIN|MAX|COUNT|SUM)\(("|`)(\w+)("|`)\)/) { "#{Regexp.last_match(1)}(#{Regexp.last_match(3)})" }
|
|
282
292
|
end
|
|
283
293
|
|
|
284
294
|
def explain
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: delayed
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan Griffith
|
|
@@ -19,7 +19,7 @@ authors:
|
|
|
19
19
|
autorequire:
|
|
20
20
|
bindir: bin
|
|
21
21
|
cert_chain: []
|
|
22
|
-
date: 2026-
|
|
22
|
+
date: 2026-02-05 00:00:00.000000000 Z
|
|
23
23
|
dependencies:
|
|
24
24
|
- !ruby/object:Gem::Dependency
|
|
25
25
|
name: activerecord
|