funktor 0.2.17 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/lib/funktor.rb +39 -2
  4. data/lib/funktor/active_job_handler.rb +2 -2
  5. data/lib/funktor/cli/bootstrap.rb +9 -1
  6. data/lib/funktor/cli/init.rb +17 -17
  7. data/lib/funktor/cli/templates/{config → funktor_config}/boot.rb +0 -0
  8. data/lib/funktor/cli/templates/{config → funktor_config}/environment.yml +1 -0
  9. data/lib/funktor/cli/templates/{config → funktor_config}/function_definitions/incoming_job_handler.yml +0 -0
  10. data/lib/funktor/cli/templates/{config → funktor_config}/function_definitions/work_queue_handler.yml +0 -0
  11. data/lib/funktor/cli/templates/{config → funktor_config}/funktor.yml +0 -0
  12. data/lib/funktor/cli/templates/{config → funktor_config}/iam_permissions/incoming_job_queue.yml +0 -0
  13. data/lib/funktor/cli/templates/{config → funktor_config}/iam_permissions/ssm.yml +0 -0
  14. data/lib/funktor/cli/templates/{config → funktor_config}/iam_permissions/work_queue.yml +0 -0
  15. data/lib/funktor/cli/templates/{config → funktor_config}/package.yml +1 -1
  16. data/lib/funktor/cli/templates/{config → funktor_config}/resources/cloudwatch_dashboard.yml +0 -0
  17. data/lib/funktor/cli/templates/{config → funktor_config}/resources/incoming_job_queue.yml +0 -0
  18. data/lib/funktor/cli/templates/{config → funktor_config}/resources/incoming_job_queue_user.yml +0 -0
  19. data/lib/funktor/cli/templates/{config → funktor_config}/resources/work_queue.yml +0 -0
  20. data/lib/funktor/cli/templates/{config → funktor_config}/ruby_layer.yml +0 -0
  21. data/lib/funktor/cli/templates/funktor_init.yml.tt +1 -1
  22. data/lib/funktor/cli/templates/lambda_event_handlers/incoming_job_handler.rb +1 -4
  23. data/lib/funktor/cli/templates/lambda_event_handlers/work_queue_handler.rb +1 -1
  24. data/lib/funktor/cli/templates/serverless.yml +4 -4
  25. data/lib/funktor/error_handler.rb +25 -0
  26. data/lib/funktor/logger.rb +5 -0
  27. data/lib/funktor/version.rb +1 -1
  28. metadata +19 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7b7b575e4abcc04a0b771e3fb9afb912ee82015ed7aa6bcb17570fca0f392fa
4
- data.tar.gz: 98d8caf556c78960b73a1ee40831d4165b01836831d65eb17014239450a5dce7
3
+ metadata.gz: 70f99a435a3ace385ee1dc3741517b03994a57fdd87e167299ef9407793cee18
4
+ data.tar.gz: b510965d08f62dab3891a33921da4d17e9bfcf2d5ee671dffea6ee3b2ef4e0d0
5
5
  SHA512:
6
- metadata.gz: 46b2e852ec64c6f4f5ea23422ec987e95941583f51fe8d76a254df36093c543a4b250c4de5f35abd32df1f9fd8db96df6655b397248697c134a208b8bc60d6f9
7
- data.tar.gz: a7231805102b4a7b05ce8eade0c35c4798779e6ca88171a294137bc20a334e32da47927abdb607d00f83d3585d7dec0d5706c2f6a6baab2e5cbf769b768e4532
6
+ metadata.gz: 5cabd0e3283726d5880fb2d29aeba2277a33fb5daac978843721aac9c6fbf1f94fcc3947755c9d35db42b98291a8c1465cbd03a2fa112dbdca8f44a421b69b0a
7
+ data.tar.gz: 2265f5459d090e444727338d7e5691dfcffd65c1b777456017b4a1b577ebae65fc52b07956fb78de949ac9c6e6aac4b174fa0e9991dab5427b1b661d859a3c7d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- funktor (0.2.17)
4
+ funktor (0.3.0)
5
5
  activesupport
6
6
  aws-sdk-sqs (~> 1.37)
7
7
  thor
@@ -81,4 +81,4 @@ DEPENDENCIES
81
81
  webmock
82
82
 
83
83
  BUNDLED WITH
84
- 2.1.4
84
+ 2.2.24
data/lib/funktor.rb CHANGED
@@ -3,16 +3,21 @@ require 'funktor/aws/sqs/event'
3
3
  require 'funktor/aws/sqs/record'
4
4
  require 'funktor/counter'
5
5
  require 'funktor/job'
6
+ require 'funktor/logger'
6
7
  require 'funktor/worker'
7
8
  require 'funktor/middleware_chain'
8
9
  require 'funktor/incoming_job_handler'
9
- require 'funktor/active_job_handler'
10
10
 
11
11
  require 'json'
12
12
 
13
13
  module Funktor
14
14
  class Error < StandardError; end
15
15
 
16
+ DEFAULT_OPTIONS = {
17
+ error_handlers: [],
18
+ log_level: Logger::DEBUG # Set a high log level during early, active development
19
+ }
20
+
16
21
  def self.configure_job_pusher
17
22
  yield self
18
23
  end
@@ -55,9 +60,41 @@ module Funktor
55
60
  def self.dump_json(object)
56
61
  JSON.generate(object)
57
62
  end
63
+
64
+ def self.options
65
+ @options ||= DEFAULT_OPTIONS.dup
66
+ end
67
+
68
+ def self.options=(opts)
69
+ @options = opts
70
+ end
71
+
72
+ # Register a proc to handle any error which occurs within the Funktor active job handler.
73
+ #
74
+ # Funktor.error_handlers << proc {|error, context| ErrorsAsAService.notify(error, context) }
75
+ #
76
+ # The default error handler logs errors to STDOUT
77
+ def self.error_handlers
78
+ options[:error_handlers]
79
+ end
80
+
81
+ def self.logger
82
+ @logger ||= Funktor::Logger.new($stdout, level: options[:log_level])
83
+ end
84
+
85
+ def self.logger=(logger)
86
+ if logger.nil?
87
+ self.logger.level = Logger::FATAL
88
+ return self.logger
89
+ end
90
+
91
+ @logger = logger
92
+ end
58
93
  end
59
94
 
60
95
  # TODO - Should we require this by default or let people opt in?
61
- # Is it a code smell that we need to include it at the bottom, after
96
+ # TODO - Is it a code smell that we need to include these at the bottom, after
62
97
  # the main Funktor module is defined?
63
98
  require 'funktor/middleware/metrics'
99
+ require 'funktor/error_handler'
100
+ require 'funktor/active_job_handler'
@@ -2,6 +2,7 @@ require 'aws-sdk-sqs'
2
2
 
3
3
  module Funktor
4
4
  class ActiveJobHandler
5
+ include Funktor::ErrorHandler
5
6
 
6
7
  def initialize
7
8
  @failed_counter = Funktor::Counter.new('failed')
@@ -28,8 +29,7 @@ module Funktor
28
29
  @processed_counter.incr(job)
29
30
  # rescue Funktor::Job::InvalidJsonError # TODO Make this work
30
31
  rescue Exception => e
31
- puts "Error during processing: #{$!}"
32
- puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}"
32
+ handle_error(e, job)
33
33
  @failed_counter.incr(job)
34
34
  attempt_retry_or_bail(job)
35
35
  end
@@ -9,6 +9,10 @@ module Funktor
9
9
  :type => :string, :desc => "The bootstrap file to generate.",
10
10
  :default => "funktor_init.yml"
11
11
 
12
+ class_option :directory, :aliases => "-d",
13
+ :type => :string, :desc => "The directory in which to place the bootstrap file.",
14
+ :default => nil
15
+
12
16
  desc <<~DESC
13
17
  Description:
14
18
  Bootstrap a new funktor application by generating a funktor_init.yml file."
@@ -26,7 +30,11 @@ module Funktor
26
30
 
27
31
  private
28
32
  def funktor_file_target
29
- File.join name, options[:file]
33
+ File.join funktor_directory_target, options[:file]
34
+ end
35
+
36
+ def funktor_directory_target
37
+ options[:directory] || name
30
38
  end
31
39
 
32
40
  end
@@ -32,11 +32,11 @@ module Funktor
32
32
 
33
33
  def funktor_config_yml
34
34
  #template "funktor_config.yml", File.join("funktor_config.yml")
35
- template File.join("config", "funktor.yml"), File.join("config", "funktor.yml")
36
- template File.join("config", "ruby_layer.yml"), File.join("config", "ruby_layer.yml")
37
- template File.join("config", "package.yml"), File.join("config", "package.yml")
38
- template File.join("config", "environment.yml"), File.join("config", "environment.yml")
39
- template File.join("config", "boot.rb"), File.join("config", "boot.rb")
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
+ template File.join("funktor_config", "environment.yml"), File.join("funktor_config", "environment.yml")
39
+ template File.join("funktor_config", "boot.rb"), File.join("funktor_config", "boot.rb")
40
40
  end
41
41
 
42
42
  def package_json
@@ -56,33 +56,33 @@ module Funktor
56
56
  end
57
57
 
58
58
  def resources
59
- template File.join("config", "resources", "incoming_job_queue.yml"), File.join("config", "resources", "incoming_job_queue.yml")
60
- template File.join("config", "resources", "incoming_job_queue_user.yml"), File.join("config", "resources", "incoming_job_queue_user.yml")
59
+ template File.join("funktor_config", "resources", "incoming_job_queue.yml"), File.join("funktor_config", "resources", "incoming_job_queue.yml")
60
+ template File.join("funktor_config", "resources", "incoming_job_queue_user.yml"), File.join("funktor_config", "resources", "incoming_job_queue_user.yml")
61
61
  # TODO - Figure out how to make the dashboard aware of various queues...
62
- template File.join("config", "resources", "cloudwatch_dashboard.yml"), File.join("config", "resources", "cloudwatch_dashboard.yml")
62
+ template File.join("funktor_config", "resources", "cloudwatch_dashboard.yml"), File.join("funktor_config", "resources", "cloudwatch_dashboard.yml")
63
63
  queues.each do |queue_details|
64
64
  @work_queue_name = queue_details.keys.first
65
65
  @work_queue_config = queue_details.values.first
66
- template File.join("config", "resources", "work_queue.yml"), File.join("config", "resources", "#{work_queue_name.underscore}_queue.yml")
66
+ template File.join("funktor_config", "resources", "work_queue.yml"), File.join("funktor_config", "resources", "#{work_queue_name.underscore}_queue.yml")
67
67
  end
68
68
  end
69
69
 
70
70
  def iam_permissions
71
- template File.join("config", "iam_permissions", "ssm.yml"), File.join("config", "iam_permissions", "ssm.yml")
72
- template File.join("config", "iam_permissions", "incoming_job_queue.yml"), File.join("config", "iam_permissions", "incoming_job_queue.yml")
71
+ template File.join("funktor_config", "iam_permissions", "ssm.yml"), File.join("funktor_config", "iam_permissions", "ssm.yml")
72
+ template File.join("funktor_config", "iam_permissions", "incoming_job_queue.yml"), File.join("funktor_config", "iam_permissions", "incoming_job_queue.yml")
73
73
  queues.each do |queue_details|
74
74
  @work_queue_name = queue_details.keys.first
75
75
  @work_queue_config = queue_details.values.first
76
- template File.join("config", "iam_permissions", "work_queue.yml"), File.join("config", "iam_permissions", "#{work_queue_name.underscore}_queue.yml")
76
+ template File.join("funktor_config", "iam_permissions", "work_queue.yml"), File.join("funktor_config", "iam_permissions", "#{work_queue_name.underscore}_queue.yml")
77
77
  end
78
78
  end
79
79
 
80
80
  def function_definitions
81
- template File.join("config", "function_definitions", "incoming_job_handler.yml"), File.join("config", "function_definitions", "incoming_job_handler.yml")
81
+ template File.join("funktor_config", "function_definitions", "incoming_job_handler.yml"), File.join("funktor_config", "function_definitions", "incoming_job_handler.yml")
82
82
  queues.each do |queue_details|
83
83
  @work_queue_name = queue_details.keys.first
84
84
  @work_queue_config = queue_details.values.first
85
- template File.join("config", "function_definitions", "work_queue_handler.yml"), File.join("config", "function_definitions", "#{work_queue_name.underscore}_queue_handler.yml")
85
+ template File.join("funktor_config", "function_definitions", "work_queue_handler.yml"), File.join("funktor_config", "function_definitions", "#{work_queue_name.underscore}_queue_handler.yml")
86
86
  end
87
87
  end
88
88
 
@@ -112,15 +112,15 @@ module Funktor
112
112
  end
113
113
 
114
114
  def all_iam_permissions
115
- Dir.glob(File.join('config', 'iam_permissions', '**.yml'))
115
+ Dir.glob(File.join('funktor_config', 'iam_permissions', '**.yml'))
116
116
  end
117
117
 
118
118
  def all_function_definitions
119
- Dir.glob(File.join('config', 'function_definitions', '**.yml'))
119
+ Dir.glob(File.join('funktor_config', 'function_definitions', '**.yml'))
120
120
  end
121
121
 
122
122
  def all_resources
123
- Dir.glob(File.join('config', 'resources', '**.yml'))
123
+ Dir.glob(File.join('funktor_config', 'resources', '**.yml'))
124
124
  end
125
125
 
126
126
  def funktor_config
@@ -1,3 +1,4 @@
1
+ BUNDLE_WITHOUT: development:test
1
2
  FUNKTOR_APP_NAME: <%= app_name %>
2
3
  FUNKTOR_INCOMING_JOB_QUEUE:
3
4
  Ref: IncomingJobQueue
@@ -3,7 +3,7 @@ individually: false
3
3
  include:
4
4
  - Gemfile
5
5
  - Gemfile.lock
6
- - config/boot.rb
6
+ - funktor_config/boot.rb
7
7
  - app/**
8
8
  # Evertyting is excluded by default with serverless-ruby-layer, but you could use
9
9
  # the lines below to exlude files that are inside an include path.
@@ -66,4 +66,4 @@ package:
66
66
  - Gemfile
67
67
  - Gemfile.lock
68
68
  - app/**
69
- - config/**
69
+ - funktor_config/**
@@ -1,7 +1,4 @@
1
- # For this handler we don't need to know about your app, or any of the other gems,
2
- # so instead of doing `require_relative '../config/boog'` we just manually require
3
- # the one gem that we do need.
4
- require 'funktor'
1
+ require_relative '../funktor_config/boot'
5
2
 
6
3
  $handler = Funktor::IncomingJobHandler.new
7
4
 
@@ -1,4 +1,4 @@
1
- require_relative '../config/boot'
1
+ require_relative '../funktor_config/boot'
2
2
 
3
3
  $handler = Funktor::ActiveJobHandler.new
4
4
 
@@ -24,7 +24,7 @@ provider:
24
24
  name: aws
25
25
  runtime: <%= runtime %>
26
26
  lambdaHashingVersion: 20201221
27
- environment: ${file(config/environment.yml)}
27
+ environment: ${file(funktor_config/environment.yml)}
28
28
  versionFunctions: false # Reduces the amount of storage used since all Lambdas together are limited to 75GB
29
29
  iamRoleStatements:
30
30
  <%- all_iam_permissions.each do |iam_permission| -%>
@@ -36,10 +36,10 @@ custom:
36
36
  # Our stage is based on what is passed in when running serverless
37
37
  # commands. Or fallsback to what we have set in the provider section.
38
38
  stage: ${self:provider.stage, 'dev'}
39
- funktor: ${file(config/funktor.yml)}
40
- rubyLayer: ${file(config/ruby_layer.yml)}
39
+ funktor: ${file(funktor_config/funktor.yml)}
40
+ rubyLayer: ${file(funktor_config/ruby_layer.yml)}
41
41
 
42
- package: ${file(config/package.yml)}
42
+ package: ${file(funktor_config/package.yml)}
43
43
 
44
44
  functions:
45
45
  <%- all_function_definitions.each do |function_definition| -%>
@@ -0,0 +1,25 @@
1
+ module Funktor
2
+ module ErrorHandler
3
+ class Logger
4
+ def call(error, context)
5
+ Funktor.logger.warn(Funktor.dump_json(context)) if context
6
+ Funktor.logger.warn("#{error.class.name}: #{error.message}")
7
+ Funktor.logger.warn(error.backtrace.join("\n")) unless error.backtrace.nil?
8
+ end
9
+
10
+ Funktor.error_handlers << Funktor::ErrorHandler::Logger.new
11
+ end
12
+
13
+ def handle_error(error, context = {})
14
+ Funktor.error_handlers.each do |handler|
15
+ begin
16
+ handler.call(error, context)
17
+ rescue => new_error
18
+ Funktor.logger.error "!!! ERROR HANDLER THREW AN ERROR !!!"
19
+ Funktor.logger.error new_error
20
+ Funktor.logger.error new_error.backtrace.join("\n") unless new_error.backtrace.nil?
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ require 'logger'
2
+ module Funktor
3
+ class Logger < ::Logger
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Funktor
2
- VERSION = "0.2.17"
2
+ VERSION = "0.3.1"
3
3
  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.2.17
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Green
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-02 00:00:00.000000000 Z
11
+ date: 2021-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-sqs
@@ -116,20 +116,20 @@ files:
116
116
  - lib/funktor/cli/init.rb
117
117
  - lib/funktor/cli/templates/Gemfile
118
118
  - lib/funktor/cli/templates/app/workers/hello_worker.rb
119
- - lib/funktor/cli/templates/config/boot.rb
120
- - lib/funktor/cli/templates/config/environment.yml
121
- - lib/funktor/cli/templates/config/function_definitions/incoming_job_handler.yml
122
- - lib/funktor/cli/templates/config/function_definitions/work_queue_handler.yml
123
- - lib/funktor/cli/templates/config/funktor.yml
124
- - lib/funktor/cli/templates/config/iam_permissions/incoming_job_queue.yml
125
- - lib/funktor/cli/templates/config/iam_permissions/ssm.yml
126
- - lib/funktor/cli/templates/config/iam_permissions/work_queue.yml
127
- - lib/funktor/cli/templates/config/package.yml
128
- - lib/funktor/cli/templates/config/resources/cloudwatch_dashboard.yml
129
- - lib/funktor/cli/templates/config/resources/incoming_job_queue.yml
130
- - lib/funktor/cli/templates/config/resources/incoming_job_queue_user.yml
131
- - lib/funktor/cli/templates/config/resources/work_queue.yml
132
- - lib/funktor/cli/templates/config/ruby_layer.yml
119
+ - lib/funktor/cli/templates/funktor_config/boot.rb
120
+ - lib/funktor/cli/templates/funktor_config/environment.yml
121
+ - lib/funktor/cli/templates/funktor_config/function_definitions/incoming_job_handler.yml
122
+ - lib/funktor/cli/templates/funktor_config/function_definitions/work_queue_handler.yml
123
+ - lib/funktor/cli/templates/funktor_config/funktor.yml
124
+ - lib/funktor/cli/templates/funktor_config/iam_permissions/incoming_job_queue.yml
125
+ - lib/funktor/cli/templates/funktor_config/iam_permissions/ssm.yml
126
+ - lib/funktor/cli/templates/funktor_config/iam_permissions/work_queue.yml
127
+ - lib/funktor/cli/templates/funktor_config/package.yml
128
+ - lib/funktor/cli/templates/funktor_config/resources/cloudwatch_dashboard.yml
129
+ - lib/funktor/cli/templates/funktor_config/resources/incoming_job_queue.yml
130
+ - lib/funktor/cli/templates/funktor_config/resources/incoming_job_queue_user.yml
131
+ - lib/funktor/cli/templates/funktor_config/resources/work_queue.yml
132
+ - lib/funktor/cli/templates/funktor_config/ruby_layer.yml
133
133
  - lib/funktor/cli/templates/funktor_init.yml.tt
134
134
  - lib/funktor/cli/templates/gitignore
135
135
  - lib/funktor/cli/templates/lambda_event_handlers/incoming_job_handler.rb
@@ -137,9 +137,11 @@ files:
137
137
  - lib/funktor/cli/templates/package.json
138
138
  - lib/funktor/cli/templates/serverless.yml
139
139
  - lib/funktor/counter.rb
140
+ - lib/funktor/error_handler.rb
140
141
  - lib/funktor/fake_job_queue.rb
141
142
  - lib/funktor/incoming_job_handler.rb
142
143
  - lib/funktor/job.rb
144
+ - lib/funktor/logger.rb
143
145
  - lib/funktor/middleware/metrics.rb
144
146
  - lib/funktor/middleware_chain.rb
145
147
  - lib/funktor/testing.rb
@@ -166,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
168
  - !ruby/object:Gem::Version
167
169
  version: '0'
168
170
  requirements: []
169
- rubygems_version: 3.1.4
171
+ rubygems_version: 3.2.24
170
172
  signing_key:
171
173
  specification_version: 4
172
174
  summary: Background processing in AWS Lambda.