funktor 0.2.6 → 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: 3a92d7870ba1cde9f91c5d872aab7e5dcc9d7a0d9ee8b4deb75fa1e679ea6ddc
4
- data.tar.gz: 79d938d9d46f9763ae6bf7001bf54bb1ad48eefee0a0b5dcbb624a934edbba85
3
+ metadata.gz: 99102148cae3682c1c870882cd44b9651869e3d1ec3adb7e3b4145ef7a6becf5
4
+ data.tar.gz: c6adb462dbe095673a72e81570d293a59a7f75d18376178684cabe5c81342f3c
5
5
  SHA512:
6
- metadata.gz: b741a360102285bc392c6b846677b1859dbb02652b9e9412773fa989172c4a2368429f7825736f4438a543f4ac058098884fd78ce8a8f89be81b10f6b2e4db94
7
- data.tar.gz: a450bec63e833671d3eeb7e4e1f00c38eec6c66c59de610ba431f8660a1273dac0ab4db85ff7b41ca2ff9e234c19f771087127d16ab2a21612b731ed61678609
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.6)
4
+ funktor (0.2.11)
5
5
  activesupport
6
6
  aws-sdk-sqs (~> 1.37)
7
7
  thor
@@ -18,7 +18,7 @@ GEM
18
18
  addressable (2.7.0)
19
19
  public_suffix (>= 2.0.2, < 5.0)
20
20
  aws-eventstream (1.1.1)
21
- aws-partitions (1.471.0)
21
+ aws-partitions (1.472.0)
22
22
  aws-sdk-core (3.115.0)
23
23
  aws-eventstream (~> 1, >= 1.0.2)
24
24
  aws-partitions (~> 1, >= 1.239.0)
data/README.md CHANGED
@@ -34,41 +34,20 @@ npm install -g serverless
34
34
 
35
35
  Then you can initialize a new app by doing:
36
36
 
37
-
38
37
  ```bash
38
+ funktor bootstrap my-funktor-app
39
+ cd my-funktor-app
39
40
  funktor init
40
41
  ```
41
42
 
43
+ Then you sh
44
+
42
45
  This will create a `funktor` directory that is ready to deploy to AWS. If you've already configured
43
46
  your aws tools via `~/.aws/credentials` you should be ready to deploy.
44
47
 
45
- `funktor/serverless.yml` is the main file that ties everything together.
46
-
47
- `funktor/config` contains a few files that you can use to configure your `funktor` application.
48
-
49
- `funktor/resources` contains a few files that provision some AWS resources that are used by `funktor`.
50
- * An SQS Queue for the "incoming jobs queue"
51
- * A Dynamo DB table to allow queueing of jobs more than 15 minutes in the future (Funktor Pro)
52
- * One or more SQS Queues for active jobs (currently there is only the default queue, support for additional queues is coming soon)
53
- * An IAM User with permission to push jobs to the incoming jobs queue
54
- * A CloudWatch dashboard to let you keep tabs on your application
55
-
56
- `funktor/lambda_handlers` contains some scripts that receive events from Lambda, then invoke `funktor` to
57
- do various things:
58
- * `active_job_handler.rb` executes your jobs
59
- * `delayed_job_scheduler.rb` (Funktor Pro) pulls delayed jobs out of DynamoDB and places them on the active job queue.
60
- * `incoming_job_handler.rb` receives incoming jobs and pushes them to DynamoDB for delayed execution or to the active job queue as appropriate.
61
-
62
- `funktor/function_definitions` contains details about hooking up the `lambda_handlers` to events.
63
-
64
- `funktor/iam_permissions` contains some details about giving your lambda functions the appropriate permissions
65
- to interact with SQS.
66
-
67
- `funktor/workers` is where your workers will live.
68
-
69
- `funktor/Gemfile` is the `Gemfile` that contains the gems that are needed for your workers to execute
70
- jobs. This should be the minimal set of gems you can get away with so that cold start times remain reasonable.
71
- This file will already contain `funktor`. (Don't remove it or `funktor` won't work!)
48
+ See the [wiki](https://github.com/Octo-Labs/funktor/wiki)
49
+ for more info, especially the
50
+ [section about getting started in a stand alone project](https://github.com/Octo-Labs/funktor/wiki/Getting-started-in-a-stand-alone-project).
72
51
 
73
52
  ## Deploying
74
53
 
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
@@ -171,7 +171,6 @@ module Funktor
171
171
  end
172
172
 
173
173
  def queue_config_value(queue_name, config_name)
174
- puts funktor_config
175
174
  queue_config(queue_name)&.dig(config_name) ||
176
175
  funktor_config.dig("handlerDefaults", config_name) ||
177
176
  "null" # When we parse yaml 'null' gets turned to nil, which comes out as an empty string in the template
@@ -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,8 +1,8 @@
1
1
  handler: lambda_event_handlers/incoming_job_handler.call
2
- timeout: ${self:custom.funktor.incomingJobHandler.timeout, 30}
3
- reservedConcurrency: ${self:custom.funktor.incomingJobHandler.reservedConcurrency, null}
4
- provisionedConcurrency: ${self:custom.funktor.incomingJobHandler.provisionedConcurrency, null}
5
- memorySize: ${self:custom.funktor.incomingJobHandler.memorySize, 256}
2
+ timeout: ${self:custom.funktor.IncomingJobHandler.timeout, 30}
3
+ reservedConcurrency: ${self:custom.funktor.IncomingJobHandler.reservedConcurrency, null}
4
+ provisionedConcurrency: ${self:custom.funktor.IncomingJobHandler.provisionedConcurrency, null}
5
+ memorySize: ${self:custom.funktor.IncomingJobHandler.memorySize, 256}
6
6
  events:
7
7
  - sqs:
8
8
  arn:
@@ -1,4 +1,4 @@
1
- incomingJobHandler:
1
+ IncomingJobHandler:
2
2
  # timeout is how long the handler can possibly run. Up to 10 messages may be delivered
3
3
  # to a handler at one time, so you'll want this to be at least 10x the maximum time you
4
4
  # expect to spend for one message. The incoming job handler usually will be pretty fast,
@@ -51,10 +51,11 @@ incomingJobHandler:
51
51
 
52
52
  # You shouldn't need to mess with these under most circumstances. But you could if you want to change
53
53
  # the name of some of your resources in AWS.
54
- incomingJobQueueName: ${self:service}-${self:custom.stage}-incoming-jobs
55
- incomingDeadJobQueueName: ${self:service}-${self:custom.stage}-incoming-dead
56
- incomingJobQueueAccessPolicyName: ${self:service}-${self:custom.stage}-incoming-job-queue-access
57
- dashboardName: ${self:service}-${self:custom.stage}-dashboard
54
+ IncomingJobQueueName: ${self:service}-${self:custom.stage}-incoming-jobs
55
+ IncomingDeadJobQueueName: ${self:service}-${self:custom.stage}-incoming-dead
56
+ IncomingJobHandlerName: ${self:service}-${self:custom.stage}-IncomingJobHandler
57
+ IncomingJobQueueAccessPolicyName: ${self:service}-${self:custom.stage}-incoming-job-queue-access
58
+ DashboardName: ${self:service}-${self:custom.stage}-dashboard
58
59
  <%- queue_names.each do |queue_name| -%>
59
60
  <%= queue_name.camelize %>QueueName: ${self:service}-${self:custom.stage}-<%= queue_name.underscore.dasherize %>
60
61
  <%= queue_name.camelize %>DeadJobQueueName: ${self:service}-${self:custom.stage}-<%= queue_name.underscore.dasherize %>-dead
@@ -2,7 +2,7 @@ Resources:
2
2
  FunktorDashboard:
3
3
  Type: AWS::CloudWatch::Dashboard
4
4
  Properties:
5
- DashboardName: ${self:custom.funktor.dashboardName}
5
+ DashboardName: ${self:custom.funktor.DashboardName}
6
6
  DashboardBody: >
7
7
  {
8
8
  "widgets": [
@@ -25,7 +25,7 @@ Resources:
25
25
  "type": "metric",
26
26
  "properties": {
27
27
  "metrics": [
28
- [ "AWS/SQS", "NumberOfMessagesReceived", "QueueName", "${self:custom.funktor.incomingJobQueueName}", { "label": "Messages Per Minute" } ]
28
+ [ "AWS/SQS", "NumberOfMessagesReceived", "QueueName", "${self:custom.funktor.IncomingJobQueueName}", { "label": "Messages Per Minute" } ]
29
29
  ],
30
30
  "view": "singleValue",
31
31
  "region": "us-east-1",
@@ -42,7 +42,7 @@ Resources:
42
42
  "type": "metric",
43
43
  "properties": {
44
44
  "metrics": [
45
- [ "AWS/Lambda", "Duration", "FunctionName", "${self:service}-${self:provider.stage}-incoming_job_handler", "Resource", "${self:service}-${self:provider.stage}-incoming_job_handler", { "label": "p10" } ],
45
+ [ "AWS/Lambda", "Duration", "FunctionName", "${self:custom.funktor.IncomingJobHandlerName}", "Resource", "${self:custom.funktor.IncomingJobHandlerName}", { "label": "p10" } ],
46
46
  [ "...", { "label": "p50", "stat": "p50" } ],
47
47
  [ "...", { "label": "p99", "stat": "p99" } ],
48
48
  [ "...", { "label": "Average", "stat": "Average" } ]
@@ -63,10 +63,10 @@ Resources:
63
63
  "type": "metric",
64
64
  "properties": {
65
65
  "metrics": [
66
- [ "AWS/SQS", "NumberOfMessagesReceived", "QueueName", "${self:custom.funktor.incomingJobQueueName}", { "label": "Received" } ],
66
+ [ "AWS/SQS", "NumberOfMessagesReceived", "QueueName", "${self:custom.funktor.IncomingJobQueueName}", { "label": "Received" } ],
67
67
  [ ".", "NumberOfMessagesDeleted", ".", ".", { "label": "Handled" } ],
68
- [ "AWS/Lambda", "Invocations", "FunctionName", "${self:service}-${self:provider.stage}-incoming_job_handler", "Resource", "${self:service}-${self:provider.stage}-incoming_job_handler", { "label": "Handler Invocations" } ],
69
- [ "AWS/SQS", "ApproximateNumberOfMessagesVisible", "QueueName", "${self:custom.funktor.incomingJobQueueName}", { "label": "Pending?" } ],
68
+ [ "AWS/Lambda", "Invocations", "FunctionName", "${self:custom.funktor.IncomingJobHandlerName}", "Resource", "${self:custom.funktor.IncomingJobHandlerName}", { "label": "Handler Invocations" } ],
69
+ [ "AWS/SQS", "ApproximateNumberOfMessagesVisible", "QueueName", "${self:custom.funktor.IncomingJobQueueName}", { "label": "Pending?" } ],
70
70
  [ ".", "ApproximateNumberOfMessagesNotVisible", ".", ".", { "label": "Backlog?" } ],
71
71
  [ ".", "NumberOfMessagesSent", ".", ".", { "label": "Sent" } ],
72
72
  [ ".", "ApproximateNumberOfMessagesDelayed", ".", ".", { "label": "Delayed" } ]
@@ -90,7 +90,7 @@ Resources:
90
90
  "properties": {
91
91
  "period": 60,
92
92
  "metrics": [
93
- [ "AWS/Lambda", "Duration", "FunctionName", "${self:service}-${self:provider.stage}-incoming_job_handler", { "stat": "Minimum" } ],
93
+ [ "AWS/Lambda", "Duration", "FunctionName", "${self:custom.funktor.IncomingJobHandlerName}", { "stat": "Minimum" } ],
94
94
  [ "...", { "stat": "Average" } ],
95
95
  [ "...", { "stat": "Maximum" } ]
96
96
  ],
@@ -110,7 +110,7 @@ Resources:
110
110
  "properties": {
111
111
  "period": 60,
112
112
  "metrics": [
113
- [ "AWS/Lambda", "Errors", "FunctionName", "${self:service}-${self:provider.stage}-incoming_job_handler", { "id": "errors", "stat": "Sum", "color": "#d13212" } ],
113
+ [ "AWS/Lambda", "Errors", "FunctionName", "${self:custom.funktor.IncomingJobHandlerName}", { "id": "errors", "stat": "Sum", "color": "#d13212" } ],
114
114
  [ ".", "Invocations", ".", ".", { "id": "invocations", "stat": "Sum", "visible": false } ],
115
115
  [ { "expression": "100 - 100 * errors / MAX([errors, invocations])", "label": "Success rate (%)", "id": "availability", "yAxis": "right", "region": "us-east-1" } ]
116
116
  ],
@@ -137,7 +137,7 @@ Resources:
137
137
  "properties": {
138
138
  "period": 60,
139
139
  "metrics": [
140
- [ "AWS/Lambda", "ConcurrentExecutions", "FunctionName", "${self:service}-${self:provider.stage}-incoming_job_handler", { "stat": "Maximum" } ]
140
+ [ "AWS/Lambda", "ConcurrentExecutions", "FunctionName", "${self:custom.funktor.IncomingJobHandlerName}", { "stat": "Maximum" } ]
141
141
  ],
142
142
  "region": "us-east-1",
143
143
  "title": "Incoming Job Handler Concurrent Executions",
@@ -2,7 +2,7 @@ Resources:
2
2
  IncomingJobQueue:
3
3
  Type: AWS::SQS::Queue
4
4
  Properties:
5
- QueueName: ${self:custom.funktor.incomingJobQueueName}
5
+ QueueName: ${self:custom.funktor.IncomingJobQueueName}
6
6
  VisibilityTimeout: 300
7
7
  RedrivePolicy:
8
8
  deadLetterTargetArn:
@@ -11,7 +11,7 @@ Resources:
11
11
  IncomingJobDeadLetterQueue:
12
12
  Type: AWS::SQS::Queue
13
13
  Properties:
14
- QueueName: ${self:custom.funktor.incomingDeadJobQueueName}
14
+ QueueName: ${self:custom.funktor.IncomingDeadJobQueueName}
15
15
 
16
16
  Outputs:
17
17
  IncomingJobQueueUrl:
@@ -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
@@ -43,7 +43,7 @@ module Funktor
43
43
  end
44
44
 
45
45
  def execute
46
- worker_class.new.perform(worker_params)
46
+ worker_class.new.perform(*worker_params)
47
47
  end
48
48
 
49
49
  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.6"
2
+ VERSION = "0.2.11"
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.6
4
+ version: 0.2.11
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