funktor 0.4.7 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.tool-versions +2 -0
  3. data/Gemfile.lock +7 -3
  4. data/funktor-testapp/.envrc +1 -0
  5. data/funktor-testapp/.gitignore +7 -0
  6. data/funktor-testapp/Gemfile +25 -0
  7. data/funktor-testapp/Gemfile.lock +51 -0
  8. data/funktor-testapp/app/services/job_flood.rb +38 -0
  9. data/funktor-testapp/app/workers/audit_worker.rb +49 -0
  10. data/funktor-testapp/app/workers/greetings_worker.rb +3 -0
  11. data/funktor-testapp/app/workers/hello_worker.rb +18 -0
  12. data/funktor-testapp/deploy-dev.sh +5 -0
  13. data/funktor-testapp/funktor_config/boot.rb +17 -0
  14. data/funktor-testapp/funktor_config/environment.yml +15 -0
  15. data/funktor-testapp/funktor_config/function_definitions/default_queue_handler.yml +11 -0
  16. data/funktor-testapp/funktor_config/function_definitions/incoming_job_handler.yml +11 -0
  17. data/funktor-testapp/funktor_config/function_definitions/job_activator.yml +8 -0
  18. data/funktor-testapp/funktor_config/function_definitions/random_job_generator.yml +18 -0
  19. data/funktor-testapp/funktor_config/function_definitions/single_thread_queue_handler.yml +11 -0
  20. data/funktor-testapp/funktor_config/funktor.yml +114 -0
  21. data/funktor-testapp/funktor_config/iam_permissions/activity_table.yml +5 -0
  22. data/funktor-testapp/funktor_config/iam_permissions/default_queue.yml +8 -0
  23. data/funktor-testapp/funktor_config/iam_permissions/incoming_job_queue.yml +8 -0
  24. data/funktor-testapp/funktor_config/iam_permissions/jobs_table.yml +5 -0
  25. data/funktor-testapp/funktor_config/iam_permissions/jobs_table_secondary_index.yml +8 -0
  26. data/funktor-testapp/funktor_config/iam_permissions/single_thread_queue.yml +8 -0
  27. data/funktor-testapp/funktor_config/iam_permissions/ssm.yml +5 -0
  28. data/funktor-testapp/funktor_config/package.yml +11 -0
  29. data/funktor-testapp/funktor_config/resources/activity_table.yml +22 -0
  30. data/funktor-testapp/funktor_config/resources/cloudwatch_dashboard.yml +804 -0
  31. data/funktor-testapp/funktor_config/resources/default_queue.yml +22 -0
  32. data/funktor-testapp/funktor_config/resources/incoming_job_queue.yml +22 -0
  33. data/funktor-testapp/funktor_config/resources/incoming_job_queue_user.yml +26 -0
  34. data/funktor-testapp/funktor_config/resources/jobs_table.yml +44 -0
  35. data/funktor-testapp/funktor_config/resources/single_thread_queue.yml +22 -0
  36. data/funktor-testapp/funktor_config/ruby_layer.yml +11 -0
  37. data/funktor-testapp/funktor_init.yml +61 -0
  38. data/funktor-testapp/lambda_event_handlers/default_queue_handler.rb +8 -0
  39. data/funktor-testapp/lambda_event_handlers/incoming_job_handler.rb +8 -0
  40. data/funktor-testapp/lambda_event_handlers/job_activator.rb +8 -0
  41. data/funktor-testapp/lambda_event_handlers/random_job_generator.rb +35 -0
  42. data/funktor-testapp/lambda_event_handlers/single_thread_queue_handler.rb +8 -0
  43. data/funktor-testapp/package-lock.json +248 -0
  44. data/funktor-testapp/package.json +8 -0
  45. data/funktor-testapp/serverless.yml +65 -0
  46. data/funktor.gemspec +1 -0
  47. data/lib/active_job/queue_adapters/funktor_adapter.rb +3 -3
  48. data/lib/funktor.rb +39 -7
  49. data/lib/funktor/activity_tracker.rb +102 -0
  50. data/lib/funktor/cli/bootstrap.rb +0 -1
  51. data/lib/funktor/cli/init.rb +13 -0
  52. data/lib/funktor/cli/templates/app/workers/hello_worker.rb +1 -1
  53. data/lib/funktor/cli/templates/funktor_config/environment.yml +4 -0
  54. data/lib/funktor/cli/templates/funktor_config/function_definitions/job_activator.yml +8 -0
  55. data/lib/funktor/cli/templates/funktor_config/funktor.yml +28 -2
  56. data/lib/funktor/cli/templates/funktor_config/iam_permissions/activity_table.yml +5 -0
  57. data/lib/funktor/cli/templates/funktor_config/iam_permissions/jobs_table.yml +5 -0
  58. data/lib/funktor/cli/templates/funktor_config/iam_permissions/jobs_table_secondary_index.yml +8 -0
  59. data/lib/funktor/cli/templates/funktor_config/resources/activity_table.yml +22 -0
  60. data/lib/funktor/cli/templates/funktor_config/resources/cloudwatch_dashboard.yml +10 -10
  61. data/lib/funktor/cli/templates/funktor_config/resources/jobs_table.yml +44 -0
  62. data/lib/funktor/cli/templates/funktor_init.yml.tt +2 -8
  63. data/lib/funktor/cli/templates/lambda_event_handlers/job_activator.rb +8 -0
  64. data/lib/funktor/cli/templates/lambda_event_handlers/work_queue_handler.rb +1 -1
  65. data/lib/funktor/cli/templates/serverless.yml +2 -2
  66. data/lib/funktor/counter.rb +4 -1
  67. data/lib/funktor/incoming_job_handler.rb +52 -12
  68. data/lib/funktor/job.rb +10 -5
  69. data/lib/funktor/job_activator.rb +98 -0
  70. data/lib/funktor/job_pusher.rb +0 -2
  71. data/lib/funktor/middleware/metrics.rb +8 -3
  72. data/lib/funktor/testing.rb +49 -47
  73. data/lib/funktor/version.rb +1 -1
  74. data/lib/funktor/{active_job_handler.rb → work_queue_handler.rb} +17 -15
  75. data/lib/funktor/worker.rb +0 -7
  76. metadata +69 -3
@@ -2,6 +2,7 @@ require 'funktor/worker'
2
2
  require 'funktor/fake_job_queue'
3
3
 
4
4
  module Funktor
5
+
5
6
  module Worker
6
7
  def self.clear_all
7
8
  Funktor::FakeJobQueue.clear_all
@@ -25,67 +26,68 @@ module Funktor
25
26
  end
26
27
  end
27
28
  end
29
+
28
30
  class Testing
31
+ class << self
32
+ attr_accessor :mode
29
33
 
30
- # TODO : We probably shouldn't use middleware for this. We should alter the behavior
31
- # of the JobPusher in the testing module isntead.
32
- def self.inline!(&block)
33
- unless block_given?
34
- raise "Funktor inline testing mode can only be called in block form."
34
+ def inline?
35
+ mode == :inline
35
36
  end
36
- Funktor.configure_job_pusher do |config|
37
- config.job_pusher_middleware do |chain|
38
- chain.add Funktor::InlineJobPusherMiddleware
39
- end
37
+
38
+ def fake?
39
+ mode == :fake
40
40
  end
41
- yield
42
- Funktor.configure_job_pusher do |config|
43
- config.job_pusher_middleware do |chain|
44
- chain.remove Funktor::InlineJobPusherMiddleware
41
+
42
+ def inline!(&block)
43
+ unless block_given?
44
+ raise "Funktor inline testing mode can only be called in block form."
45
45
  end
46
+ set_mode(:inline, &block)
46
47
  end
47
- end
48
- def self.fake!(&block)
49
- if block_given?
50
- Funktor.configure_job_pusher do |config|
51
- config.job_pusher_middleware do |chain|
52
- chain.add Funktor::FakeJobPusherMiddleware
53
- end
54
- end
55
- yield
56
- Funktor.configure_job_pusher do |config|
57
- config.job_pusher_middleware do |chain|
58
- chain.remove Funktor::FakeJobPusherMiddleware
59
- end
60
- end
61
- else
62
- Funktor.configure_job_pusher do |config|
63
- config.job_pusher_middleware do |chain|
64
- chain.add Funktor::FakeJobPusherMiddleware
48
+
49
+ def fake!(&block)
50
+ set_mode(:fake, &block)
51
+ end
52
+
53
+ def disable!
54
+ set_mode(:disabled)
55
+ end
56
+
57
+ def set_mode(new_mode, &block)
58
+ if block_given?
59
+ original_mode = mode
60
+ self.mode = new_mode
61
+ begin
62
+ yield
63
+ ensure
64
+ self.mode = original_mode
65
65
  end
66
+ else
67
+ self.mode = new_mode
66
68
  end
67
69
  end
68
70
  end
69
- def self.disable!
70
- Funktor.configure_job_pusher do |config|
71
- config.job_pusher_middleware do |chain|
72
- chain.remove Funktor::FakeJobPusherMiddleware
71
+ end
72
+
73
+ module TestingPusher
74
+ def push(payload)
75
+ if Funktor::Testing.inline?
76
+ Funktor.job_pusher_middleware.invoke(payload) do
77
+ payload = payload.with_indifferent_access
78
+ worker = Object.const_get payload["worker"]
79
+ worker.new.perform(*payload["worker_params"])
73
80
  end
81
+ elsif Funktor::Testing.fake?
82
+ Funktor.job_pusher_middleware.invoke(payload) do
83
+ Funktor::FakeJobQueue.push(payload)
84
+ end
85
+ else
86
+ super
74
87
  end
75
88
  end
76
89
  end
77
90
 
78
- class InlineJobPusherMiddleware
79
- def call(payload)
80
- payload = payload.with_indifferent_access
81
- worker = Object.const_get payload["worker"]
82
- worker.new.perform(*payload["worker_params"])
83
- end
84
- end
91
+ Funktor::JobPusher.prepend TestingPusher
85
92
 
86
- class FakeJobPusherMiddleware
87
- def call(payload)
88
- Funktor::FakeJobQueue.push(payload)
89
- end
90
- end
91
93
  end
@@ -1,3 +1,3 @@
1
1
  module Funktor
2
- VERSION = "0.4.7"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -1,17 +1,18 @@
1
1
  require 'aws-sdk-sqs'
2
2
 
3
3
  module Funktor
4
- class ActiveJobHandler
4
+ class WorkQueueHandler
5
5
  include Funktor::ErrorHandler
6
6
 
7
7
  def initialize
8
8
  @failed_counter = Funktor::Counter.new('failed')
9
9
  @processed_counter = Funktor::Counter.new('processed')
10
+ @tracker = Funktor::ActivityTracker.new
10
11
  end
11
12
 
12
13
  def call(event:, context:)
13
14
  event = Funktor::Aws::Sqs::Event.new(event)
14
- puts "event.jobs.count = #{event.jobs.count}"
15
+ Funktor.logger.debug "event.jobs.count = #{event.jobs.count}"
15
16
  event.jobs.each do |job|
16
17
  dispatch(job)
17
18
  end
@@ -23,31 +24,32 @@ module Funktor
23
24
 
24
25
  def dispatch(job)
25
26
  begin
26
- Funktor.active_job_handler_middleware.invoke(job) do
27
+ @tracker.track(:processingStarted, job)
28
+ Funktor.work_queue_handler_middleware.invoke(job) do
27
29
  job.execute
28
30
  end
29
31
  @processed_counter.incr(job)
32
+ @tracker.track(:processingComplete, job)
30
33
  # rescue Funktor::Job::InvalidJsonError # TODO Make this work
31
34
  rescue Exception => e
32
35
  handle_error(e, job)
33
36
  @failed_counter.incr(job)
34
- attempt_retry_or_bail(job)
35
- end
36
- end
37
-
38
- def attempt_retry_or_bail(job)
39
- if job.can_retry
40
- trigger_retry(job)
41
- else
42
- puts "We retried max times. We're bailing on this one."
43
- puts job.to_json
37
+ if job.can_retry
38
+ @tracker.track(:retrying, job)
39
+ trigger_retry(job)
40
+ else
41
+ @tracker.track(:bailingOut, job)
42
+ Funktor.logger.error "We retried max times. We're bailing on this one."
43
+ Funktor.logger.error job.to_json
44
+ end
45
+ @tracker.track(:processingFailed, job)
44
46
  end
45
47
  end
46
48
 
47
49
  def trigger_retry(job)
48
50
  job.increment_retries
49
- puts "scheduling retry # #{job.retries} with delay of #{job.delay}"
50
- puts job.to_json
51
+ Funktor.logger.error "scheduling retry # #{job.retries} with delay of #{job.delay}"
52
+ Funktor.logger.error job.to_json
51
53
  sqs_client.send_message({
52
54
  queue_url: job.retry_queue_url,
53
55
  message_body: job.to_json
@@ -27,9 +27,6 @@ module Funktor::Worker
27
27
  end
28
28
 
29
29
  def perform_in(delay, *worker_params)
30
- if delay > max_delay
31
- raise Funktor::DelayTooLongError.new("The delay can't be longer than #{max_delay} seconds. This is a limitation of SQS. Funktor Pro has mechanisms to work around this limitation.")
32
- end
33
30
  self.push(delay, *worker_params)
34
31
  end
35
32
 
@@ -38,10 +35,6 @@ module Funktor::Worker
38
35
  Funktor.job_pusher.push(payload)
39
36
  end
40
37
 
41
- def max_delay
42
- 900
43
- end
44
-
45
38
  def build_job_payload(delay, *worker_params)
46
39
  {
47
40
  worker: self.name,
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.4.7
4
+ version: 0.5.0
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-08-03 00:00:00.000000000 Z
11
+ date: 2021-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-sqs
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.37'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-dynamodb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.62'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.62'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: activesupport
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -120,6 +134,7 @@ files:
120
134
  - ".github/workflows/ruby.yml"
121
135
  - ".gitignore"
122
136
  - ".rspec"
137
+ - ".tool-versions"
123
138
  - ".travis.yml"
124
139
  - CODE_OF_CONDUCT.md
125
140
  - Gemfile
@@ -131,10 +146,52 @@ files:
131
146
  - bin/setup
132
147
  - exe/funktor
133
148
  - exe/funktor-deploy
149
+ - funktor-testapp/.envrc
150
+ - funktor-testapp/.gitignore
151
+ - funktor-testapp/Gemfile
152
+ - funktor-testapp/Gemfile.lock
153
+ - funktor-testapp/app/services/job_flood.rb
154
+ - funktor-testapp/app/workers/audit_worker.rb
155
+ - funktor-testapp/app/workers/greetings_worker.rb
156
+ - funktor-testapp/app/workers/hello_worker.rb
157
+ - funktor-testapp/deploy-dev.sh
158
+ - funktor-testapp/funktor_config/boot.rb
159
+ - funktor-testapp/funktor_config/environment.yml
160
+ - funktor-testapp/funktor_config/function_definitions/default_queue_handler.yml
161
+ - funktor-testapp/funktor_config/function_definitions/incoming_job_handler.yml
162
+ - funktor-testapp/funktor_config/function_definitions/job_activator.yml
163
+ - funktor-testapp/funktor_config/function_definitions/random_job_generator.yml
164
+ - funktor-testapp/funktor_config/function_definitions/single_thread_queue_handler.yml
165
+ - funktor-testapp/funktor_config/funktor.yml
166
+ - funktor-testapp/funktor_config/iam_permissions/activity_table.yml
167
+ - funktor-testapp/funktor_config/iam_permissions/default_queue.yml
168
+ - funktor-testapp/funktor_config/iam_permissions/incoming_job_queue.yml
169
+ - funktor-testapp/funktor_config/iam_permissions/jobs_table.yml
170
+ - funktor-testapp/funktor_config/iam_permissions/jobs_table_secondary_index.yml
171
+ - funktor-testapp/funktor_config/iam_permissions/single_thread_queue.yml
172
+ - funktor-testapp/funktor_config/iam_permissions/ssm.yml
173
+ - funktor-testapp/funktor_config/package.yml
174
+ - funktor-testapp/funktor_config/resources/activity_table.yml
175
+ - funktor-testapp/funktor_config/resources/cloudwatch_dashboard.yml
176
+ - funktor-testapp/funktor_config/resources/default_queue.yml
177
+ - funktor-testapp/funktor_config/resources/incoming_job_queue.yml
178
+ - funktor-testapp/funktor_config/resources/incoming_job_queue_user.yml
179
+ - funktor-testapp/funktor_config/resources/jobs_table.yml
180
+ - funktor-testapp/funktor_config/resources/single_thread_queue.yml
181
+ - funktor-testapp/funktor_config/ruby_layer.yml
182
+ - funktor-testapp/funktor_init.yml
183
+ - funktor-testapp/lambda_event_handlers/default_queue_handler.rb
184
+ - funktor-testapp/lambda_event_handlers/incoming_job_handler.rb
185
+ - funktor-testapp/lambda_event_handlers/job_activator.rb
186
+ - funktor-testapp/lambda_event_handlers/random_job_generator.rb
187
+ - funktor-testapp/lambda_event_handlers/single_thread_queue_handler.rb
188
+ - funktor-testapp/package-lock.json
189
+ - funktor-testapp/package.json
190
+ - funktor-testapp/serverless.yml
134
191
  - funktor.gemspec
135
192
  - lib/active_job/queue_adapters/funktor_adapter.rb
136
193
  - lib/funktor.rb
137
- - lib/funktor/active_job_handler.rb
194
+ - lib/funktor/activity_tracker.rb
138
195
  - lib/funktor/aws/sqs/event.rb
139
196
  - lib/funktor/aws/sqs/record.rb
140
197
  - lib/funktor/cli/application.rb
@@ -148,20 +205,27 @@ files:
148
205
  - lib/funktor/cli/templates/funktor_config/boot.rb
149
206
  - lib/funktor/cli/templates/funktor_config/environment.yml
150
207
  - lib/funktor/cli/templates/funktor_config/function_definitions/incoming_job_handler.yml
208
+ - lib/funktor/cli/templates/funktor_config/function_definitions/job_activator.yml
151
209
  - lib/funktor/cli/templates/funktor_config/function_definitions/work_queue_handler.yml
152
210
  - lib/funktor/cli/templates/funktor_config/funktor.yml
211
+ - lib/funktor/cli/templates/funktor_config/iam_permissions/activity_table.yml
153
212
  - lib/funktor/cli/templates/funktor_config/iam_permissions/incoming_job_queue.yml
213
+ - lib/funktor/cli/templates/funktor_config/iam_permissions/jobs_table.yml
214
+ - lib/funktor/cli/templates/funktor_config/iam_permissions/jobs_table_secondary_index.yml
154
215
  - lib/funktor/cli/templates/funktor_config/iam_permissions/ssm.yml
155
216
  - lib/funktor/cli/templates/funktor_config/iam_permissions/work_queue.yml
156
217
  - lib/funktor/cli/templates/funktor_config/package.yml
218
+ - lib/funktor/cli/templates/funktor_config/resources/activity_table.yml
157
219
  - lib/funktor/cli/templates/funktor_config/resources/cloudwatch_dashboard.yml
158
220
  - lib/funktor/cli/templates/funktor_config/resources/incoming_job_queue.yml
159
221
  - lib/funktor/cli/templates/funktor_config/resources/incoming_job_queue_user.yml
222
+ - lib/funktor/cli/templates/funktor_config/resources/jobs_table.yml
160
223
  - lib/funktor/cli/templates/funktor_config/resources/work_queue.yml
161
224
  - lib/funktor/cli/templates/funktor_config/ruby_layer.yml
162
225
  - lib/funktor/cli/templates/funktor_init.yml.tt
163
226
  - lib/funktor/cli/templates/gitignore
164
227
  - lib/funktor/cli/templates/lambda_event_handlers/incoming_job_handler.rb
228
+ - lib/funktor/cli/templates/lambda_event_handlers/job_activator.rb
165
229
  - lib/funktor/cli/templates/lambda_event_handlers/work_queue_handler.rb
166
230
  - lib/funktor/cli/templates/package.json
167
231
  - lib/funktor/cli/templates/serverless.yml
@@ -170,6 +234,7 @@ files:
170
234
  - lib/funktor/fake_job_queue.rb
171
235
  - lib/funktor/incoming_job_handler.rb
172
236
  - lib/funktor/job.rb
237
+ - lib/funktor/job_activator.rb
173
238
  - lib/funktor/job_pusher.rb
174
239
  - lib/funktor/logger.rb
175
240
  - lib/funktor/middleware/metrics.rb
@@ -177,6 +242,7 @@ files:
177
242
  - lib/funktor/rails.rb
178
243
  - lib/funktor/testing.rb
179
244
  - lib/funktor/version.rb
245
+ - lib/funktor/work_queue_handler.rb
180
246
  - lib/funktor/worker.rb
181
247
  - lib/funktor/worker/funktor_options.rb
182
248
  homepage: https://github.com/Octo-Labs/funktor