inst-jobs 3.1.1 → 3.1.2

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: 0ea5fb9db3338718560d2107fd348ca95077e2b1f98490d33a8f61ecf686d7dd
4
- data.tar.gz: 17ae33dac196625a7d194c51b609f1c7e98b6ce8917898b2a03b283b9784c96c
3
+ metadata.gz: 95bdbd537405c6325f378bed05570a3149053ba8a2e290893010c590df72ea9a
4
+ data.tar.gz: 6f0d577f1fba37bb01e3e0a4ec05b600e65ebb77d001e29e38b479f6facde73b
5
5
  SHA512:
6
- metadata.gz: 20ad04cef57908281160729d47e4e9ae0a86b2c75c7200cdb0467c23b69dd32d634b1f6c886cda42209d1a2f794acf2461f0b69f82f4fe8571a999c93b35f277
7
- data.tar.gz: 874f268caddfa09f160dd3eb05fa7d9be3d04fb667e23da32d6cce5901d6e45321e203db83830ad4d40986119656453b9e63f3da65f654f302150a4c95286fb6
6
+ metadata.gz: 38392cab25180d44f40960ffb15b2dd3241bd739980b9d0962b93020a809497bb1a9022caf7a05f4ba40f4cc3792281f03468946c33a1fc62891dec3b411f7cf
7
+ data.tar.gz: cbea2ab6e762a876994179ac1c9ffd414ea2ec13905931b2cddb087d816664e8b682ecf8f9406726d8f80a0867b8e44bc1331b6e0e73de3415b4ab31090d1ee9
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddRequeuedJobIdToFailedJobs < ActiveRecord::Migration[6.0]
4
+ def change
5
+ add_column :failed_jobs, :requeued_job_id, :integer, limit: 8
6
+ end
7
+ end
@@ -583,6 +583,21 @@ module Delayed
583
583
  def self.cleanup_old_jobs(before_date, batch_size: 10_000)
584
584
  where("failed_at < ?", before_date).in_batches(of: batch_size).delete_all
585
585
  end
586
+
587
+ def requeue!
588
+ attrs = attributes.except("id", "last_error", "locked_at", "failed_at", "locked_by", "original_job_id",
589
+ "requeued_job_id")
590
+ self.class.transaction do
591
+ job = nil
592
+ Delayed::Worker.lifecycle.run_callbacks(:create, attrs.merge("payload_object" => payload_object)) do
593
+ job = Job.create(attrs)
594
+ end
595
+ self.requeued_job_id = job.id
596
+ save!
597
+ JobTracking.job_created(job)
598
+ job
599
+ end
600
+ end
586
601
  end
587
602
  end
588
603
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Delayed
4
- VERSION = "3.1.1"
4
+ VERSION = "3.1.2"
5
5
  end
@@ -300,4 +300,27 @@ describe "Delayed::Backed::ActiveRecord::Job" do
300
300
  allow(Delayed::Job.connection).to receive(:execute).and_call_original
301
301
  end
302
302
  end
303
+
304
+ context "Failed#requeue!" do
305
+ it "requeues a failed job" do
306
+ j = create_job(attempts: 1, max_attempts: 1)
307
+ fj = j.fail!
308
+
309
+ lifecycle_args = nil
310
+ Delayed::Worker.lifecycle.after(:create) do |args|
311
+ lifecycle_args = args
312
+ end
313
+ j2 = fj.requeue!
314
+ expect(lifecycle_args["payload_object"].class).to eq SimpleJob
315
+ expect(fj.reload.requeued_job_id).to eq j2.id
316
+
317
+ orig_atts = j.attributes.except("id", "locked_at", "locked_by")
318
+ new_atts = j2.attributes.except("id", "locked_at", "locked_by")
319
+ expect(orig_atts).to eq(new_atts)
320
+
321
+ # ensure the requeued job actually runs even though `attempts` are maxed out
322
+ # (so it will not be retried after being manually requeued)
323
+ expect { run_job(j2) }.to change(SimpleJob, :runs).by(1)
324
+ end
325
+ end
303
326
  end
@@ -82,7 +82,7 @@ shared_examples_for "a backend" do
82
82
  it "works with jobs in modules" do
83
83
  M::ModuleJob.runs = 0
84
84
  job = Delayed::Job.enqueue M::ModuleJob.new
85
- expect { job.invoke_job }.to change { M::ModuleJob.runs }.from(0).to(1)
85
+ expect { job.invoke_job }.to change(M::ModuleJob, :runs).from(0).to(1)
86
86
  end
87
87
 
88
88
  it "raises an DeserializationError when the job class is totally unknown" do
@@ -347,7 +347,7 @@ shared_examples_for "Delayed::Worker" do
347
347
 
348
348
  it "does not run expired jobs" do
349
349
  Delayed::Job.enqueue SimpleJob.new, expires_at: Delayed::Job.db_time_now - 1.day
350
- expect { @worker.run }.to change(SimpleJob, :runs).by(0)
350
+ expect { @worker.run }.not_to change(SimpleJob, :runs)
351
351
  end
352
352
 
353
353
  it "reports a permanent failure when an expired job is dequeued" do
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.1.1
4
+ version: 3.1.2
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-05-12 00:00:00.000000000 Z
13
+ date: 2022-05-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -460,6 +460,7 @@ files:
460
460
  - db/migrate/20220128084900_update_delete_trigger_for_singleton_unique_constraint_change.rb
461
461
  - db/migrate/20220203063200_remove_old_singleton_index.rb
462
462
  - db/migrate/20220328152900_add_failed_jobs_indicies.rb
463
+ - db/migrate/20220519204546_add_requeued_job_id_to_failed_jobs.rb
463
464
  - exe/inst_jobs
464
465
  - lib/delayed/backend/active_record.rb
465
466
  - lib/delayed/backend/base.rb