funktor 0.7.5 → 0.7.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +3 -3
  3. data/funktor-testapp/Dockerfile +63 -0
  4. data/funktor-testapp/app/services/job_flood.rb +1 -1
  5. data/funktor-testapp/funktor_config/boot.rb +3 -0
  6. data/funktor-testapp/funktor_config/environment.yml +10 -1
  7. data/funktor-testapp/funktor_config/function_definitions/default_queue_handler.yml +5 -1
  8. data/funktor-testapp/funktor_config/function_definitions/incoming_job_handler.yml +5 -1
  9. data/funktor-testapp/funktor_config/function_definitions/job_activator.yml +5 -1
  10. data/funktor-testapp/funktor_config/function_definitions/low_concurrency_queue_handler.yml +5 -1
  11. data/funktor-testapp/funktor_config/package.yml +6 -6
  12. data/funktor-testapp/funktor_config/resources/cloudwatch_dashboard.yml +645 -37
  13. data/funktor-testapp/funktor_config/ruby_layer.yml +1 -1
  14. data/funktor-testapp/serverless.yml +13 -3
  15. data/lib/funktor/activity_tracker.rb +1 -2
  16. data/lib/funktor/cli/init.rb +4 -0
  17. data/lib/funktor/cli/templates/Dockerfile +63 -0
  18. data/lib/funktor/cli/templates/funktor_config/environment.yml +10 -1
  19. data/lib/funktor/cli/templates/funktor_config/function_definitions/incoming_job_handler.yml +5 -1
  20. data/lib/funktor/cli/templates/funktor_config/function_definitions/job_activator.yml +5 -1
  21. data/lib/funktor/cli/templates/funktor_config/function_definitions/work_queue_handler.yml +5 -1
  22. data/lib/funktor/cli/templates/funktor_config/package.yml +6 -6
  23. data/lib/funktor/cli/templates/funktor_config/resources/cloudwatch_dashboard.yml +161 -0
  24. data/lib/funktor/cli/templates/funktor_config/ruby_layer.yml +1 -1
  25. data/lib/funktor/cli/templates/serverless.yml +13 -3
  26. data/lib/funktor/incoming_job_handler.rb +9 -7
  27. data/lib/funktor/job_activator.rb +33 -17
  28. data/lib/funktor/job_pusher.rb +1 -1
  29. data/lib/funktor/version.rb +1 -1
  30. data/lib/funktor/web/application.rb +1 -1
  31. data/lib/funktor/work_queue_handler.rb +21 -6
  32. data/lib/funktor.rb +20 -1
  33. metadata +4 -2
@@ -20,23 +20,28 @@ module Funktor
20
20
  end
21
21
 
22
22
  def dynamodb_client
23
- @dynamodb_client ||= ::Aws::DynamoDB::Client.new
23
+ Funktor.dynamodb_client
24
24
  end
25
25
 
26
26
  def sqs_client
27
- @sqs_client ||= ::Aws::SQS::Client.new
27
+ Funktor.sqs_client
28
28
  end
29
29
 
30
30
  def dispatch(job)
31
31
  begin
32
32
  @tracker.track(:processingStarted, job)
33
- update_job_category(job, "processing")
33
+ if Funktor.enable_work_queue_visibility
34
+ update_job_category(job, "processing")
35
+ end
34
36
  Funktor.work_queue_handler_middleware.invoke(job) do
35
37
  job.execute
36
38
  end
37
39
  @processed_counter.incr(job)
38
40
  @tracker.track(:processingComplete, job)
39
- delete_job_from_dynamodb(job)
41
+
42
+ if Funktor.enable_work_queue_visibility
43
+ delete_job_from_dynamodb(job)
44
+ end
40
45
  # rescue Funktor::Job::InvalidJsonError # TODO Make this work
41
46
  rescue Exception => e
42
47
  handle_error(e, job)
@@ -44,11 +49,17 @@ module Funktor
44
49
  job.error = e
45
50
  if job.can_retry
46
51
  @tracker.track(:retrying, job)
47
- update_job_category(job, "retry")
52
+
53
+ if Funktor.enable_work_queue_visibility
54
+ update_job_category(job, "retry")
55
+ end
48
56
  trigger_retry(job)
49
57
  else
50
58
  @tracker.track(:bailingOut, job)
51
- update_job_category(job, "dead")
59
+
60
+ if Funktor.enable_work_queue_visibility
61
+ update_job_category(job, "dead")
62
+ end
52
63
  Funktor.logger.error "We retried max times. We're bailing on this one."
53
64
  Funktor.logger.error job.to_json
54
65
  end
@@ -71,6 +82,7 @@ module Funktor
71
82
  end
72
83
 
73
84
  def update_job_category(job, category)
85
+ puts "starting update_job_category #{category}"
74
86
  dynamodb_client.update_item({
75
87
  key: {
76
88
  "jobShard" => job.shard,
@@ -84,9 +96,11 @@ module Funktor
84
96
  },
85
97
  return_values: "ALL_OLD"
86
98
  })
99
+ puts "ending update_job_category #{category}"
87
100
  end
88
101
 
89
102
  def delete_job_from_dynamodb(job)
103
+ puts "starting delete_job_from_dynamodb"
90
104
  dynamodb_client.delete_item({
91
105
  key: {
92
106
  "jobShard" => job.shard,
@@ -95,6 +109,7 @@ module Funktor
95
109
  table_name: delayed_job_table,
96
110
  return_values: "ALL_OLD"
97
111
  })
112
+ puts "ending delete_job_from_dynamodb"
98
113
  end
99
114
 
100
115
  end
data/lib/funktor.rb CHANGED
@@ -12,13 +12,16 @@ require_relative 'funktor/job_activator'
12
12
  require_relative 'funktor/activity_tracker'
13
13
 
14
14
  require 'json'
15
+ require 'aws-sdk-dynamodb'
16
+ require 'aws-sdk-sqs'
15
17
 
16
18
  module Funktor
17
19
  class Error < StandardError; end
18
20
 
19
21
  DEFAULT_OPTIONS = {
20
22
  error_handlers: [],
21
- log_level: Logger::DEBUG # Set a high log level during early, active development
23
+ log_level: Logger::DEBUG, # Set a high log level during early, active development
24
+ enable_work_queue_visibility: true # Enable this by default during early, active development
22
25
  }
23
26
 
24
27
  def self.configure_job_pusher
@@ -110,6 +113,14 @@ module Funktor
110
113
  @logger = logger
111
114
  end
112
115
 
116
+ def self.enable_work_queue_visibility
117
+ options[:enable_work_queue_visibility]
118
+ end
119
+
120
+ def self.enable_work_queue_visibility= enabled
121
+ options[:enable_work_queue_visibility] = enabled
122
+ end
123
+
113
124
  # We have a raw_logger that doesn't add timestamps and what not. This is used to publish
114
125
  # CloudWatch metrics that can be used in dashboards.
115
126
  def self.raw_logger
@@ -126,6 +137,14 @@ module Funktor
126
137
 
127
138
  @raw_logger = raw_logger
128
139
  end
140
+
141
+ def self.dynamodb_client
142
+ @dynamodb_client ||= ::Aws::DynamoDB::Client.new
143
+ end
144
+
145
+ def self.sqs_client
146
+ @sqs_client ||= ::Aws::SQS::Client.new
147
+ end
129
148
  end
130
149
 
131
150
  # TODO - Is it a code smell that we need to include these at the bottom, after
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.5
4
+ version: 0.7.8
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-05-04 00:00:00.000000000 Z
11
+ date: 2022-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-sqs
@@ -176,6 +176,7 @@ files:
176
176
  - exe/funktor-deploy
177
177
  - funktor-testapp/.envrc
178
178
  - funktor-testapp/.gitignore
179
+ - funktor-testapp/Dockerfile
179
180
  - funktor-testapp/Gemfile
180
181
  - funktor-testapp/Gemfile.lock
181
182
  - funktor-testapp/app/services/job_flood.rb
@@ -227,6 +228,7 @@ files:
227
228
  - lib/funktor/cli/generate/base.rb
228
229
  - lib/funktor/cli/generate/work_queue.rb
229
230
  - lib/funktor/cli/init.rb
231
+ - lib/funktor/cli/templates/Dockerfile
230
232
  - lib/funktor/cli/templates/Gemfile
231
233
  - lib/funktor/cli/templates/app/workers/hello_worker.rb
232
234
  - lib/funktor/cli/templates/funktor_config/boot.rb