funktor 0.2.10 → 0.2.15

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: 16ad166a922c31ac7de1008d48fe34824203b0d325e7faae2f7ede140fc0f836
4
- data.tar.gz: fafbd5ca0858ecb87c2c9e87c8efa52accc9262f922d6f3f1d4b311b3c8c470b
3
+ metadata.gz: a1b4182ab20dd1edaab9d00d00f454d25a1e0333502b2c20fca839902692f6ba
4
+ data.tar.gz: dc5d7f97ddda5d20292db6520d7023c185cf5f117a548b8c40d3dcaf96608061
5
5
  SHA512:
6
- metadata.gz: b40e4deee38ed584b93c863150d2d6c45dfc3aea1ac3ed0d7aa4d249c5661b527f252cf1b700545f54e80f98bf6158345c01b218f175eef117ce31626c5f5b21
7
- data.tar.gz: 240839bae2964df499664ec8c21a44d3c8c4cf46d3d6df5cb798af95ba3b454deee6a41d5b4b0a3d71fc8c04e36bdfdb0d787f6168e71ef1cb516370e1c0d369
6
+ metadata.gz: 0ae29280dd7ed160ac7f228a5ca0fdde92634e8bcd63179ffcacd49107b680a2d72f3067878d277c7146d72ccc0d2321575e7bc46acf9925a717ab32973772f6
7
+ data.tar.gz: 562723cc07a29e5a3036610423bbc54ad4ed00ede8ec47462319750924802b3c8bd37c9a0ea3235b455db9864a08dd628ef592fe6c72f10727ef7675468527a4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- funktor (0.2.10)
4
+ funktor (0.2.15)
5
5
  activesupport
6
6
  aws-sdk-sqs (~> 1.37)
7
7
  thor
data/lib/funktor.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "funktor/version"
2
2
  require 'funktor/aws/sqs/event'
3
3
  require 'funktor/aws/sqs/record'
4
+ require 'funktor/counter'
4
5
  require 'funktor/job'
5
6
  require 'funktor/worker'
6
7
  require 'funktor/middleware_chain'
@@ -3,6 +3,11 @@ require 'aws-sdk-sqs'
3
3
  module Funktor
4
4
  class ActiveJobHandler
5
5
 
6
+ def initialize
7
+ @failed_counter = Funktor::Counter.new('failed')
8
+ @processed_counter = Funktor::Counter.new('processed')
9
+ end
10
+
6
11
  def call(event:, context:)
7
12
  event = Funktor::Aws::Sqs::Event.new(event)
8
13
  puts "event.jobs.count = #{event.jobs.count}"
@@ -20,10 +25,12 @@ module Funktor
20
25
  Funktor.active_job_handler_middleware.invoke(job) do
21
26
  job.execute
22
27
  end
28
+ @processed_counter.incr(job)
23
29
  # rescue Funktor::Job::InvalidJsonError # TODO Make this work
24
30
  rescue Exception => e
25
31
  puts "Error during processing: #{$!}"
26
32
  puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}"
33
+ @failed_counter.incr(job)
27
34
  attempt_retry_or_bail(job)
28
35
  end
29
36
  end
@@ -43,8 +50,7 @@ module Funktor
43
50
  puts job.to_json
44
51
  sqs_client.send_message({
45
52
  queue_url: job.retry_queue_url,
46
- message_body: job.to_json,
47
- delay_seconds: job.delay
53
+ message_body: job.to_json
48
54
  })
49
55
  end
50
56
 
@@ -321,6 +321,29 @@ Resources:
321
321
  "title": "Job Duration by Worker"
322
322
  }
323
323
  },
324
+
325
+ <% current_y += 6 %>
326
+ { <% "Processed/Failed Jobs By Worker" %>
327
+ "height": 6,
328
+ "width": 24,
329
+ "y": <%= current_y %>,
330
+ "x": 0,
331
+ "type": "metric",
332
+ "properties": {
333
+ "metrics": [
334
+ <%- app_worker_names.each do |worker_name| -%>
335
+ [ "<%= app_name %>", "processed", "WorkerClassName", "<%= worker_name %>" ],
336
+ [ ".", "failed", ".", "." ]<%= worker_name == app_worker_names.last ? "" : "," %>
337
+ <%- end -%>
338
+ ],
339
+ "view": "timeSeries",
340
+ "stacked": false,
341
+ "region": "us-east-1",
342
+ "title": "Process/Failed Jobs By Worker",
343
+ "period": 60,
344
+ "stat": "Sum"
345
+ }
346
+ },
324
347
  <% current_y += 6 %>
325
348
 
326
349
  { <% "Delayed Jobs" %>
@@ -551,5 +574,8 @@ Resources:
551
574
  }
552
575
  }
553
576
 
577
+
578
+
579
+
554
580
  ]
555
581
  }
@@ -0,0 +1,43 @@
1
+ module Funktor
2
+ class Counter
3
+ attr_accessor :dimension
4
+
5
+ def initialize(dimension)
6
+ @dimension = dimension
7
+ end
8
+
9
+ def incr(job)
10
+ put_metric_to_stdout(job)
11
+ end
12
+
13
+ def put_metric_to_stdout(job)
14
+ puts Funktor.dump_json(metric_hash(job))
15
+ end
16
+
17
+ def metric_hash(job)
18
+ {
19
+ "_aws": {
20
+ "Timestamp": Time.now.strftime('%s%3N').to_i,
21
+ "CloudWatchMetrics": [
22
+ {
23
+ "Namespace": ENV['FUNKTOR_APP_NAME'],
24
+ "Dimensions": [["WorkerClassName", "Queue"]],
25
+ "Metrics": [ # CPU, Memory, Duration, etc...
26
+ {
27
+ "Name": dimension,
28
+ "Unit": "Count"
29
+ }
30
+ ]
31
+ }
32
+ ]
33
+ },
34
+ "WorkerClassName": job.worker_class_name,
35
+ "Queue": job.queue,
36
+ "#{dimension}": 1
37
+ #"count": value,
38
+ #"requestId": "989ffbf8-9ace-4817-a57c-e4dd734019ee"
39
+ }
40
+ #data[key] = value
41
+ end
42
+ end
43
+ end
data/lib/funktor/job.rb CHANGED
@@ -35,7 +35,11 @@ module Funktor
35
35
  end
36
36
 
37
37
  def delay
38
- job_data["delay"]
38
+ # TODO - In Funktor Pro we need to override this method (or do something else) so that
39
+ # we can schedule jobs farther in the future than 15 minutes. We do this here in case a
40
+ # retry sequence goes too long.
41
+ jdelay = job_data["delay"]
42
+ return jdelay < 900 ? jdelay : 900
39
43
  end
40
44
 
41
45
  def delay=(delay)
@@ -20,7 +20,7 @@ module Funktor
20
20
  "CloudWatchMetrics": [
21
21
  {
22
22
  "Namespace": ENV['FUNKTOR_APP_NAME'],
23
- "Dimensions": [["WorkerClassName"]],
23
+ "Dimensions": [["WorkerClassName", "Queue"]],
24
24
  "Metrics": [ # CPU, Memory, Duration, etc...
25
25
  {
26
26
  "Name": "Duration",
@@ -31,6 +31,7 @@ module Funktor
31
31
  ]
32
32
  },
33
33
  "WorkerClassName": job.worker_class_name,
34
+ "Queue": job.queue,
34
35
  "Duration": time_diff_in_seconds * 1_000
35
36
  #"count": value,
36
37
  #"requestId": "989ffbf8-9ace-4817-a57c-e4dd734019ee"
@@ -1,3 +1,3 @@
1
1
  module Funktor
2
- VERSION = "0.2.10"
2
+ VERSION = "0.2.15"
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.10
4
+ version: 0.2.15
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-06-30 00:00:00.000000000 Z
11
+ date: 2021-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-sqs
@@ -136,6 +136,7 @@ files:
136
136
  - lib/funktor/cli/templates/lambda_event_handlers/work_queue_handler.rb
137
137
  - lib/funktor/cli/templates/package.json
138
138
  - lib/funktor/cli/templates/serverless.yml
139
+ - lib/funktor/counter.rb
139
140
  - lib/funktor/fake_job_queue.rb
140
141
  - lib/funktor/incoming_job_handler.rb
141
142
  - lib/funktor/job.rb