funktor 0.2.10 → 0.2.11

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: 99102148cae3682c1c870882cd44b9651869e3d1ec3adb7e3b4145ef7a6becf5
4
+ data.tar.gz: c6adb462dbe095673a72e81570d293a59a7f75d18376178684cabe5c81342f3c
5
5
  SHA512:
6
- metadata.gz: b40e4deee38ed584b93c863150d2d6c45dfc3aea1ac3ed0d7aa4d249c5661b527f252cf1b700545f54e80f98bf6158345c01b218f175eef117ce31626c5f5b21
7
- data.tar.gz: 240839bae2964df499664ec8c21a44d3c8c4cf46d3d6df5cb798af95ba3b454deee6a41d5b4b0a3d71fc8c04e36bdfdb0d787f6168e71ef1cb516370e1c0d369
6
+ metadata.gz: 501e7dd2f92ff36d492da512861bf4dd6ab56f07a4fcbc6c362fa5249a52f0e2694b835d6eda1b454304046be2315c8a9a253c92a25e8548605a7dc4829008ac
7
+ data.tar.gz: fa98731784d2b0007b9bf831b2536f9ec93bbb5a8870e7f5b9e8810b414002d1f760000d18fa581b7e6f8016f48e9dbca1d905bf1d2821dbfaf85cdec80158dc
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.11)
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
@@ -0,0 +1,42 @@
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"]],
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
+ "#{dimension}": 1
36
+ #"count": value,
37
+ #"requestId": "989ffbf8-9ace-4817-a57c-e4dd734019ee"
38
+ }
39
+ #data[key] = value
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module Funktor
2
- VERSION = "0.2.10"
2
+ VERSION = "0.2.11"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Green
@@ -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