recurring_active_job 0.3.0 → 0.4.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: db5fcab0fb358e480791ac6e5edc3022a7eea74389a721aa01d6db3bf762839a
4
- data.tar.gz: c7bf5cb3943b2d18cd42a80820a1a65936b4b70dd8a017def66e63a5c5bba4bf
3
+ metadata.gz: 3fae517957eb8fac2b6eb06280371965354866c1d848fe72f728a6ced95bc69f
4
+ data.tar.gz: 6f72d60ec0196a6c0e98fc9b891f7461e4107afaf3a84139c2ed97f2f7a1a3f8
5
5
  SHA512:
6
- metadata.gz: fe5f736bec2bc1d283a3d8da25768afffb5cc6686096e3b6a28b92c4044393966851e13b01a2b8e18a1931ab036b7a26c204dad14360489c2781416276231f90
7
- data.tar.gz: 49ccafa5e1d73a3ce27f63975549baa1b7a7f3a44ae7ec37dfcc93510f5e72f4d07cbecc23d6c2bc172c941720380909d7eb4dfd3b58b750d673a464afc9d490
6
+ metadata.gz: 1799830197e836e0d2e6e734fe2a21cb4b785dbbee1f5e468d29503a9a9e3c8f71b5c9b6972f84ac2f2a32727530e1c267c0822f7a3272973864a834e0d4f64b
7
+ data.tar.gz: b33e9b50033f2d1be5a79cf4c75be5c3744b33d500558eb9d545f0653187111003a3e244d0c5191f1432d1d40b61a8b4071e3de436b116fa70f2e7ddffbaea95
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  #### Adapter agnostic ActiveJob scheduler based on time spent between executions.
4
4
 
5
5
  <!--- Version informartion -->
6
- *You are viewing the README of version [v0.3.0](https://github.com/thisismydesign/recurring_active_job/releases/tag/v0.3.0). You can find other releases [here](https://github.com/thisismydesign/recurring_active_job/releases).*
6
+ *You are viewing the README of version [v0.4.0](https://github.com/thisismydesign/recurring_active_job/releases/tag/v0.4.0). You can find other releases [here](https://github.com/thisismydesign/recurring_active_job/releases).*
7
7
  <!--- Version informartion end -->
8
8
 
9
9
  | Branch | Status |
@@ -107,13 +107,11 @@ Add a shared context to be included when testing Recurring jobs:
107
107
  `spec/support/shared_context_for_recurring_active_job.rb`
108
108
  ```ruby
109
109
  RSpec.shared_context "recurring active job" do
110
- let(:recurring_active_job) { build_stubbed(:recurring_active_job) }
110
+ let(:recurring_active_job) { create(:recurring_active_job) }
111
111
  let(:recurring_active_job_params) { { recurring_active_job_id: recurring_active_job.id } }
112
112
 
113
113
  before do
114
114
  allow(RecurringActiveJob::Model).to receive(:find).and_return(recurring_active_job)
115
- allow(recurring_active_job).to receive(:save!)
116
- allow(recurring_active_job).to receive(:destroy!)
117
115
  end
118
116
  end
119
117
  ```
@@ -127,6 +125,32 @@ RSpec.describe MyJob do
127
125
  end
128
126
  ```
129
127
 
128
+ ### Custom error handling
129
+
130
+ `RecurringActiveJob` defines the following generic error handling which is required for some features (but raises the original error at the end):
131
+
132
+ ```ruby
133
+ rescue_from(StandardError) do |e|
134
+ handle_exception(e)
135
+ end
136
+ ```
137
+
138
+ To define your own error handling but keep those features working you can redefine `handle_exception` like this:
139
+
140
+ ```ruby
141
+ rescue_from(StandardError) do |e|
142
+ handle_exception(e)
143
+ end
144
+
145
+ # ...
146
+
147
+ def handle_exception(e)
148
+ super rescue StandardError
149
+
150
+ # ...
151
+ end
152
+ ```
153
+
130
154
  ## Feedback
131
155
 
132
156
  Feedback is appreciated.
@@ -6,14 +6,8 @@ module RecurringActiveJob
6
6
  attr_accessor :logger
7
7
  end
8
8
 
9
- retry_on(StandardError, attempts: 0) do |job, e|
10
- recurring_active_job = RecurringActiveJob::Model.find(job.arguments.first&.dig(:recurring_active_job_id))
11
- if ActiveJob.gem_version < Gem::Version.new("5.2.0")
12
- recurring_active_job.update!(last_error: e, last_error_details: e)
13
- else
14
- recurring_active_job.update!(last_error: "#{e.class}: #{e.message}", last_error_details: ruby_style_error(e))
15
- end
16
- raise e
9
+ rescue_from(StandardError) do |e|
10
+ handle_exception(e)
17
11
  end
18
12
 
19
13
  before_enqueue do |job|
@@ -76,7 +70,17 @@ module RecurringActiveJob
76
70
  self.class.logger
77
71
  end
78
72
 
79
- def self.ruby_style_error(e)
73
+ def handle_exception(e)
74
+ recurring_active_job = RecurringActiveJob::Model.find(arguments.first&.dig(:recurring_active_job_id))
75
+ if ActiveJob.gem_version < Gem::Version.new("5.2.0")
76
+ recurring_active_job.update!(last_error: e, last_error_details: e)
77
+ else
78
+ recurring_active_job.update!(last_error: "#{e.class}: #{e.message}", last_error_details: ruby_style_error(e))
79
+ end
80
+ raise e
81
+ end
82
+
83
+ def ruby_style_error(e)
80
84
  e.backtrace.join("\n\t")
81
85
  .sub("\n\t", ": #{e}#{e.class ? " (#{e.class})" : ''}\n\t")
82
86
  end
@@ -1,3 +1,3 @@
1
1
  module RecurringActiveJob
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recurring_active_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thisismydesign
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-24 00:00:00.000000000 Z
11
+ date: 2018-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob