inst-jobs 3.0.13 → 3.1.0

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
  SHA256:
3
- metadata.gz: c1369efb0e72de3f01f922b7f77a95a6c5dd1979aaec11cfd76cdc4507202428
4
- data.tar.gz: 244a543711c3ceab301f4ea0f30bb238e47330921059ec27133a7a2de44389f7
3
+ metadata.gz: 37ca25ff97580c47a56d0d40a1ab2f78c62a2f47629d0c2e5ba6c8e5c4ace0bd
4
+ data.tar.gz: 16d4a060bfc0c23f84360d305e35adb5482d0d96f50b50c1a45a8a0b02739c90
5
5
  SHA512:
6
- metadata.gz: '09ce7c560febe39082502641d62e9309f515d026eb95d840e3645fbb2725d9eb6c70f2b147402a44d462bc5761c8f4727739e87a7f4a6acbed391868ae024d2e'
7
- data.tar.gz: d0332dc2e652adf67b93f61122d535a7e48f20d48e9d66a08d2e5fc75d08c4be1c7e15b4656c7f1bfc4102a389bd23d256b4d43cb88b914e98ce9a0ea67ddd3c
6
+ metadata.gz: 7f981418c6f0493c84114777193674559f8a0a15006547600bc00cc44eaaff08232c7695f801a3b84c2919167c68c7fb7d91562aa1d4d47d9f98d28a1362b0e3
7
+ data.tar.gz: 4b31d64c30f9208c54b32796d6ad99f22f9beb3f405a8b4585398306d03b15063d3fde88fce2d063f4f76949da1e350bf4607b8bcf6709a4a20ff686f5c87b6d
@@ -86,8 +86,12 @@ module Delayed
86
86
  kwargs.merge!(n_strand_options(full_strand_name, num_strands))
87
87
  end
88
88
 
89
+ job = nil
90
+
89
91
  if singleton
90
- job = create(**kwargs)
92
+ Delayed::Worker.lifecycle.run_callbacks(:create, kwargs) do
93
+ job = create(**kwargs)
94
+ end
91
95
  elsif batches && strand.nil? && run_at.nil?
92
96
  batch_enqueue_args = kwargs.slice(*self.batch_enqueue_args)
93
97
  batches[batch_enqueue_args] << kwargs
@@ -95,7 +99,9 @@ module Delayed
95
99
  else
96
100
  raise ArgumentError, "on_conflict can only be provided with singleton" if kwargs[:on_conflict]
97
101
 
98
- job = create(**kwargs)
102
+ Delayed::Worker.lifecycle.run_callbacks(:create, kwargs) do
103
+ job = create(**kwargs)
104
+ end
99
105
  end
100
106
 
101
107
  JobTracking.job_created(job)
@@ -5,6 +5,7 @@ module Delayed
5
5
 
6
6
  class Lifecycle
7
7
  EVENTS = {
8
+ create: [:args],
8
9
  error: %i[worker job exception],
9
10
  exceptional_exit: %i[worker exception],
10
11
  execute: [:worker],
@@ -16,7 +16,7 @@ module Delayed
16
16
  # Rails will take care of establishing the DB connection for us if there is
17
17
  # an application present
18
18
  if using_active_record? && !ActiveRecord::Base.connected?
19
- ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"])
19
+ ActiveRecord::Base.establish_connection(ENV.fetch("DATABASE_URL", nil))
20
20
  end
21
21
 
22
22
  @allow_update = args.length.positive? && args[0][:update]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Delayed
4
- VERSION = "3.0.13"
4
+ VERSION = "3.1.0"
5
5
  end
@@ -276,7 +276,7 @@ module Delayed
276
276
  # set up the session context information, so that it gets logged with the job log lines
277
277
  # also set up a unique tmpdir, which will get removed at the end of the job.
278
278
  def configure_for_job(job)
279
- previous_tmpdir = ENV["TMPDIR"]
279
+ previous_tmpdir = ENV.fetch("TMPDIR", nil)
280
280
 
281
281
  self.class.running_job(job) do
282
282
  dir = Dir.mktmpdir("job-#{job.id}-#{name.gsub(/[^\w.]/, '.')}-")
@@ -35,6 +35,22 @@ shared_examples_for "a backend" do
35
35
  expect(Delayed::Job.jobs_count(:current)).to eq(1)
36
36
  end
37
37
 
38
+ it "triggers the lifecycle event around the create" do
39
+ called = false
40
+ called_args = nil
41
+
42
+ Delayed::Worker.lifecycle.after(:create) do |args|
43
+ called = true
44
+ called_args = args
45
+ end
46
+
47
+ job = SimpleJob.new
48
+ Delayed::Job.enqueue(job)
49
+
50
+ expect(called).to be_truthy
51
+ expect(called_args[:payload_object]).to eq job
52
+ end
53
+
38
54
  it "is able to set priority when enqueuing items" do
39
55
  @job = Delayed::Job.enqueue SimpleJob.new, priority: 5
40
56
  expect(@job.priority).to eq(5)
data/spec/spec_helper.rb CHANGED
@@ -47,14 +47,14 @@ RSpec::Core::ExampleGroup.include(NoYamlDump)
47
47
 
48
48
  ENV["TEST_ENV_NUMBER"] ||= "1"
49
49
  ENV["TEST_DB_HOST"] ||= "localhost"
50
- ENV["TEST_DB_DATABASE"] ||= "inst-jobs-test-#{ENV['TEST_ENV_NUMBER']}"
50
+ ENV["TEST_DB_DATABASE"] ||= "inst-jobs-test-#{ENV.fetch('TEST_ENV_NUMBER', nil)}"
51
51
 
52
52
  connection_config = {
53
53
  adapter: :postgresql,
54
54
  host: ENV["TEST_DB_HOST"].presence,
55
55
  encoding: "utf8",
56
- username: ENV["TEST_DB_USERNAME"],
57
- database: ENV["TEST_DB_DATABASE"],
56
+ username: ENV.fetch("TEST_DB_USERNAME", nil),
57
+ database: ENV.fetch("TEST_DB_DATABASE", nil),
58
58
  min_messages: "notice",
59
59
  # Ensure the pool is big enough the deadlock tests don't get starved for connections by rails instead
60
60
  pool: 20
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inst-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.13
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2022-04-05 00:00:00.000000000 Z
13
+ date: 2022-05-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord