funktor 0.2.8 → 0.2.13

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: ed00bb1e70f943b1b4193e681fdde83c41fd0bd84bae056d4b171689f2dbe5c8
4
- data.tar.gz: 57c02b8d42a470f0f52b90d60fff3c4b176523a7c606a7f7c562649dddbdfe4e
3
+ metadata.gz: ea0e753064ccb434aa89a656425dbe94ce223e8fcce85e7ad3423bc3d082ba31
4
+ data.tar.gz: 02ff46a0ca5276400dacce0e239bdacc48142624f5bbd36311267bc04964aa78
5
5
  SHA512:
6
- metadata.gz: 3575e30e6ae1dea0d36f4b31dcc06ec06b2e92ac07342f79cafc5cc99da9f66d22df79091643e4b036a24f22dab01747adb485806e4e3bae42be3441250f1839
7
- data.tar.gz: f2a1827d30175051202691e9ab062929cbf73ba6b32b2bf8081259696fcb29d386822e94cfd4706993864581f294ded37918f45d23ab0cf986d5f21ada0c7f2c
6
+ metadata.gz: 98d58ca33de1fe46d1121ce3498522fc1de8316b71fdd978780ab9ffbd2f97085bf47cef9ff59809648b36e9b4abea96cd89b785df1403c64a587ecec70bcb92
7
+ data.tar.gz: e6db57253fd756583344d4424fac291cb6126f90838b30761febb0142d32959a5cdec3ee82b92c9ecb5dc9ce2a25c94db9152c4a64ed87a8e0b566024e54c650
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- funktor (0.2.8)
4
+ funktor (0.2.13)
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
 
@@ -1,3 +1,4 @@
1
+ FUNKTOR_APP_NAME: <%= app_name %>
1
2
  FUNKTOR_INCOMING_JOB_QUEUE:
2
3
  Ref: IncomingJobQueue
3
4
  <%- queue_names.each do |queue_name| -%>
@@ -1,4 +1,7 @@
1
- require_relative '../config/boot'
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'
2
5
 
3
6
  $handler = Funktor::IncomingJobHandler.new
4
7
 
@@ -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
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)
@@ -43,7 +47,7 @@ module Funktor
43
47
  end
44
48
 
45
49
  def execute
46
- worker_class.new.perform(worker_params)
50
+ worker_class.new.perform(*worker_params)
47
51
  end
48
52
 
49
53
  def worker_class
@@ -19,7 +19,7 @@ module Funktor
19
19
  "Timestamp": Time.now.strftime('%s%3N').to_i,
20
20
  "CloudWatchMetrics": [
21
21
  {
22
- "Namespace": "rails-lambda-experiment", # TODO - We should get this from config or someting
22
+ "Namespace": ENV['FUNKTOR_APP_NAME'],
23
23
  "Dimensions": [["WorkerClassName"]],
24
24
  "Metrics": [ # CPU, Memory, Duration, etc...
25
25
  {
@@ -57,7 +57,7 @@ module Funktor
57
57
 
58
58
  class InlineJobPusherMiddleware
59
59
  def call(worker, payload)
60
- worker.new.perform(payload[:worker_params])
60
+ worker.new.perform(*payload[:worker_params])
61
61
  end
62
62
  end
63
63
 
@@ -1,3 +1,3 @@
1
1
  module Funktor
2
- VERSION = "0.2.8"
2
+ VERSION = "0.2.13"
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.8
4
+ version: 0.2.13
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-29 00:00:00.000000000 Z
11
+ date: 2021-06-30 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