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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/funktor.rb +1 -0
- data/lib/funktor/active_job_handler.rb +8 -2
- data/lib/funktor/cli/templates/config/environment.yml +1 -0
- data/lib/funktor/cli/templates/lambda_event_handlers/incoming_job_handler.rb +4 -1
- data/lib/funktor/counter.rb +42 -0
- data/lib/funktor/job.rb +6 -2
- data/lib/funktor/middleware/metrics.rb +1 -1
- data/lib/funktor/testing.rb +1 -1
- data/lib/funktor/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea0e753064ccb434aa89a656425dbe94ce223e8fcce85e7ad3423bc3d082ba31
|
4
|
+
data.tar.gz: 02ff46a0ca5276400dacce0e239bdacc48142624f5bbd36311267bc04964aa78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98d58ca33de1fe46d1121ce3498522fc1de8316b71fdd978780ab9ffbd2f97085bf47cef9ff59809648b36e9b4abea96cd89b785df1403c64a587ecec70bcb92
|
7
|
+
data.tar.gz: e6db57253fd756583344d4424fac291cb6126f90838b30761febb0142d32959a5cdec3ee82b92c9ecb5dc9ce2a25c94db9152c4a64ed87a8e0b566024e54c650
|
data/Gemfile.lock
CHANGED
data/lib/funktor.rb
CHANGED
@@ -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,4 +1,7 @@
|
|
1
|
-
|
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
|
-
|
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":
|
22
|
+
"Namespace": ENV['FUNKTOR_APP_NAME'],
|
23
23
|
"Dimensions": [["WorkerClassName"]],
|
24
24
|
"Metrics": [ # CPU, Memory, Duration, etc...
|
25
25
|
{
|
data/lib/funktor/testing.rb
CHANGED
data/lib/funktor/version.rb
CHANGED
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.
|
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-
|
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
|