funktor 0.2.9 → 0.2.14
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/resources/cloudwatch_dashboard.yml +26 -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: 78d588a9932c62a7d4cb3d4e86adacf7f0eb99ac422447e54c5ce336fe77f6f2
|
4
|
+
data.tar.gz: 1a4ef97fdbab5d9d38600e4a247141ffba81fe82ba3fda42de0d024dbcfc180d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dda1f909c912b01bd469b4b13398546abc9482ab3d60e6ec275f2002ba5161fa580e123d68732fd19bd148aaf97cfbd42112dc72c416fb745b9bfc14fab555dc
|
7
|
+
data.tar.gz: acccfa11ddd50cde6b372bdeecfc34ce9fe0d0d0294cd5e99d905d6456373979ef9f03c67ed38ce3e54b2acdd6ebf8b6ecaa2d678d40c37ecfe6f153ca36d757
|
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
|
|
@@ -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
|
}
|
@@ -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": ENV['FUNKTOR_APP_NAME'],
|
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.14
|
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-
|
11
|
+
date: 2021-07-01 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
|