funktor 0.2.1 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +35 -0
  3. data/.gitignore +2 -2
  4. data/Gemfile.lock +6 -6
  5. data/funktor.gemspec +1 -1
  6. data/lib/funktor.rb +0 -1
  7. data/lib/funktor/cli/bootstrap.rb +7 -7
  8. data/lib/funktor/cli/init.rb +135 -30
  9. data/lib/funktor/cli/templates/Gemfile +1 -3
  10. data/lib/funktor/cli/templates/{workers → app/workers}/hello_worker.rb +0 -0
  11. data/lib/funktor/cli/templates/config/boot.rb +16 -0
  12. data/lib/funktor/cli/templates/config/environment.yml +4 -2
  13. data/lib/funktor/cli/templates/{function_definitions → config/function_definitions}/incoming_job_handler.yml +1 -1
  14. data/lib/funktor/cli/templates/config/function_definitions/work_queue_handler.yml +11 -0
  15. data/lib/funktor/cli/templates/config/funktor.yml +27 -14
  16. data/lib/funktor/cli/templates/{iam_permissions → config/iam_permissions}/incoming_job_queue.yml +0 -0
  17. data/lib/funktor/cli/templates/{iam_permissions → config/iam_permissions}/ssm.yml +0 -0
  18. data/lib/funktor/cli/templates/{iam_permissions/active_job_queue.yml → config/iam_permissions/work_queue.yml} +1 -1
  19. data/lib/funktor/cli/templates/config/package.yml +4 -2
  20. data/lib/funktor/cli/templates/{resources → config/resources}/cloudwatch_dashboard.yml +268 -231
  21. data/lib/funktor/cli/templates/{resources → config/resources}/incoming_job_queue.yml +0 -0
  22. data/lib/funktor/cli/templates/{resources → config/resources}/incoming_job_queue_user.yml +0 -0
  23. data/lib/funktor/cli/templates/config/resources/work_queue.yml +22 -0
  24. data/lib/funktor/cli/templates/funktor_init.yml.tt +69 -0
  25. data/lib/funktor/cli/templates/{handlers → lambda_event_handlers}/incoming_job_handler.rb +1 -1
  26. data/lib/funktor/cli/templates/lambda_event_handlers/work_queue_handler.rb +8 -0
  27. data/lib/funktor/cli/templates/package.json +8 -1
  28. data/lib/funktor/cli/templates/serverless.yml +13 -12
  29. data/lib/funktor/incoming_job_handler.rb +11 -1
  30. data/lib/funktor/job.rb +4 -0
  31. data/lib/funktor/version.rb +1 -1
  32. data/lib/funktor/worker.rb +9 -0
  33. metadata +17 -18
  34. data/lib/funktor/cli/templates/function_definitions/active_job_handler.yml +0 -11
  35. data/lib/funktor/cli/templates/funktor.yml.tt +0 -51
  36. data/lib/funktor/cli/templates/handlers/active_job_handler.rb +0 -17
  37. data/lib/funktor/cli/templates/resources/active_job_queue.yml +0 -22
  38. data/lib/funktor/deploy/cli.rb +0 -42
  39. data/lib/funktor/deploy/serverless.rb +0 -60
  40. data/lib/funktor/deploy/serverless_templates/serverless.yml +0 -156
@@ -1,60 +0,0 @@
1
- require 'yaml'
2
-
3
- module Funktor
4
- module Deploy
5
- class Serverless
6
- attr_accessor :file, :tmp_dir_prefix, :verbose, :stage
7
- def initialize(file:, tmp_dir_prefix:, verbose:, stage:)
8
- @file = file
9
- @tmp_dir_prefix = tmp_dir_prefix
10
- @verbose = verbose
11
- @stage = stage
12
- end
13
-
14
- def call
15
- #puts "deploying file #{file} via tmp_dir_prefix #{tmp_dir_prefix} for stage #{stage}"
16
- make_tmp_dir
17
- create_serverless_file
18
- end
19
-
20
- def funktor_data
21
- @funktor_data ||= squash_hash(YAML.load_file(file))
22
- end
23
-
24
- def squash_hash(hsh, stack=[])
25
- hsh.reduce({}) do |res, (key, val)|
26
- next_stack = [ *stack, key ]
27
- if val.is_a?(Hash)
28
- next res.merge(squash_hash(val, next_stack))
29
- end
30
- res.merge(next_stack.join(".").to_sym => val)
31
- end
32
- end
33
-
34
- def make_tmp_dir
35
- FileUtils.mkdir_p tmp_dir
36
- end
37
-
38
- def tmp_dir
39
- "#{tmp_dir_prefix}_#{stage}"
40
- end
41
-
42
- def create_serverless_file
43
- #puts "funktor_data = "
44
- #puts funktor_data
45
- template_source = File.open(serverless_file_source).read
46
- file_content = template_source % funktor_data
47
- File.open(serverless_file_destination, 'w') { |file| file.write(file_content) }
48
- end
49
-
50
- def serverless_file_source
51
- File.expand_path("../serverless_templates/serverless.yml", __FILE__)
52
- end
53
-
54
- def serverless_file_destination
55
- File.join tmp_dir, 'serverless.yml'
56
- end
57
- end
58
- end
59
- end
60
-
@@ -1,156 +0,0 @@
1
- # WARNING : You probably don't want to mess with this file directly.
2
- service: %{stack_name}
3
- # app and org for use with dashboard.serverless.com
4
- #app: your-app-name
5
- #org: your-org-name
6
-
7
- frameworkVersion: '2'
8
-
9
- provider:
10
- name: aws
11
- runtime: %{runtime}
12
- lambdaHashingVersion: 20201221
13
- ecr:
14
- images:
15
- funktorimage:
16
- path: ./
17
- # TODO : Expose buildArgs via funktor.yml?
18
- buildArgs:
19
- BUNDLE_GEM__FURY__IO: ${env:BUNDLE_GEM__FURY__IO}
20
- # TODO : Expose environment to funktor.yml?
21
- environment:
22
- FUNKTOR_INCOMING_JOB_QUEUE:
23
- Ref: IncomingJobQueue
24
- FUNKTOR_ACTIVE_JOB_QUEUE:
25
- Ref: ActiveJobQueue
26
- FUNKTOR_DELAYED_JOB_TABLE:
27
- Ref: DelayedJobTable
28
- delayedJobTable:
29
- Ref: DelayedJobTable
30
- iamRoleStatements:
31
- - Effect: Allow
32
- Action:
33
- - ssm:Get*
34
- Resource:
35
- - '*' # TODO : This should probably be more selective...
36
- - Effect: Allow
37
- Action:
38
- - sqs:ReceiveMessage
39
- - sqs:DeleteMessage
40
- - sqs:SendMessage
41
- - sqs:GetQueueAttributes
42
- Resource:
43
- - "Fn::GetAtt": [ ActiveJobQueue, Arn ]
44
- - Effect: Allow
45
- Action:
46
- - sqs:ReceiveMessage
47
- - sqs:DeleteMessage
48
- - sqs:SendMessage
49
- - sqs:GetQueueAttributes
50
- Resource:
51
- - "Fn::GetAtt": [ IncomingJobQueue, Arn ]
52
- - Effect: Allow
53
- Action:
54
- - sqs:ReceiveMessage
55
- - sqs:DeleteMessage
56
- - sqs:SendMessage
57
- - sqs:GetQueueAttributes
58
- Resource:
59
- - "Fn::GetAtt": [ ActivityQueue, Arn ]
60
- - Effect: Allow
61
- Action:
62
- - dynamodb:PutItem
63
- - dynamodb:DeleteItem
64
- Resource:
65
- - "Fn::GetAtt": [ DelayedJobTable, Arn ]
66
- - Effect: Allow
67
- Action:
68
- - dynamodb:*
69
- Resource:
70
- - "Fn::GetAtt": [ StatsTable, Arn ]
71
- - Effect: Allow
72
- Action:
73
- - dynamodb:Query
74
- Resource:
75
- Fn::Join:
76
- - ""
77
- - - "Fn::GetAtt": [ DelayedJobTable, Arn ]
78
- - "/index/performAtIndex"
79
-
80
- custom:
81
- # Our stage is based on what is passed in when running serverless
82
- # commands. Or fallsback to what we have set in the provider section.
83
- stage: ${opt:stage, 'dev'}
84
- incomingJobQueueName: ${self:service}-${self:custom.stage}-incoming-jobs
85
- incomingJobQueueAccessPolicyName: ${self:service}-${self:custom.stage}-incoming-job-queue-access
86
- incomingDeadJobQueueName: ${self:service}-${self:custom.stage}-incoming-dead-jobs
87
- activeJobQueueName: ${self:service}-${self:custom.stage}-active-jobs
88
- activityQueueName: ${self:service}-${self:custom.stage}-activity
89
- activityDeadQueueName: ${self:service}-${self:custom.stage}-activity-dead
90
- deadJobQueueName: ${self:service}-${self:custom.stage}-dead-jobs
91
- delayedJobTableName: ${self:service}-${self:custom.stage}-delayed-jobs
92
- statsTableName: ${self:service}-${self:custom.stage}-stats
93
- dashboardName: ${self:service}-${self:custom.stage}-dashboard
94
-
95
- # you can define service wide environment variables here
96
- # environment:
97
- # variable1: value1
98
-
99
- functions:
100
- # TODO - How could other functions be passed in from funktor.yml?
101
- #random_job_generator:
102
- ##handler: lambda_handlers/random_job_generator.RandomJobGenerator.call
103
- #image:
104
- #name: funktorimage
105
- #command:
106
- #- lambda_handlers/random_job_generator.RandomJobGenerator.call
107
- #timeout: 170
108
- #reservedConcurrency: 0
109
- #events:
110
- #- schedule: rate(1 minute)
111
-
112
- delayed_job_activator:
113
- image:
114
- name: funktorimage
115
- command:
116
- - lambda_handlers/delayed_job_activator.call
117
- timeout: %{delayed_job_activator.timeout_in_seconds}
118
- # TODO - handle memory and concurrency
119
- #reservedConcurrency: 1
120
- events:
121
- - schedule: %{delayed_job_activator.execution_schedule}
122
-
123
- incoming_job_handler:
124
- image:
125
- name: funktorimage
126
- command:
127
- - lambda_handlers/incoming_job_handler.call
128
- timeout: %{incoming_job_handler.timeout_in_seconds}
129
- events:
130
- - sqs:
131
- arn:
132
- Fn::GetAtt:
133
- - IncomingJobQueue
134
- - Arn
135
-
136
- # TODO - We need one of these per work queue
137
- active_job_handler:
138
- image:
139
- name: funktorimage
140
- command:
141
- - lambda_handlers/active_job_handler.call
142
- timeout: 300
143
- events:
144
- - sqs:
145
- arn:
146
- Fn::GetAtt:
147
- - ActiveJobQueue
148
- - Arn
149
-
150
- # you can add CloudFormation resource templates here
151
- resources:
152
- - ${file(resources/sqs-queue.yml)}
153
- - ${file(resources/sqs-incoming-user.yml)}
154
- - ${file(resources/dynamodb-table.yml)}
155
- - ${file(resources/cloudfront-dashboard.yml)}
156
-