lambdakiq 2.0.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -15
- data/lib/lambdakiq/job.rb +14 -4
- data/lib/lambdakiq/queue.rb +2 -2
- data/lib/lambdakiq/version.rb +1 -1
- data/lib/lambdakiq.rb +4 -0
- 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: 84d147fdbb851da5e7e6ebace4cd2eb5a00ae53d3bd0d36981d9cb90c93bac5b
|
4
|
+
data.tar.gz: 534d3f92cde56e7462202ebfd0b828039974d37792ee19d4c30b64ea0e901d61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cff69c86fae5f46a63cfbd7ee6290fb8aa472a6dc1377424df1cf8daf17ca96c373a87577c4f50ebaf081d8c9b13421e032f8b71b314cbd4135ec2ca7ca7dfe
|
7
|
+
data.tar.gz: bed7c2407983c15b2ed48ba63362afe7b7a305c7415ec0deb533e25928ea805b8b5c8ad91bbeee4b51a7d3b69008e4854910b9093f392f454fdb78c8e8550db6
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
See this http://keepachangelog.com link for information on how we want this documented formatted.
|
4
4
|
|
5
|
+
## v2.2.0
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- Simple `Lambdakiq.cmd` to be used with `ImageConfig.Command`.
|
10
|
+
|
11
|
+
## v2.1.0
|
12
|
+
|
13
|
+
#### Fixed
|
14
|
+
|
15
|
+
- Ensure failed messages go to DLQ. Fixes #30. Fixes #31. Thanks @thenano
|
16
|
+
|
5
17
|
## v2.0.2
|
6
18
|
|
7
19
|
#### Fixed
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -56,21 +56,7 @@ ActionMailer::MailDeliveryJob.include Lambdakiq::Worker
|
|
56
56
|
ActionMailer::MailDeliveryJob.queue_as ENV['JOBS_QUEUE_NAME']
|
57
57
|
```
|
58
58
|
|
59
|
-
The same Docker image will be used for both your `web` and `jobs` functions (example setup in following sections)
|
60
|
-
|
61
|
-
```ruby
|
62
|
-
def handler(event:, context:)
|
63
|
-
Lamby.handler $app, event, context
|
64
|
-
end
|
65
|
-
```
|
66
|
-
|
67
|
-
You can use the Lambdakiq handler directly in cases where your handler is a different method. Likewise there is a `Lambdakiq.jobs?(event)` helper function which returns true if the `messageAttributes` has a `lambdakiq` attribute.
|
68
|
-
|
69
|
-
```ruby
|
70
|
-
def jobs_handler(event:, context:)
|
71
|
-
Lambdakiq.handler(event)
|
72
|
-
end
|
73
|
-
```
|
59
|
+
The same Docker image will be used for both your `web` and `jobs` functions (example setup in following sections). The [Lamby](https://lamby.custominktech.com) gem can automatically can detect if Lambdakiq is present when using the newer `Lamby.cmd` or older lower `Lamby.handler` method. That said, please take a look at the `JobsLambda` in the following section and how `ImageConfig` is used as the golden path for sharing containers.
|
74
60
|
|
75
61
|
### SQS Resources
|
76
62
|
|
@@ -146,6 +132,8 @@ JobsLambda:
|
|
146
132
|
BatchSize: 1
|
147
133
|
FunctionResponseTypes:
|
148
134
|
- ReportBatchItemFailures
|
135
|
+
ImageConfig:
|
136
|
+
Command: ["config/environment.Lambdakiq.cmd"]
|
149
137
|
MemorySize: 1792
|
150
138
|
PackageType: Image
|
151
139
|
Policies:
|
@@ -161,6 +149,7 @@ JobsLambda:
|
|
161
149
|
|
162
150
|
Here are some key aspects of our `JobsLambda` resource above:
|
163
151
|
|
152
|
+
- We use the `ImageConfig.Command` to load your Rails env and invoke the `Lambdakiq.cmd` which calls the `Lambdakiq.handler` on your behalf.
|
164
153
|
- The `Events` property uses the [SQS Type](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-sqs.html).
|
165
154
|
- The [BatchSize](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-sqs.html#sam-function-sqs-batchsize) can be any number you like. Less means more Lambda concurrency, more means some jobs could take longer. The jobs function `Timeout` must be lower than the `JobsQueue`'s `VisibilityTimeout` property. When the batch size is one, the queue's visibility is generally one second more.
|
166
155
|
- You must use `ReportBatchItemFailures` response types. Lambdakiq assumes we are [reporting batch item failures](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting). This is a new feature of SQS introduced in [November 2021](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting).
|
data/lib/lambdakiq/job.rb
CHANGED
@@ -72,7 +72,11 @@ module Lambdakiq
|
|
72
72
|
@error = e
|
73
73
|
else
|
74
74
|
instrument :retry_stopped, error: e
|
75
|
-
|
75
|
+
if should_redrive?
|
76
|
+
@error = e
|
77
|
+
else
|
78
|
+
delete_message
|
79
|
+
end
|
76
80
|
end
|
77
81
|
end
|
78
82
|
|
@@ -97,10 +101,16 @@ module Lambdakiq
|
|
97
101
|
executions > retry_limit
|
98
102
|
end
|
99
103
|
|
104
|
+
def job_retry
|
105
|
+
[active_job.lambdakiq_retry, Lambdakiq.config.max_retries, 12].compact.min
|
106
|
+
end
|
107
|
+
|
100
108
|
def retry_limit
|
101
|
-
|
102
|
-
|
103
|
-
|
109
|
+
[job_retry, (queue.max_receive_count - 1)].min
|
110
|
+
end
|
111
|
+
|
112
|
+
def should_redrive?
|
113
|
+
!queue.redrive_policy.nil? && job_retry >= queue.max_receive_count
|
104
114
|
end
|
105
115
|
|
106
116
|
def fifo_delay?
|
data/lib/lambdakiq/queue.rb
CHANGED
@@ -22,11 +22,11 @@ module Lambdakiq
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def redrive_policy
|
25
|
-
@redrive_policy ||= JSON.parse(attributes['RedrivePolicy'])
|
25
|
+
@redrive_policy ||= attributes['RedrivePolicy'] ? JSON.parse(attributes['RedrivePolicy']) : nil
|
26
26
|
end
|
27
27
|
|
28
28
|
def max_receive_count
|
29
|
-
redrive_policy
|
29
|
+
redrive_policy&.dig('maxReceiveCount')&.to_i || 1
|
30
30
|
end
|
31
31
|
|
32
32
|
def fifo?
|
data/lib/lambdakiq/version.rb
CHANGED
data/lib/lambdakiq.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lambdakiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Collins
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|