From a0852e2250b7a604dbc62c30c523e5074d9fe270 Mon Sep 17 00:00:00 2001 From: Paul Padier Date: Wed, 27 Oct 2021 13:45:22 +0900 Subject: [PATCH 1/6] RF-22752 Add releasing instructions to README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index b828ba3..65e13d6 100644 --- a/README.md +++ b/README.md @@ -169,3 +169,7 @@ require "queue_classic_plus/datadog" ``` createdb queue_classic_plus_test ``` + +## Releasing + +Releasing is done in CircleCI via the `push_to_rubygems`, triggered by pushing a tagged commit. To do so, simply [create a new GitHub release](https://github.com/rainforestapp/queue_classic_plus/releases/new). From b162fe9328b92fb278233db4ab3733ec6dce3a8b Mon Sep 17 00:00:00 2001 From: Paul Padier Date: Wed, 27 Oct 2021 13:57:06 +0900 Subject: [PATCH 2/6] RF-22752 Fix indentation Also remove needless existence check. Both `nil` and `false` respond to `:responds_to?`, but neither respond to `:retries_on?`. --- lib/queue_classic_plus/worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/queue_classic_plus/worker.rb b/lib/queue_classic_plus/worker.rb index ee7932d..7bc2e4c 100644 --- a/lib/queue_classic_plus/worker.rb +++ b/lib/queue_classic_plus/worker.rb @@ -31,7 +31,7 @@ def handle_failure(job, e) Metrics.increment("qc.force_retry", source: @q_name) retry_with_remaining(e) # The mailers doesn't have a retries_on? - elsif failed_job_class && failed_job_class.respond_to?(:retries_on?) && failed_job_class.retries_on?(e) + elsif failed_job_class.respond_to?(:retries_on?) && failed_job_class.retries_on?(e) Metrics.increment("qc.retry", source: @q_name) retry_with_remaining(e) else From de4ea97bf11fd471b52a3243a389fe5ba9ce8936 Mon Sep 17 00:00:00 2001 From: Paul Padier Date: Wed, 27 Oct 2021 14:05:42 +0900 Subject: [PATCH 3/6] RF-22752 DRY up Rails contexts --- spec/base_spec.rb | 6 +----- spec/spec_helper.rb | 7 +++++++ spec/worker_spec.rb | 7 +------ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/spec/base_spec.rb b/spec/base_spec.rb index d09c387..d1218c0 100644 --- a/spec/base_spec.rb +++ b/spec/base_spec.rb @@ -160,11 +160,7 @@ def self.perform end end - context "with Rails defined" do - require 'active_job/arguments' - - before { stub_const('Rails', true) } - + context "with Rails defined", rails: true do subject do Class.new(QueueClassicPlus::Base) do @queue = :test diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 22e4311..b543529 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,4 +26,11 @@ # Reset the default (memoized) queue instance between specs QC.default_queue = nil end + + config.before(:each, rails: true) do + require 'active_job' + require 'active_job/arguments' + + stub_const('Rails', Struct.new(:logger).new(Logger.new(STDOUT))) + end end diff --git a/spec/worker_spec.rb b/spec/worker_spec.rb index c2de119..0405622 100644 --- a/spec/worker_spec.rb +++ b/spec/worker_spec.rb @@ -67,12 +67,7 @@ end end - context 'when Rails is defined' do - require 'active_job' - require 'active_job/arguments' - - before { stub_const('Rails', Struct.new(:logger).new(Logger.new(STDOUT))) } - + context 'when Rails is defined', rails: true do it 'retries' do expect do job_type.enqueue_perform(:foo) From fc80644f5c916783ce1b88de2be71ad06859c5d7 Mon Sep 17 00:00:00 2001 From: Paul Padier Date: Wed, 27 Oct 2021 14:28:45 +0900 Subject: [PATCH 4/6] RF-22752 Fix argument serializing when enqueuing failed job --- lib/queue_classic_plus/worker.rb | 6 ++++-- spec/worker_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/queue_classic_plus/worker.rb b/lib/queue_classic_plus/worker.rb index 7bc2e4c..f46e859 100644 --- a/lib/queue_classic_plus/worker.rb +++ b/lib/queue_classic_plus/worker.rb @@ -25,7 +25,8 @@ def handle_failure(job, e) end @failed_job = job - @failed_job_args = failed_job_class ? failed_job_class.deserialized(job[:args]) : job[:args] + @raw_args = job[:args] + @failed_job_args = failed_job_class ? failed_job_class.deserialized(@raw_args) : @raw_args if force_retry && !(failed_job_class.respond_to?(:disable_retries) && failed_job_class.disable_retries) Metrics.increment("qc.force_retry", source: @q_name) @@ -80,7 +81,8 @@ def connection_error?(e) def enqueue_failed(e) sql = "INSERT INTO #{QC.table_name} (q_name, method, args, last_error) VALUES ('failed_jobs', $1, $2, $3)" last_error = e.backtrace ? ([e.message] + e.backtrace ).join("\n") : e.message - QC.default_conn_adapter.execute sql, @failed_job[:method], JSON.dump(@failed_job_args), last_error + + QC.default_conn_adapter.execute sql, @failed_job[:method], JSON.dump(@raw_args), last_error QueueClassicPlus.exception_handler.call(e, @failed_job) Metrics.increment("qc.errors", source: @q_name) diff --git a/spec/worker_spec.rb b/spec/worker_spec.rb index 0405622..7cd92b2 100644 --- a/spec/worker_spec.rb +++ b/spec/worker_spec.rb @@ -26,6 +26,26 @@ worker.work expect(failed_queue.count).to eq(1) end + + context 'when Rails is defined', rails: true do + let(:job_type) { Jobs::Tests::TestJobNoRetry } + let(:queue) { job_type.queue } + + it 'properly serializes arguments for jobs in the failed queue' do + job_type.enqueue_perform(:raise) + expect(failed_queue.count).to eq(0) + worker.work + + expect(failed_queue.count).to eq(1) + job = QueueClassicMatchers::QueueClassicRspec.find_by_args( + 'failed_jobs', + 'Jobs::Tests::TestJobNoRetry._perform', + [:raise]).first + + expect(job).to_not be_nil + expect(job['last_error']).to_not be_nil + end + end end context "retry" do From bedfd2ecd18df349a2e642ee2779775e87d31f84 Mon Sep 17 00:00:00 2001 From: Paul Padier Date: Wed, 27 Oct 2021 14:29:05 +0900 Subject: [PATCH 5/6] RF-22752 Remove superfluous begin keyword --- lib/queue_classic_plus/worker.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/queue_classic_plus/worker.rb b/lib/queue_classic_plus/worker.rb index f46e859..bcd6cce 100644 --- a/lib/queue_classic_plus/worker.rb +++ b/lib/queue_classic_plus/worker.rb @@ -61,11 +61,9 @@ def remaining_retries end def failed_job_class - begin - Object.const_get(@failed_job[:method].split('.')[0]) - rescue NameError - nil - end + Object.const_get(@failed_job[:method].split('.')[0]) + rescue NameError + nil end def backoff From 8c16035afdfceefddafa03711acaf7bca0a6a975 Mon Sep 17 00:00:00 2001 From: Paul Padier Date: Wed, 27 Oct 2021 14:29:43 +0900 Subject: [PATCH 6/6] RF-22752 RF-22643 Bump version to 4.0.0.alpha9 --- lib/queue_classic_plus/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/queue_classic_plus/version.rb b/lib/queue_classic_plus/version.rb index 86edb5c..e43c6dd 100644 --- a/lib/queue_classic_plus/version.rb +++ b/lib/queue_classic_plus/version.rb @@ -1,3 +1,3 @@ module QueueClassicPlus - VERSION = '4.0.0.alpha8'.freeze + VERSION = '4.0.0.alpha9'.freeze end