lambdakiq 1.0.3 → 2.0.1

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: 3f6c1f6c45eb8d1a8a5188e4e70e63ed36b05bbf334a807cef72c523d6661b55
4
- data.tar.gz: 4a9683cd82caadeedbbba483686c9584a0c0591bf85e63198202b4af0b414bf7
3
+ metadata.gz: 907b219d7a132815c0f656a7e69296aba6556b15d1c8f031afcdebebca42bb96
4
+ data.tar.gz: cd7480cb9e54c0037674d7335a669d443954f8812686beeee7dcaa9e17efb43e
5
5
  SHA512:
6
- metadata.gz: 812d898f39463401a4dc348213b75b40d1892618a575f58791edfd7d168304ead00bf562831d414533304ccb83e00e826e0a8c43653c19432c9a190100e1ca15
7
- data.tar.gz: 144f18512e4db39eae43f6299fa81e48750e0438540ccd03a3e831a5efd914639cc20fec86ebb820ec5aeff1c6cb4ce5a4a2396b34d495f1f3788b486d55aa48
6
+ metadata.gz: 33766b628c71b3c6803b9884cf44a1ec18655b04d1bccd3a8641c37bde5c29b8464b47822b6e10be6d67739e71abd53d9891c5cefbefd53988418eed39b66be6
7
+ data.tar.gz: e69cc722782cfb724c8265dce20c2c57db42cecf54747620dae54ee3856d203dbd51ccc13a27d52705f9dfc52e134501f6192be69ce6bb26c508332966f4110a
data/CHANGELOG.md CHANGED
@@ -2,11 +2,23 @@
2
2
 
3
3
  See this http://keepachangelog.com link for information on how we want this documented formatted.
4
4
 
5
- ## v1.0.2, v1.0.3
5
+ ## v2.0.1
6
6
 
7
7
  #### Fixed
8
8
 
9
- - Ensure `active_job` events are safe for non-Lambdakiq jobs.
9
+ - Rails 5.1 oddities for class attribute default not set.
10
+
11
+ ## v2.0.0
12
+
13
+ #### Changed
14
+
15
+ - Leverage new `ReportBatchItemFailures` feature of SQS.
16
+
17
+ ## v1.0.2, v1.0.3, v1.0.4
18
+
19
+ #### Fixed
20
+
21
+ - Rails v5.2 compatibility. Metrics logging is are safe for non-Lambdakiq jobs
10
22
 
11
23
  ## v1.0.0
12
24
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lambdakiq (1.0.3)
4
+ lambdakiq (2.0.1)
5
5
  activejob
6
6
  aws-sdk-sqs
7
7
  concurrent-ruby
data/README.md CHANGED
@@ -30,7 +30,7 @@ Add the Lambdakiq gem to your `Gemfile`.
30
30
  gem 'lambdakiq'
31
31
  ```
32
32
 
33
- Open `config/initializers/production.rb` and set Lambdakiq as your ActiveJob queue adapter.
33
+ Open `config/environments/production.rb` and set Lambdakiq as your ActiveJob queue adapter.
34
34
 
35
35
  ```ruby
36
36
  config.active_job.queue_adapter = :lambdakiq
@@ -45,6 +45,17 @@ class ApplicationJob < ActiveJob::Base
45
45
  end
46
46
  ```
47
47
 
48
+ Using ActionMailer's built-in deliver job with ActiveJob? Make sure to include the Lambdakiq worker and set the queue name depending on your Rails version. You can do this in a newly created `config/initializers//action_mailer.rb` or another initializer of your choice.
49
+
50
+ ```ruby
51
+ # Rails 5.x
52
+ ActionMailer::DeliveryJob.include Lambdakiq::Worker
53
+ ActionMailer::DeliveryJob.queue_as ENV['JOBS_QUEUE_NAME']
54
+ # Rails 6.x
55
+ ActionMailer::MailDeliveryJob.include Lambdakiq::Worker
56
+ ActionMailer::MailDeliveryJob.queue_as ENV['JOBS_QUEUE_NAME']
57
+ ```
58
+
48
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.
49
60
 
50
61
  ```ruby
@@ -133,6 +144,8 @@ JobsLambda:
133
144
  Properties:
134
145
  Queue: !GetAtt JobsQueue.Arn
135
146
  BatchSize: 1
147
+ FunctionResponseTypes:
148
+ - ReportBatchItemFailures
136
149
  MemorySize: 1792
137
150
  PackageType: Image
138
151
  Policies:
@@ -149,9 +162,9 @@ JobsLambda:
149
162
  Here are some key aspects of our `JobsLambda` resource above:
150
163
 
151
164
  - The `Events` property uses the [SQS Type](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-sqs.html).
152
- - Our [BatchSize](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-sqs.html#sam-function-sqs-batchsize) is set to one so we can handle retrys more easily without worrying about idempotency in larger batches.
165
+ - 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
+ - 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).
153
167
  - The `Metadata`'s Docker properties must be the same as our web function except for the `DockerTag`. This is needed for the image to be shared. This works around a known [SAM issue](https://github.com/aws/aws-sam-cli/issues/2466) vs using the `ImageConfig` property.
154
- - 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.
155
168
 
156
169
  🎉 Deploy your application and have fun with ActiveJob on SQS & Lambda.
157
170
 
@@ -181,12 +194,6 @@ end
181
194
 
182
195
  - `retry` - Overrides the default Lambdakiq `max_retries` for this one job.
183
196
 
184
- ## Concurrency & Limits
185
-
186
- AWS SQS is highly scalable with [few limits](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-quotas.html). As your jobs in SQS increases so should your concurrent functions to process that work. However, as this article, ["Why isn't my Lambda function with an Amazon SQS event source scaling optimally?"](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-sqs-scaling/) describes it is possible that errors will effect your concurrency.
187
-
188
- To help keep your queue and workers scalable, reduce the errors raised by your jobs. You an also reduce the retry count.
189
-
190
197
  ## Observability with CloudWatch
191
198
 
192
199
  Get ready to gain way more insights into your ActiveJobs using AWS' [CloudWatch](https://aws.amazon.com/cloudwatch/) service. Every AWS service, including SQS & Lambda, publishes detailed [CloudWatch Metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/working_with_metrics.html). This gem leverages [CloudWatch Embedded Metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html) to add detailed ActiveJob metrics to that system. You can mix and match these data points to build your own [CloudWatch Dashboards](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html). If needed, any combination can be used to trigger [CloudWatch Alarms](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html). Much like Sumo Logic, you can search & query for data using [CloudWatch Logs Insights](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html).
@@ -2,16 +2,6 @@ module Lambdakiq
2
2
  class Error < StandardError
3
3
  end
4
4
 
5
- class JobError < Error
6
- attr_reader :original_exception, :job
7
-
8
- def initialize(error)
9
- @original_exception = error
10
- super(error.message)
11
- set_backtrace Rails.backtrace_cleaner.clean(error.backtrace)
12
- end
13
- end
14
-
15
5
  class FifoDelayError < Error
16
6
  def initialize(error)
17
7
  super
data/lib/lambdakiq/job.rb CHANGED
@@ -9,9 +9,9 @@ module Lambdakiq
9
9
  records = Event.records(event)
10
10
  jobs = records.map { |record| new(record) }
11
11
  jobs.each(&:perform)
12
- jwerror = jobs.detect{ |j| j.error }
13
- return unless jwerror
14
- raise JobError.new(jwerror.error)
12
+ failed_jobs = jobs.select { |j| j.error }
13
+ item_failures = failed_jobs.map { |j| { itemIdentifier: j.provider_job_id } }
14
+ { batchItemFailures: item_failures }
15
15
  end
16
16
 
17
17
  end
@@ -40,10 +40,14 @@ module Lambdakiq
40
40
  active_job.executions
41
41
  end
42
42
 
43
+ def provider_job_id
44
+ active_job.provider_job_id
45
+ end
46
+
43
47
  def perform
44
48
  if fifo_delay?
45
49
  fifo_delay
46
- raise FifoDelayError, active_job.job_id
50
+ return
47
51
  end
48
52
  execute
49
53
  end
@@ -104,6 +108,7 @@ module Lambdakiq
104
108
  end
105
109
 
106
110
  def fifo_delay
111
+ @error = FifoDelayError.new(active_job.job_id)
107
112
  params = client_params.merge visibility_timeout: record.fifo_delay_visibility_timeout
108
113
  client.change_message_visibility(params)
109
114
  end
@@ -30,8 +30,14 @@ module Lambdakiq
30
30
  job.class.name
31
31
  end
32
32
 
33
+ def adapter_name
34
+ event.payload[:adapter].class.name
35
+ end
36
+
33
37
  def lambdakiq?
34
- job.respond_to?(:lambdakiq?) && job.lambdakiq?
38
+ adapter_name.include?('Lambdakiq') &&
39
+ job.respond_to?(:lambdakiq?) &&
40
+ job.lambdakiq?
35
41
  end
36
42
 
37
43
  def logger
@@ -65,7 +71,7 @@ module Lambdakiq
65
71
  set_property 'QueueName', job.queue_name
66
72
  set_property 'MessageId', job.provider_job_id if job.provider_job_id
67
73
  set_property 'ExceptionName', exception_name if exception_name
68
- set_property 'EnqueuedAt', job.enqueued_at if job.enqueued_at
74
+ set_property 'EnqueuedAt', job.enqueued_at if job.respond_to?(:enqueued_at) && job.enqueued_at
69
75
  set_property 'Executions', job.executions if job.executions
70
76
  job.arguments.each_with_index do |argument, index|
71
77
  set_property "JobArg#{index+1}", argument
@@ -113,4 +119,3 @@ module Lambdakiq
113
119
 
114
120
  end
115
121
  end
116
-
@@ -1,3 +1,3 @@
1
1
  module Lambdakiq
2
- VERSION = '1.0.3'
2
+ VERSION = '2.0.1'
3
3
  end
@@ -4,8 +4,8 @@ module Lambdakiq
4
4
 
5
5
  included do
6
6
  class_attribute :lambdakiq_options_hash,
7
- instance_predicate: false,
8
- default: Hash.new
7
+ instance_predicate: false
8
+ self.lambdakiq_options_hash = Hash.new
9
9
  end
10
10
 
11
11
  class_methods do
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: 1.0.3
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Collins
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-04 00:00:00.000000000 Z
11
+ date: 2022-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob