lambdakiq 2.0.2 → 2.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc719ae59b3ba58dca3f268f2be9c3fc96f56c2c40eabee791da33da33b50534
4
- data.tar.gz: 873a8d6563b4e17dcf52534b2776e166aeb0a18cd4992d3d91139bc60f77a4d9
3
+ metadata.gz: 84d147fdbb851da5e7e6ebace4cd2eb5a00ae53d3bd0d36981d9cb90c93bac5b
4
+ data.tar.gz: 534d3f92cde56e7462202ebfd0b828039974d37792ee19d4c30b64ea0e901d61
5
5
  SHA512:
6
- metadata.gz: b830f98d593b7fd995b946889669b8b7c6bf9c450df752abf6b6d17b4bf674ab393000691c5a92f089a07c73bddf99f6375aac4933a046cafefa55bf01bb2586
7
- data.tar.gz: 2cbbd15df392bfc7b3837e22afafd177aaa9db739a0883ac7090772ec028ef05e8c621f575232f9bffe7151dda2789a748096bcadfd6cc8e526b6e30cc712d2a
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lambdakiq (2.0.2)
4
+ lambdakiq (2.2.0)
5
5
  activejob
6
6
  aws-sdk-sqs
7
7
  concurrent-ruby
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) which means the same `app.rb` handler would be used. The [Lamby](https://lamby.custominktech.com) gem automatically detects if Lambdakiq is being used so the following handler works as is.
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
- delete_message
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
- config_retry = [Lambdakiq.config.max_retries, 12].min
102
- [ (active_job.lambdakiq_retry || config_retry),
103
- (queue.max_receive_count - 1) ].min
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?
@@ -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['maxReceiveCount'].to_i
29
+ redrive_policy&.dig('maxReceiveCount')&.to_i || 1
30
30
  end
31
31
 
32
32
  def fifo?
@@ -1,3 +1,3 @@
1
1
  module Lambdakiq
2
- VERSION = '2.0.2'
2
+ VERSION = '2.2.0'
3
3
  end
data/lib/lambdakiq.rb CHANGED
@@ -20,6 +20,10 @@ require 'lambdakiq/railtie'
20
20
 
21
21
  module Lambdakiq
22
22
 
23
+ def cmd(event:, context:)
24
+ handler(event)
25
+ end
26
+
23
27
  def handler(event)
24
28
  Job.handler(event)
25
29
  end
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.2
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-08-02 00:00:00.000000000 Z
11
+ date: 2022-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob