funktor 0.7.24 → 0.7.27

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: 8fdcd3e939904ca9cd77b31c29842e3a43c5cbf53113180c8fbb32fc3fe7c5e2
4
- data.tar.gz: 3ed291a899ad41382275e2f0a1cb4da28d688a5b262831a4eed96e5487024200
3
+ metadata.gz: ef7feda36c3d7a6609b907b94632602d744b98a2f685853eb4686f77aa62330b
4
+ data.tar.gz: 6ceaf132ea54f0e97760a05660208e262d7ed9c1d0473522100b5bf5c3d39161
5
5
  SHA512:
6
- metadata.gz: 6c2c23526960146d1d7d0e895484dba8c1403bc1dafbbe88d1fa4309765c8176294c126447b5ca4806f59f74d03ae504a710121d97301a1759234b133e6a15ce
7
- data.tar.gz: 15ad50995710277c1bf8105d53b38c6f3746ae1139613dd2f4e4630c5539204452d8675f815d50bdb53046ccae13452e939909ff081d481f435eac67318b97f5
6
+ metadata.gz: 5ee21aa7210894ad2a05554d73eaa0958100ac87956e8e70e85146e0e04e419e402afc905f9eb20ba488537be053882739deb8595842cb50953594617e5f2dfc
7
+ data.tar.gz: 9dbbed69db716f99cf8bd16db47938a45036b16d88bd5c576f862c3b2dd9457a589b15697829f95ed669d801d5e58bac856a4406c980d94157fd8a627bd88c2e
data/Gemfile CHANGED
@@ -5,3 +5,5 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
+
9
+ gem 'newrelic_rpm'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- funktor (0.7.24)
4
+ funktor (0.7.27)
5
5
  activesupport
6
6
  aws-sdk-dynamodb (~> 1.62)
7
7
  aws-sdk-sqs (~> 1.37)
@@ -22,7 +22,7 @@ GEM
22
22
  addressable (2.8.0)
23
23
  public_suffix (>= 2.0.2, < 5.0)
24
24
  aws-eventstream (1.2.0)
25
- aws-partitions (1.595.0)
25
+ aws-partitions (1.597.0)
26
26
  aws-sdk-core (3.131.1)
27
27
  aws-eventstream (~> 1, >= 1.0.2)
28
28
  aws-partitions (~> 1, >= 1.525.0)
@@ -53,6 +53,7 @@ GEM
53
53
  minitest (5.14.4)
54
54
  mustermann (1.1.1)
55
55
  ruby2_keywords (~> 0.0.1)
56
+ newrelic_rpm (8.8.0)
56
57
  pry (0.13.1)
57
58
  coderay (~> 1.1)
58
59
  method_source (~> 1.0)
@@ -107,6 +108,7 @@ PLATFORMS
107
108
  DEPENDENCIES
108
109
  activejob (>= 5.1.5)
109
110
  funktor!
111
+ newrelic_rpm
110
112
  pry-byebug
111
113
  rake (~> 12.0)
112
114
  rspec (~> 3.0)
@@ -8,7 +8,7 @@ FROM public.ecr.aws/lambda/ruby:2.7 AS build_image
8
8
  #ENV BUNDLE_GEM__FURY__IO=${BUNDLE_GEM__FURY__IO}
9
9
 
10
10
  # First we install some stuff that we need for gems that have to compile native extensions
11
- #RUN yum groupinstall "Development Tools" -y
11
+ RUN yum groupinstall "Development Tools" -y
12
12
  #RUN yum install -y amazon-linux-extras
13
13
  #RUN amazon-linux-extras enable postgresql11
14
14
  #RUN yum install -y postgresql-devel
@@ -57,6 +57,12 @@ FROM public.ecr.aws/lambda/ruby:2.7 AS deploy_image
57
57
  COPY --from=build_image /var/task .
58
58
  COPY . .
59
59
 
60
+ # Now we prime the bootsnap cache to minimize cold start times.
61
+
62
+ ENV BOOTSNAP_CACHE_DIR=/var/task/tmp/cache
63
+ RUN bundle exec bootsnap precompile --gemfile . \
64
+ && SKIP_ENV=true bundle exec ruby lambda_event_handlers/incoming_job_handler.rb
65
+
60
66
  # And finally we have the CMD for the deployed container
61
67
  # You can overwrite command in `serverless.yml` template
62
68
  CMD [ "app.LambdaFunction::Handler.process" ]
@@ -23,3 +23,5 @@ gem 'aws-sdk-dynamodb', '~> 1.62'
23
23
  gem "activesupport"
24
24
  gem "thor" # Thor drives the CLI TODO - Maybe we don't need it here?
25
25
 
26
+ # This helps make cold starts faster
27
+ gem 'bootsnap', require: false
@@ -22,11 +22,14 @@ GEM
22
22
  aws-sigv4 (~> 1.1)
23
23
  aws-sigv4 (1.2.4)
24
24
  aws-eventstream (~> 1, >= 1.0.2)
25
+ bootsnap (1.12.0)
26
+ msgpack (~> 1.2)
25
27
  concurrent-ruby (1.1.9)
26
28
  i18n (1.8.10)
27
29
  concurrent-ruby (~> 1.0)
28
30
  jmespath (1.4.0)
29
31
  minitest (5.14.4)
32
+ msgpack (1.5.2)
30
33
  require_all (1.5.0)
31
34
  thor (1.1.0)
32
35
  tzinfo (2.0.4)
@@ -41,6 +44,7 @@ DEPENDENCIES
41
44
  activesupport
42
45
  aws-sdk-dynamodb (~> 1.62)
43
46
  aws-sdk-sqs (~> 1.37)
47
+ bootsnap
44
48
  require_all (~> 1.0)
45
49
  thor
46
50
 
@@ -5,6 +5,9 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
5
5
  require "rubygems"
6
6
  require 'bundler/setup'
7
7
 
8
+ # load bootsnap for faster cold starts
9
+ require 'bootsnap/setup'
10
+
8
11
  # Set up gems listed in the Gemfile.
9
12
  Bundler.require(:default, :production)
10
13
 
@@ -52,9 +52,6 @@ custom:
52
52
  # commands. Or fallsback to what we have set in the provider section.
53
53
  stage: ${self:provider.stage, 'dev'}
54
54
  funktor: ${file(funktor_config/funktor.yml)}
55
- #rubyLayer: ${file(funktor_config/ruby_layer.yml)}
56
-
57
- #package: ${file(funktor_config/package.yml)}
58
55
 
59
56
  functions:
60
57
  IncomingJobHandler: ${file(funktor_config/function_definitions/incoming_job_handler.yml)}
@@ -72,4 +69,3 @@ resources:
72
69
  - ${file(funktor_config/resources/jobs_table.yml)}
73
70
 
74
71
  plugins:
75
- #- serverless-ruby-layer
@@ -33,27 +33,13 @@ module Funktor
33
33
  def funktor_config_yml
34
34
  #template "funktor_config.yml", File.join("funktor_config.yml")
35
35
  template File.join("funktor_config", "funktor.yml"), File.join("funktor_config", "funktor.yml")
36
- template File.join("funktor_config", "ruby_layer.yml"), File.join("funktor_config", "ruby_layer.yml")
37
- template File.join("funktor_config", "package.yml"), File.join("funktor_config", "package.yml")
38
36
  template File.join("funktor_config", "environment.yml"), File.join("funktor_config", "environment.yml")
39
37
  template File.join("funktor_config", "boot.rb"), File.join("funktor_config", "boot.rb")
40
38
  end
41
39
 
42
40
  def package_json
43
41
  if File.exist?("package.json")
44
- package_data = File.open("package.json").read
45
- if package_data =~ /serverless-ruby-layer/
46
- say "serverless-ruby-layer is already installed in package.json"
47
- else
48
- if File.exist?("package-lock.json")
49
- run "npm install serverless-ruby-layer@1.4.0 --save-dev"
50
- # TODO - Add handers for yarn and what not
51
- elsif File.exist?("yarn.lock")
52
- run "yarn add --dev serverless-ruby-layer@1.4.0"
53
- else
54
- say "You should install serverless-ruby-layer version 1.4.0 using yor package manager of choice."
55
- end
56
- end
42
+ say "package.json already exists"
57
43
  else
58
44
  template "package.json", File.join("package.json")
59
45
  end
@@ -8,7 +8,7 @@ FROM public.ecr.aws/lambda/ruby:2.7 AS build_image
8
8
  #ENV BUNDLE_GEM__FURY__IO=${BUNDLE_GEM__FURY__IO}
9
9
 
10
10
  # First we install some stuff that we need for gems that have to compile native extensions
11
- #RUN yum groupinstall "Development Tools" -y
11
+ RUN yum groupinstall "Development Tools" -y
12
12
  #RUN yum install -y amazon-linux-extras
13
13
  #RUN amazon-linux-extras enable postgresql11
14
14
  #RUN yum install -y postgresql-devel
@@ -57,6 +57,12 @@ FROM public.ecr.aws/lambda/ruby:2.7 AS deploy_image
57
57
  COPY --from=build_image /var/task .
58
58
  COPY . .
59
59
 
60
+ # Now we prime the bootsnap cache to minimize cold start times.
61
+
62
+ ENV BOOTSNAP_CACHE_DIR=/var/task/tmp/cache
63
+ RUN bundle exec bootsnap precompile --gemfile . \
64
+ && SKIP_ENV=true bundle exec ruby lambda_event_handlers/incoming_job_handler.rb
65
+
60
66
  # And finally we have the CMD for the deployed container
61
67
  # You can overwrite command in `serverless.yml` template
62
68
  CMD [ "app.LambdaFunction::Handler.process" ]
@@ -4,4 +4,4 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
4
4
  ruby '~> 2.7'
5
5
 
6
6
  gem 'funktor'
7
-
7
+ gem 'bootsnap', require: false
@@ -5,6 +5,9 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
5
5
  require "rubygems"
6
6
  require 'bundler/setup'
7
7
 
8
+ # load bootsnap for faster cold starts
9
+ require 'bootsnap/setup'
10
+
8
11
  # Set up gems listed in the Gemfile.
9
12
  Bundler.require(:default, :production)
10
13
 
@@ -38,12 +38,12 @@ handlerDefaults:
38
38
  # Visibility timeout should only come into play in the case of Funktor errors.
39
39
  # Application level errors should be handled by Funktor retry mechanisms.
40
40
  # The visibility timeout should be at least as long as the function timeout, and up to 6 times larger.
41
- visibilityTimeout: 1800
41
+ visibilityTimeout: 300
42
42
 
43
43
  # Max recieve count affects how many times a job will retry that has been throttled at the SQS -> Lambda boundary.
44
44
  # Amazon recommend this be at least 5, but I've found that higher numbers are better to avoid legit jobs ending
45
45
  # up in the dead letter queue
46
- maxReceiveCount: 20
46
+ maxReceiveCount: 120
47
47
 
48
48
  # Incoming Job Handler
49
49
  incomingJobHandler:
@@ -3,6 +3,5 @@
3
3
  "description": "",
4
4
  "version": "0.1.0",
5
5
  "devDependencies": {
6
- "serverless-ruby-layer": "^1.4.0"
7
6
  }
8
7
  }
@@ -49,9 +49,6 @@ custom:
49
49
  # commands. Or fallsback to what we have set in the provider section.
50
50
  stage: ${self:provider.stage, 'dev'}
51
51
  funktor: ${file(funktor_config/funktor.yml)}
52
- #rubyLayer: ${file(funktor_config/ruby_layer.yml)}
53
-
54
- #package: ${file(funktor_config/package.yml)}
55
52
 
56
53
  functions:
57
54
  <%- all_function_definitions.each do |function_definition| -%>
@@ -64,4 +61,3 @@ resources:
64
61
  <%- end -%>
65
62
 
66
63
  plugins:
67
- #- serverless-ruby-layer
data/lib/funktor/job.rb CHANGED
@@ -114,8 +114,16 @@ module Funktor
114
114
  self.delay = seconds_to_delay(retries)
115
115
  end
116
116
 
117
- # delayed_job and sidekiq use the same basic formula
118
117
  def seconds_to_delay(count)
118
+ if worker_class&.funktor_retry_in_block
119
+ worker_class.funktor_retry_in_block.call(count)
120
+ else
121
+ default_seconds_to_delay(count)
122
+ end
123
+ end
124
+
125
+ # delayed_job and sidekiq use the same basic formula
126
+ def default_seconds_to_delay(count)
119
127
  (count**4) + 15 + (rand(30) * (count + 1))
120
128
  end
121
129
 
@@ -124,7 +132,7 @@ module Funktor
124
132
  end
125
133
 
126
134
  def retry_limit
127
- 25
135
+ worker_class&.custom_retry_limit || 25
128
136
  end
129
137
 
130
138
  def can_retry
@@ -0,0 +1,34 @@
1
+ require 'newrelic_rpm'
2
+ module Funktor
3
+ module Middleware
4
+ class NewRelic
5
+ include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
6
+
7
+ def call(job)
8
+ trace_args = {
9
+ :name => 'perform',
10
+ :class_name => job.worker_class_name_for_metrics,
11
+ :category => 'OtherTransaction/Funktor'
12
+ }
13
+ perform_action_with_newrelic_trace(trace_args) do
14
+ ::NewRelic::Agent::Transaction.merge_untrusted_agent_attributes(job.worker_params,
15
+ :'worker.funktor.params',
16
+ ::NewRelic::Agent::AttributeFilter::DST_NONE)
17
+ yield
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def new_relic!
24
+ Funktor.configure_work_queue_handler do |config|
25
+ config.work_queue_handler_middleware do |chain|
26
+ chain.add Funktor::Middleware::NewRelic
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+
33
+
34
+
@@ -1,3 +1,3 @@
1
1
  module Funktor
2
- VERSION = "0.7.24"
2
+ VERSION = "0.7.27"
3
3
  end
@@ -7,6 +7,7 @@ module Funktor
7
7
  base.extend ClassMethods
8
8
  base.class_eval do
9
9
  class_attribute :funktor_options_hash
10
+ class_attribute :funktor_retry_in_block
10
11
  end
11
12
  end
12
13
  module ClassMethods
@@ -18,6 +19,10 @@ module Funktor
18
19
  self.funktor_options_hash || {}
19
20
  end
20
21
 
22
+ def funktor_retry_in(&block)
23
+ self.funktor_retry_in_block = block
24
+ end
25
+
21
26
  def custom_queue_url
22
27
  get_funktor_options[:queue_url]
23
28
  end
@@ -26,6 +31,16 @@ module Funktor
26
31
  get_funktor_options[:queue]
27
32
  end
28
33
 
34
+ def custom_retry_limit
35
+ retry_limit = get_funktor_options[:retry]
36
+ if retry_limit.nil?
37
+ retry_limit = 25
38
+ elsif !retry_limit # if someone did "retry: false"
39
+ retry_limit = 0
40
+ end
41
+ return retry_limit
42
+ end
43
+
29
44
  def queue_url
30
45
  custom_queue_url
31
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: funktor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.24
4
+ version: 0.7.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Green
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-03 00:00:00.000000000 Z
11
+ date: 2022-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-sqs
@@ -199,14 +199,12 @@ files:
199
199
  - funktor-testapp/funktor_config/iam_permissions/jobs_table_secondary_index.yml
200
200
  - funktor-testapp/funktor_config/iam_permissions/low_concurrency_queue.yml
201
201
  - funktor-testapp/funktor_config/iam_permissions/ssm.yml
202
- - funktor-testapp/funktor_config/package.yml
203
202
  - funktor-testapp/funktor_config/resources/cloudwatch_dashboard.yml
204
203
  - funktor-testapp/funktor_config/resources/default_queue.yml
205
204
  - funktor-testapp/funktor_config/resources/incoming_job_queue.yml
206
205
  - funktor-testapp/funktor_config/resources/incoming_job_queue_user.yml
207
206
  - funktor-testapp/funktor_config/resources/jobs_table.yml
208
207
  - funktor-testapp/funktor_config/resources/low_concurrency_queue.yml
209
- - funktor-testapp/funktor_config/ruby_layer.yml
210
208
  - funktor-testapp/funktor_init.yml
211
209
  - funktor-testapp/lambda_event_handlers/default_queue_handler.rb
212
210
  - funktor-testapp/lambda_event_handlers/incoming_job_handler.rb
@@ -242,13 +240,11 @@ files:
242
240
  - lib/funktor/cli/templates/funktor_config/iam_permissions/jobs_table_secondary_index.yml
243
241
  - lib/funktor/cli/templates/funktor_config/iam_permissions/ssm.yml
244
242
  - lib/funktor/cli/templates/funktor_config/iam_permissions/work_queue.yml
245
- - lib/funktor/cli/templates/funktor_config/package.yml
246
243
  - lib/funktor/cli/templates/funktor_config/resources/cloudwatch_dashboard.yml
247
244
  - lib/funktor/cli/templates/funktor_config/resources/incoming_job_queue.yml
248
245
  - lib/funktor/cli/templates/funktor_config/resources/incoming_job_queue_user.yml
249
246
  - lib/funktor/cli/templates/funktor_config/resources/jobs_table.yml
250
247
  - lib/funktor/cli/templates/funktor_config/resources/work_queue.yml
251
- - lib/funktor/cli/templates/funktor_config/ruby_layer.yml
252
248
  - lib/funktor/cli/templates/funktor_init.yml.tt
253
249
  - lib/funktor/cli/templates/gitignore
254
250
  - lib/funktor/cli/templates/lambda_event_handlers/incoming_job_handler.rb
@@ -265,6 +261,7 @@ files:
265
261
  - lib/funktor/job_pusher.rb
266
262
  - lib/funktor/logger.rb
267
263
  - lib/funktor/middleware/metrics.rb
264
+ - lib/funktor/middleware/new_relic.rb
268
265
  - lib/funktor/middleware_chain.rb
269
266
  - lib/funktor/rails.rb
270
267
  - lib/funktor/shard_utils.rb
@@ -1,11 +0,0 @@
1
- # TODO - Figure out how to allow individual packaging to work out of the box.
2
- #individually: false
3
- #include:
4
- #- Gemfile
5
- #- Gemfile.lock
6
- #- funktor_config/boot.rb
7
- #- app/**
8
- # Evertyting is excluded by default with serverless-ruby-layer, but you could use
9
- # the lines below to exlude files that are inside an include path.
10
- #exclude:
11
- # - workers/excluded_worker.rb
@@ -1,11 +0,0 @@
1
- #use_docker: false
2
- #docker_yums:
3
- #- postgresql-devel
4
- #native_libs:
5
- #- /usr/lib64/libpq.so.5
6
- #- /usr/lib64/libldap_r-2.4.so.2
7
- #- /usr/lib64/liblber-2.4.so.2
8
- #- /usr/lib64/libsasl2.so.3
9
- #- /usr/lib64/libssl3.so
10
- #- /usr/lib64/libsmime3.so
11
- #- /usr/lib64/libnss3.so
@@ -1,11 +0,0 @@
1
- # TODO - Figure out how to allow individual packaging to work out of the box.
2
- #individually: false
3
- #include:
4
- #- Gemfile
5
- #- Gemfile.lock
6
- #- funktor_config/boot.rb
7
- #- app/**
8
- # Evertyting is excluded by default with serverless-ruby-layer, but you could use
9
- # the lines below to exlude files that are inside an include path.
10
- #exclude:
11
- # - workers/excluded_worker.rb
@@ -1,11 +0,0 @@
1
- #use_docker: false
2
- #docker_yums:
3
- #- postgresql-devel
4
- #native_libs:
5
- #- /usr/lib64/libpq.so.5
6
- #- /usr/lib64/libldap_r-2.4.so.2
7
- #- /usr/lib64/liblber-2.4.so.2
8
- #- /usr/lib64/libsasl2.so.3
9
- #- /usr/lib64/libssl3.so
10
- #- /usr/lib64/libsmime3.so
11
- #- /usr/lib64/libnss3.so