sidekiq-amigo 1.7.0 → 1.8.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/amigo/retry.rb +29 -5
- data/lib/amigo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a32299bc84d87b6c497414b4fcb6b89278e2993543eff1ba07bcf1a9fb75c59f
|
4
|
+
data.tar.gz: 27acf41f1e0235536da93d7dfd0b2a5ad1f65e4e993f428967e8072e7213f83f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47e75ba71d67411a80e7d5ae20f06c0b3bb4e0fb056356e63fb47ec3cd84cdb72f0deb6e2bd00f5cc0cd091267dc30725e4607ae018b7f29a31093c4c9e82ebd
|
7
|
+
data.tar.gz: 761f7febdba270fe365f39cb740f734615118bd8c160485ac9296119f00124458f1970e159dbdd0ed8a6fbecd4c66df8bfe07f86803a14e2982e738fbe69115c
|
data/lib/amigo/retry.rb
CHANGED
@@ -17,18 +17,29 @@ require "sidekiq/api"
|
|
17
17
|
# end
|
18
18
|
module Amigo
|
19
19
|
module Retry
|
20
|
-
class Error < StandardError
|
20
|
+
class Error < StandardError
|
21
|
+
protected def exc_or_msg(timing_msg, obj)
|
22
|
+
return timing_msg if obj.nil?
|
23
|
+
return obj.to_s unless obj.is_a?(Exception)
|
24
|
+
return "#{timing_msg} (#{obj.class}: #{obj.message})"
|
25
|
+
end
|
26
|
+
|
27
|
+
protected def exc?(ex)
|
28
|
+
return ex.is_a?(Exception) ? ex : nil
|
29
|
+
end
|
30
|
+
end
|
21
31
|
|
22
32
|
# Raise this class, or a subclass of it, to schedule a later retry,
|
23
33
|
# rather than using an error to trigger Sidekiq's default retry behavior.
|
24
34
|
# The benefit here is that it allows a consistent, customizable behavior,
|
25
35
|
# so is better for 'expected' errors like rate limiting.
|
26
36
|
class Retry < Error
|
27
|
-
attr_accessor :interval_or_timestamp
|
37
|
+
attr_accessor :interval_or_timestamp, :wrapped
|
28
38
|
|
29
39
|
def initialize(interval_or_timestamp, msg=nil)
|
30
40
|
@interval_or_timestamp = interval_or_timestamp
|
31
|
-
|
41
|
+
@wrapped = exc?(msg)
|
42
|
+
super(exc_or_msg("retry job in #{interval_or_timestamp.to_i}s", msg))
|
32
43
|
end
|
33
44
|
end
|
34
45
|
|
@@ -37,18 +48,25 @@ module Amigo
|
|
37
48
|
# This allows jobs to hard-fail when there is something like a total outage,
|
38
49
|
# rather than retrying.
|
39
50
|
class Die < Error
|
51
|
+
attr_accessor :wrapped
|
52
|
+
|
53
|
+
def initialize(msg=nil)
|
54
|
+
@wrapped = exc?(msg)
|
55
|
+
super(exc_or_msg("kill job", msg))
|
56
|
+
end
|
40
57
|
end
|
41
58
|
|
42
59
|
# Raise this class, or a subclass of it, to:
|
43
60
|
# - Use +Retry+ exception semantics while the current attempt is <= +attempts+, or
|
44
61
|
# - Use +Die+ exception semantics if the current attempt is > +attempts+.
|
45
62
|
class OrDie < Error
|
46
|
-
attr_reader :attempts, :interval_or_timestamp
|
63
|
+
attr_reader :attempts, :interval_or_timestamp, :wrapped
|
47
64
|
|
48
65
|
def initialize(attempts, interval_or_timestamp, msg=nil)
|
66
|
+
@wrapped = exc?(msg)
|
49
67
|
@attempts = attempts
|
50
68
|
@interval_or_timestamp = interval_or_timestamp
|
51
|
-
super(
|
69
|
+
super(exc_or_msg("retry every #{interval_or_timestamp.to_i}s up to #{attempts} times", msg))
|
52
70
|
end
|
53
71
|
end
|
54
72
|
|
@@ -56,6 +74,12 @@ module Amigo
|
|
56
74
|
# from deep in a job and they want to jump out of the whole thing.
|
57
75
|
# Usually you should log before raising this!
|
58
76
|
class Quit < Error
|
77
|
+
attr_accessor :wrapped
|
78
|
+
|
79
|
+
def initialize(msg=nil)
|
80
|
+
@wrapped = exc?(msg)
|
81
|
+
super(exc_or_msg("quit job", msg))
|
82
|
+
end
|
59
83
|
end
|
60
84
|
|
61
85
|
class ServerMiddleware
|
data/lib/amigo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-amigo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lithic Technology
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|