cloudwatch_scheduler 1.1.0 → 1.1.1

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: 64fa196a7c5440aced3186a703a91171b2f39be185e19ef5362d5279e0a757c7
4
- data.tar.gz: 73ed1e6e651e4a7316431f0a6d0ab919fb61333c003f50112d1ea18aeb8ca729
3
+ metadata.gz: 482ee591648526177d8b1f26193b4406c035f407535ff1fb069e736d8bc27ab0
4
+ data.tar.gz: 4a7dab7fd8518547edccda964038952f03280b49886f3f458105a358a518a167
5
5
  SHA512:
6
- metadata.gz: b581946e80369ec2c37e03a7b049e37f5e052ed9c4d49efa469f84d3bd694d1d528cd4b798a9a4ef0eef41220d0713134ab81cd63adf4efa8fad388f0d4b85c5
7
- data.tar.gz: 8e9c30866cd7c5cdae95f852322473b6de7275321371a1ce27badc68398eb529aee864c12a48e51b67231a9faac12ee3d90f3d4eb440f2fedf17298348e6fbb6
6
+ metadata.gz: 35c72f33f2e9b723d27f81a1786895cb2b711520c22ddca1a06ac7c76421fb7483b541365ac6682281027a6e0d98adbf1a955abf813ca19537d45178a299ed77
7
+ data.tar.gz: cfe856484ef05f3f9402a7b73d9ef59542cebbd3219f97cf5002a157f35d3068e166e0f2a5de0b5a5ef51fbffb09502c857e003eee4ea171b875c828d63a983f
@@ -0,0 +1,49 @@
1
+ name: CI
2
+
3
+ on:
4
+ - push
5
+ - pull_request
6
+
7
+ jobs:
8
+ rspec:
9
+ name: RSpec
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@master
14
+ - name: Set up Ruby
15
+ uses: actions/setup-ruby@v1
16
+ with:
17
+ ruby-version: 2.7
18
+
19
+ - name: Bundle
20
+ run: |
21
+ bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
22
+ bundle exec appraisal install
23
+
24
+ - name: RSpec
25
+ run: |
26
+ bundle exec appraisal rspec
27
+
28
+ # build:
29
+ # name: Build + Publish
30
+ # runs-on: ubuntu-latest
31
+ # needs: rspec
32
+
33
+ # steps:
34
+ # - uses: actions/checkout@master
35
+ # - name: Set up Ruby 2.6
36
+ # uses: actions/setup-ruby@v1
37
+ # with:
38
+ # version: 2.6.x
39
+
40
+ # - name: Publish to RubyGems
41
+ # run: |
42
+ # mkdir -p $HOME/.gem
43
+ # touch $HOME/.gem/credentials
44
+ # chmod 0600 $HOME/.gem/credentials
45
+ # printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
46
+ # gem build *.gemspec
47
+ # gem push *.gem
48
+ # env:
49
+ # GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
data/.rubocop.yml CHANGED
@@ -1,89 +1,351 @@
1
- Rails:
2
- Enabled: true
1
+ inherit_from:
2
+ - https://relaxed.ruby.style/rubocop.yml
3
+
4
+ require:
5
+ - rubocop-rspec
3
6
 
4
7
  AllCops:
5
8
  DisplayCopNames: true
6
9
  DisplayStyleGuide: true
10
+ TargetRubyVersion: 2.7
7
11
 
8
- Include:
9
- - "**/Rakefile"
10
- - "**/config.ru"
11
12
  Exclude:
12
13
  - "vendor/**/*"
13
14
  - "spec/fixtures/**/*"
14
15
  - "bin/**/*"
15
16
  - "script/**/*"
16
- Metrics/LineLength:
17
- Max: 120
18
- Rails/Date:
17
+ - "node_modules/**/*"
18
+ - "public/**/*"
19
+ - "tmp/**/*"
20
+ - "work/**/*"
21
+
22
+ Layout:
23
+ Severity: error
24
+ Lint:
25
+ Severity: error
26
+
27
+ Layout/HashAlignment:
28
+ EnforcedHashRocketStyle: table
29
+ EnforcedColonStyle: table
30
+ Layout/LineLength:
31
+ Enabled: true
32
+ Max: 140
33
+ Exclude:
34
+ - db/migrate/*.rb
35
+ Lint/AmbiguousBlockAssociation:
36
+ Exclude:
37
+ - "spec/**/*" # `expect { }.to change { }` is fine
38
+ Lint/ShadowingOuterLocalVariable:
39
+ # Shadowing outer local variables with block parameters is often useful to
40
+ # not reinvent a new name for the same thing, it highlights the relation
41
+ # between the outer variable and the parameter. The cases where it's actually
42
+ # confusing are rare, and usually bad for other reasons already, for example
43
+ # because the method is too long.
19
44
  Enabled: false
20
- Rails/TimeZone:
45
+ Metrics/BlockLength:
46
+ Exclude:
47
+ - config/routes.rb
48
+ - db/migrate/*.rb
49
+ - lib/tasks/**/*
50
+ - Gemfile
51
+ - Guardfile
52
+ - shared_context
53
+ - feature
54
+ - app/admin/*
55
+ IgnoredMethods:
56
+ - configure
57
+ - context
58
+ - define
59
+ - describe
60
+ - factory
61
+ - it
62
+ - namespace
63
+ - specify
64
+ - task
65
+ - shared_examples_for
66
+ - shared_context
67
+ - feature
68
+ - define_type
69
+ Metrics/ClassLength:
70
+ Exclude:
71
+ - "spec/**/*_spec.rb"
72
+ Naming/RescuedExceptionsVariableName:
73
+ PreferredName: ex
74
+ Naming/FileName:
21
75
  Enabled: false
22
- AllCops:
23
- TargetRubyVersion: 2.3
24
- Style/AndOr:
25
- EnforcedStyle: conditionals
26
- Style/CaseIndentation:
27
- IndentOneStep: true
28
- Style/Documentation:
76
+ Naming/AccessorMethodName:
77
+ # Avoid writing accessors in Ruby, but this catches too many false positives
29
78
  Enabled: false
30
- Style/EachWithObject:
79
+ Naming/MethodParameterName:
31
80
  Enabled: false
32
- Style/ExtraSpacing:
33
- Exclude:
34
- - "config/routes.rb"
81
+ Style/EmptyLiteral:
82
+ Enabled: false
83
+ Style/FormatStringToken:
84
+ Enabled: false
85
+ Style/FrozenStringLiteralComment:
86
+ Enabled: true
87
+ SafeAutoCorrect: true
88
+ Style/HashEachMethods:
89
+ Enabled: true
35
90
  Style/HashSyntax:
36
91
  Exclude:
37
- - "lib/tasks/**/*"
38
- Style/MultilineOperationIndentation:
39
- EnforcedStyle: indented
92
+ - lib/tasks/**/*.rake
93
+ Style/HashTransformKeys:
94
+ Enabled: true
95
+ Style/HashTransformValues:
96
+ Enabled: true
97
+ Style/MethodCallWithoutArgsParentheses:
98
+ Enabled: true
40
99
  Style/NumericLiterals:
41
100
  Enabled: false
42
- Style/PercentLiteralDelimiters:
43
- PreferredDelimiters:
44
- "%w": "[]"
45
- "%W": "[]"
46
- "%i": "[]"
47
- "%I": "[]"
48
- "%r": "()"
49
- Style/SignalException:
50
- EnforcedStyle: semantic
51
- Style/SingleLineBlockParams:
52
- Enabled: false
101
+ Style/StringChars:
102
+ Enabled: true
53
103
  Style/StringLiterals:
104
+ Enabled: true
54
105
  EnforcedStyle: double_quotes
55
- Style/MultilineMethodCallIndentation:
56
- Exclude:
57
- - "spec/**/*.rb"
106
+ Style/SymbolArray:
107
+ MinSize: 4
58
108
 
109
+ # 0.81
110
+ Lint/RaiseException:
111
+ Enabled: true
112
+ Lint/StructNewOverride:
113
+ Enabled: false
59
114
 
60
- # Rubocop's global exclude seems to fail to exclude the bin/ dir, so set all
61
- # the cops that are failing manually, since most of these files are
62
- # auto-generated anyways. Also, if the rules also appear above, we need to copy
63
- # the same attrs, because YAML won't merge, only overwrite.
115
+ # 0.82
116
+ Layout/SpaceAroundMethodCallOperator:
117
+ Enabled: true
118
+ Style/ExponentialNotation:
119
+ Enabled: true
64
120
 
65
- Style/StringLiterals:
66
- EnforcedStyle: double_quotes
67
- Exclude:
68
- - "bin/**/*"
69
- Style/FrozenStringLiteralComment:
70
- Exclude:
71
- - "bin/**/*"
72
- Style/LeadingCommentSpace:
73
- Exclude:
74
- - "bin/**/*"
75
- Style/SpaceInsideParens:
76
- Exclude:
77
- - "bin/**/*"
78
- Style/AlignParameters:
79
- Exclude:
80
- - "bin/**/*"
81
- Style/ExtraSpacing:
82
- Exclude:
83
- - "bin/**/*"
84
- Exclude:
85
- - "config/routes.rb"
86
- Lint/PercentStringArray:
87
- Exclude:
88
- # SecureHeaders needs the single quotes in `%w[https: 'self']`
89
- - config/initializers/secure_headers.rb
121
+ # 0.83
122
+ Layout/EmptyLinesAroundAttributeAccessor:
123
+ Enabled: true
124
+ Style/SlicingWithRange:
125
+ Enabled: true
126
+
127
+ # 0.84
128
+ Lint/DeprecatedOpenSSLConstant:
129
+ Enabled: true
130
+
131
+ # 0.85
132
+ Lint/MixedRegexpCaptureTypes:
133
+ Enabled: true
134
+ Style/RedundantRegexpCharacterClass:
135
+ Enabled: true
136
+ Style/RedundantRegexpEscape:
137
+ Enabled: true
138
+
139
+ # 0.86
140
+ Style/RedundantFetchBlock:
141
+ Enabled: true
142
+ Lint/ConstantResolution:
143
+ Enabled: false
144
+
145
+ # 0.87
146
+ Style/AccessorGrouping:
147
+ Enabled: true
148
+ Style/BisectedAttrAccessor:
149
+ Enabled: true
150
+ Style/RedundantAssignment:
151
+ Enabled: true
152
+
153
+ # 0.88
154
+ Lint/DuplicateElsifCondition:
155
+ Enabled: true
156
+ Style/ArrayCoercion:
157
+ Enabled: true
158
+ Style/CaseLikeIf:
159
+ Enabled: true
160
+ Style/HashAsLastArrayItem:
161
+ Enabled: true
162
+ Style/HashLikeCase:
163
+ Enabled: true
164
+ Style/RedundantFileExtensionInRequire:
165
+ Enabled: true
166
+
167
+ # 0.89
168
+ Lint/BinaryOperatorWithIdenticalOperands:
169
+ Enabled: true
170
+ Lint/DuplicateRescueException:
171
+ Enabled: true
172
+ Lint/EmptyConditionalBody:
173
+ Enabled: true
174
+ Lint/FloatComparison:
175
+ Enabled: true
176
+ Lint/MissingSuper:
177
+ Enabled: false
178
+ Lint/OutOfRangeRegexpRef:
179
+ Enabled: true
180
+ Lint/SelfAssignment:
181
+ Enabled: true
182
+ Lint/TopLevelReturnWithArgument:
183
+ Enabled: true
184
+ Lint/UnreachableLoop:
185
+ Enabled: true
186
+ Style/ExplicitBlockArgument:
187
+ Enabled: true
188
+ Style/GlobalStdStream:
189
+ Enabled: false
190
+ Style/OptionalBooleanParameter:
191
+ Enabled: false
192
+ Style/SingleArgumentDig:
193
+ Enabled: false
194
+ Style/SoleNestedConditional:
195
+ Enabled: true
196
+ Style/StringConcatenation:
197
+ # `"a" + var + "b"` should be interpolated, but `"a" + var` or `var + "b"` is
198
+ # fine concatted
199
+ Enabled: false
200
+
201
+ # 0.90
202
+ Lint/DuplicateRequire:
203
+ Enabled: true
204
+ Lint/EmptyFile:
205
+ Enabled: true
206
+ Lint/TrailingCommaInAttributeDeclaration:
207
+ Enabled: true
208
+ Lint/UselessMethodDefinition:
209
+ Enabled: true
210
+ Style/CombinableLoops:
211
+ Enabled: true
212
+ Style/KeywordParametersOrder:
213
+ Enabled: true
214
+ Style/RedundantSelfAssignment:
215
+ Enabled: true
216
+
217
+ # 0.91
218
+ Layout/BeginEndAlignment:
219
+ Enabled: true
220
+ Lint/ConstantDefinitionInBlock:
221
+ Enabled: false
222
+ Lint/IdentityComparison:
223
+ Enabled: true
224
+ Lint/UselessTimes:
225
+ Enabled: true
226
+
227
+ # 0.93
228
+ Lint/HashCompareByIdentity:
229
+ Enabled: true
230
+ Lint/RedundantSafeNavigation:
231
+ Enabled: true
232
+ Style/ClassEqualityComparison:
233
+ Enabled: true
234
+
235
+ # 1.1
236
+ Lint/DuplicateRegexpCharacterClassElement:
237
+ Enabled: true
238
+ Lint/EmptyBlock:
239
+ Enabled: false
240
+ Lint/ToEnumArguments:
241
+ Enabled: true
242
+ Lint/UnmodifiedReduceAccumulator:
243
+ Enabled: true
244
+ Style/ArgumentsForwarding:
245
+ Enabled: true
246
+ Style/SwapValues:
247
+ Enabled: true
248
+ Style/DocumentDynamicEvalDefinition:
249
+ Enabled: false
250
+
251
+ #1.2
252
+ Lint/NoReturnInBeginEndBlocks:
253
+ Enabled: false
254
+ Style/CollectionCompact:
255
+ Enabled: true
256
+ Style/NegatedIfElseCondition:
257
+ Enabled: true
258
+
259
+ # 1.3
260
+ Lint/DuplicateBranch:
261
+ Enabled: true
262
+ Lint/EmptyClass:
263
+ Enabled: true
264
+ Style/NilLambda:
265
+ Enabled: true
266
+
267
+ # 1.4
268
+ Style/RedundantArgument:
269
+ Enabled: false # Better to be explicit
270
+
271
+ # 1.5
272
+ Lint/UnexpectedBlockArity:
273
+ Enabled: true
274
+
275
+ # 1.7
276
+ Layout/SpaceBeforeBrackets:
277
+ Enabled: false #spaces are sometimes necessary
278
+ Lint/AmbiguousAssignment:
279
+ Enabled: true
280
+ Style/HashExcept:
281
+ Enabled: true
282
+
283
+ # 1.8
284
+ Lint/DeprecatedConstants:
285
+ Enabled: true
286
+ Lint/LambdaWithoutLiteralBlock:
287
+ Enabled: true
288
+ Lint/RedundantDirGlobSort:
289
+ Enabled: true
290
+ Style/EndlessMethod:
291
+ Enabled: true
292
+
293
+ # 1.9
294
+
295
+ Lint/NumberedParameterAssignment:
296
+ Enabled: true
297
+ Lint/OrAssignmentToConstant:
298
+ Enabled: true
299
+ Lint/TripleQuotes:
300
+ Enabled: true
301
+ Style/IfWithBooleanLiteralBranches:
302
+ Enabled: true
303
+ Lint/SymbolConversion:
304
+ Enabled: true
305
+
306
+ # 1.10
307
+ Gemspec/DateAssignment:
308
+ Enabled: true
309
+ Style/HashConversion:
310
+ Enabled: true
311
+
312
+
313
+ # Rspec
314
+ RSpec/Capybara/FeatureMethods:
315
+ Enabled: false
316
+ RSpec/ContextWording:
317
+ Enabled: false
318
+ RSpec/DescribeClass:
319
+ Enabled: false
320
+ RSpec/DescribedClass:
321
+ Enabled: false
322
+ RSpec/ExampleLength:
323
+ Max: 10
324
+ RSpec/ExampleWording:
325
+ Enabled: false
326
+ RSpec/ExpectChange:
327
+ EnforcedStyle: block
328
+ RSpec/Focus:
329
+ Severity: error
330
+ RSpec/ImplicitExpect:
331
+ Enabled: false
332
+ RSpec/LeadingSubject:
333
+ Enabled: false
334
+ RSpec/MessageSpies:
335
+ Enabled: false
336
+ RSpec/MultipleExpectations:
337
+ Max: 4
338
+ RSpec/NestedGroups:
339
+ Max: 4
340
+ RSpec/NotToNot:
341
+ Enabled: false
342
+ RSpec/ExpectInHook:
343
+ Enabled: false
344
+ RSpec/LetSetup:
345
+ Enabled: false
346
+ RSpec/MultipleMemoizedHelpers:
347
+ Enabled: false
348
+
349
+ # 1.44
350
+ RSpec/StubbedMock:
351
+ Enabled: true
data/Appraisals CHANGED
@@ -1,12 +1,11 @@
1
+ # frozen_string_literal: true
1
2
 
2
- appraise "rails-5.0" do
3
- gem "rails", "~> 5.0.0"
4
- end
5
-
6
- appraise "rails-5.1" do
7
- gem "rails", "~> 5.1.0"
3
+ appraise "rails-5.2" do
4
+ gem "railties", "~> 5.2.0"
5
+ gem "activejob", "~> 5.2.0"
8
6
  end
9
7
 
10
- appraise "rails-5.2" do
11
- gem "rails", "~> 5.2.0"
8
+ appraise "rails-6.1" do
9
+ gem "railties", "~> 6.1"
10
+ gem "activejob", "~> 6.1"
12
11
  end
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in cloudwatch_scheduler.gemspec
6
6
  gemspec
@@ -10,5 +10,6 @@ group :development, :test do
10
10
  gem "guard"
11
11
  gem "guard-rspec"
12
12
 
13
- gem "appraisal"
13
+ gem "rubocop"
14
+ gem "rubocop-rspec"
14
15
  end
data/Guardfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # A sample Guardfile
2
4
  # More info at https://github.com/guard/guard#readme
3
5
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # CloudwatchScheduler
2
2
 
3
- [![Build Status](https://travis-ci.org/paul/cloudwatch_scheduler.svg?branch=master)](https://travis-ci.org/paul/cloudwatch_scheduler)
3
+ [![Actions Status](https://github.com/paul/cloudwatch_scheduler/workflows/CI/badge.svg)](https://github.com/paul/cloudwatch_scheduler/actions)
4
4
 
5
5
  Are you using Rails 4.2+ and ActiveJob with the [Shoryuken
6
6
  driver][shoryuken-driver] to use SQS? Do you have recurring jobs that you kick
@@ -54,10 +54,49 @@ CloudwatchScheduler do |config|
54
54
  end
55
55
  ```
56
56
 
57
+ You'll also need to inform Shoryuken about the `cloudwatch_scheduler` queue,
58
+ either in the `config/shoryuken.yml` or with `-q cloudwatch_scheduler` on the
59
+ command line.
60
+
57
61
  Then do `rake cloudwatch_scheduler:setup`, and CloudwatchScheduler will provision the events and
58
62
  cloudwatch_scheduler queue. Then, start your Shoruken workers as normal, and the
59
63
  `CloudwatchScheduler::Job` will get those events, and perform the tasks defined.
60
64
 
65
+ ### IAM Permissions
66
+
67
+ The setup task requires some permissions in the AWS account to create the queue
68
+ and Cloudwatch Events. Here's a sample policy:
69
+
70
+ ```json
71
+ {
72
+ "Version": "2012-10-17",
73
+ "Statement": [
74
+ {
75
+ "Effect": "Allow",
76
+ "Action": [
77
+ "sqs:CreateQueue",
78
+ "sqs:GetQueueAttributes",
79
+ "sqs:SetQueueAttributes",
80
+ ],
81
+ "Resource": [
82
+ "arn:aws:sqs:REGION:AWS_ACCOUNT:cloudwatch_scheduler",
83
+ "arn:aws:sqs:REGION:AWS_ACCOUNT:cloudwatch_scheduler-failures"
84
+ ]
85
+ },
86
+ {
87
+ "Effect": "Allow",
88
+ "Action": [
89
+ "events:PutRule",
90
+ "events:PutTargets"
91
+ ],
92
+ "Resource": [
93
+ "*"
94
+ ]
95
+ }
96
+ ]
97
+ }
98
+ ```
99
+
61
100
  ## Development
62
101
 
63
102
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -19,12 +19,15 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r(^exe/)) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.required_ruby_version = "~> 2.5"
23
+
22
24
  spec.add_dependency "aws-sdk-cloudwatchevents", "~> 1.13"
23
25
  spec.add_dependency "aws-sdk-sqs", "~> 1.10"
24
- spec.add_dependency "rails", ">= 4.2.0"
26
+ spec.add_dependency "rails", ">= 5.2.0"
25
27
  spec.add_dependency "shoryuken", ">= 2.0"
26
28
 
29
+ spec.add_development_dependency "appraisal", "~> 2.2.0"
27
30
  spec.add_development_dependency "bundler", ">= 1.12"
28
- spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rake", "~> 12.0"
29
32
  spec.add_development_dependency "rspec", "~> 3.0"
30
33
  end
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file was generated by Appraisal
2
4
 
3
5
  source "https://rubygems.org"
4
6
 
5
- gem "rails", "~> 5.2.0"
7
+ gem "activejob", "~> 5.2.0"
8
+ gem "railties", "~> 5.2.0"
6
9
 
7
10
  group :development, :test do
8
11
  gem "awesome_print"
9
12
  gem "guard"
10
13
  gem "guard-rspec"
11
- gem "appraisal"
12
14
  end
13
15
 
14
16
  gemspec path: "../"
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file was generated by Appraisal
2
4
 
3
5
  source "https://rubygems.org"
4
6
 
5
- gem "rails", "~> 4.2.0"
7
+ gem "activejob", "~> 6.0"
8
+ gem "railties", "~> 6.0"
6
9
 
7
10
  group :development, :test do
8
11
  gem "awesome_print"
9
12
  gem "guard"
10
13
  gem "guard-rspec"
11
- gem "appraisal"
12
14
  end
13
15
 
14
16
  gemspec path: "../"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  require "cloudwatch_scheduler/configuration"
3
4
  require "cloudwatch_scheduler/task"
@@ -10,10 +11,7 @@ def CloudwatchScheduler(&config)
10
11
  end
11
12
 
12
13
  module CloudwatchScheduler
13
-
14
14
  def self.global
15
15
  @global ||= CloudwatchScheduler::Configuration.new
16
16
  end
17
-
18
17
  end
19
-
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/numeric/time"
2
4
 
3
5
  module CloudwatchScheduler
4
6
  class Configuration
5
-
6
- attr_accessor :queue_name,
7
- :queue_visibility_timeout,
7
+ attr_accessor :queue_visibility_timeout,
8
8
  :queue_max_receive_count,
9
9
  :use_dead_letter_queue
10
10
 
@@ -30,9 +30,10 @@ module CloudwatchScheduler
30
30
  @use_dead_letter_queue = true
31
31
  end
32
32
 
33
+ attr_writer :queue_name
34
+
33
35
  def queue_name
34
36
  @queue_name ||= CloudwatchScheduler::Job.queue_name
35
37
  end
36
-
37
38
  end
38
39
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module CloudwatchScheduler
3
4
  class Engine < Rails::Engine
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CloudwatchScheduler
2
4
  class Job < ::ApplicationJob
3
5
  queue_as :cloudwatch_scheduler
@@ -9,6 +11,5 @@ module CloudwatchScheduler
9
11
  def perform(job_to_spawn)
10
12
  @config.tasks[job_to_spawn].invoke
11
13
  end
12
-
13
14
  end
14
15
  end
@@ -23,37 +23,24 @@ module CloudwatchScheduler
23
23
  attributes = { "VisibilityTimeout" => config.queue_visibility_timeout.to_s }
24
24
  @queue_url = sqs.create_queue(queue_name: queue_name, attributes: attributes).queue_url
25
25
 
26
- if config.use_dead_letter_queue
27
- dlq_name = queue_name + "-failures"
28
- dlq_url = sqs.create_queue(queue_name: dlq_name).queue_url
29
- dlq_arn = sqs.get_queue_attributes(queue_url: dlq_url, attribute_names: ["QueueArn"]).attributes["QueueArn"]
30
-
31
- redrive_attrs = {
32
- maxReceiveCount: config.queue_max_receive_count.to_s,
33
- deadLetterTargetArn: dlq_arn
34
- }.to_json
35
-
36
- attributes = { "RedrivePolicy" => redrive_attrs }
37
-
38
- sqs.set_queue_attributes(queue_url: queue_url, attributes: attributes)
39
- end
26
+ create_dead_letter_queue! if config.use_dead_letter_queue
40
27
  end
41
28
 
42
29
  def create_events!
43
30
  rule_arns = config.tasks.map do |_name, task|
44
31
  rule_arn = cwe.put_rule(
45
- name: task.rule_name,
32
+ name: task.rule_name,
46
33
  schedule_expression: task.rule_schedule_expression,
47
- state: "ENABLED",
48
- description: "CloudwatchScheduler task defined at #{task.code.source_location}"
34
+ state: "ENABLED",
35
+ description: "CloudwatchScheduler task defined at #{task.code.source_location}"
49
36
  ).rule_arn
50
37
 
51
38
  cwe.put_targets(
52
- rule: task.rule_name,
39
+ rule: task.rule_name,
53
40
  targets: [
54
41
  {
55
- id: task.rule_name,
56
- arn: queue_arn,
42
+ id: task.rule_name,
43
+ arn: queue_arn,
57
44
  input: task.event_data.to_json
58
45
  }
59
46
  ]
@@ -63,19 +50,19 @@ module CloudwatchScheduler
63
50
  end
64
51
 
65
52
  policy = {
66
- "Version": "2012-10-17",
67
- "Id": "#{queue_arn}/SQSDefaultPolicy",
68
- "Statement": rule_arns.map do |rule_arn|
53
+ Version: "2012-10-17",
54
+ Id: "#{queue_arn}/SQSDefaultPolicy",
55
+ Statement: rule_arns.map do |rule_arn|
69
56
  {
70
- "Sid": "TrustCWESendingToSQS",
71
- "Effect": "Allow",
72
- "Principal": {
73
- "AWS": "*"
57
+ Sid: "TrustCWESendingToSQS",
58
+ Effect: "Allow",
59
+ Principal: {
60
+ AWS: "*"
74
61
  },
75
- "Action": "sqs:SendMessage",
76
- "Resource": queue_arn,
77
- "Condition": {
78
- "ArnEquals": {
62
+ Action: "sqs:SendMessage",
63
+ Resource: queue_arn,
64
+ Condition: {
65
+ ArnEquals: {
79
66
  "aws:SourceArn": rule_arn
80
67
  }
81
68
  }
@@ -84,7 +71,7 @@ module CloudwatchScheduler
84
71
  }
85
72
 
86
73
  sqs.set_queue_attributes(
87
- queue_url: queue_url,
74
+ queue_url: queue_url,
88
75
  attributes: {
89
76
  "Policy" => policy.to_json
90
77
  }
@@ -93,6 +80,21 @@ module CloudwatchScheduler
93
80
 
94
81
  private
95
82
 
83
+ def create_dead_letter_queue!
84
+ dlq_name = queue_name + "-failures"
85
+ dlq_url = sqs.create_queue(queue_name: dlq_name).queue_url
86
+ dlq_arn = sqs.get_queue_attributes(queue_url: dlq_url, attribute_names: ["QueueArn"]).attributes["QueueArn"]
87
+
88
+ redrive_attrs = {
89
+ maxReceiveCount: config.queue_max_receive_count.to_s,
90
+ deadLetterTargetArn: dlq_arn
91
+ }.to_json
92
+
93
+ attributes = { "RedrivePolicy" => redrive_attrs }
94
+
95
+ sqs.set_queue_attributes(queue_url: queue_url, attributes: attributes)
96
+ end
97
+
96
98
  def queue_name
97
99
  config.queue_name
98
100
  end
@@ -1,4 +1,6 @@
1
- require 'active_support/core_ext/digest/uuid'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/digest/uuid"
2
4
 
3
5
  module CloudwatchScheduler
4
6
  class Task
@@ -8,6 +10,7 @@ module CloudwatchScheduler
8
10
  @name = name
9
11
  @every, @cron = every, cron
10
12
  fail "You must specify one of every: or cron:" unless [@every, @cron].any?
13
+
11
14
  @code = code
12
15
  end
13
16
 
@@ -24,18 +27,18 @@ module CloudwatchScheduler
24
27
  # "locale":"en"}
25
28
  def event_data
26
29
  {
27
- job_class: CloudwatchScheduler::Job.name,
28
- job_id: job_id,
30
+ job_class: CloudwatchScheduler::Job.name,
31
+ job_id: job_id,
29
32
  queue_name: CloudwatchScheduler::Job.queue_name,
30
- arguments: [name],
31
- locale: "en",
32
- priority: nil
33
+ arguments: [name],
34
+ locale: "en",
35
+ priority: nil
33
36
  }
34
37
  end
35
38
 
36
39
  def rule_name
37
40
  limit = 64 - CloudwatchScheduler::Job.queue_name.length
38
- [name[0, limit-1], CloudwatchScheduler::Job.queue_name].join("-")
41
+ [name[0, limit - 1], CloudwatchScheduler::Job.queue_name].join("-")
39
42
  end
40
43
 
41
44
  def rule_schedule_expression
@@ -65,6 +68,5 @@ module CloudwatchScheduler
65
68
  def cron_exp
66
69
  "cron(#{@cron})"
67
70
  end
68
-
69
71
  end
70
72
  end
@@ -1,14 +1,12 @@
1
-
1
+ # frozen_string_literal: true
2
2
 
3
3
  namespace :cloudwatch_scheduler do
4
-
5
4
  desc "Create AWS Cloudwatch Event Rules for all defined tasks"
6
- task :setup => :environment do
5
+ task setup: :environment do
7
6
  Aws.config[:logger] = Logger.new(STDOUT)
8
7
  require Rails.root.join("config/cloudwatch_schedule").to_s
9
8
 
10
9
  config = CloudwatchScheduler.global
11
10
  CloudwatchScheduler::Provisioner.new(config).provision
12
11
  end
13
-
14
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CloudwatchScheduler
2
- VERSION = "1.1.0"
4
+ VERSION = "1.1.1"
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudwatch_scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Sadauskas
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-09 00:00:00.000000000 Z
11
+ date: 2021-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-cloudwatchevents
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 4.2.0
47
+ version: 5.2.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 4.2.0
54
+ version: 5.2.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: shoryuken
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: appraisal
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.2.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.2.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +100,14 @@ dependencies:
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '10.0'
103
+ version: '12.0'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '10.0'
110
+ version: '12.0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rspec
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +129,7 @@ executables: []
115
129
  extensions: []
116
130
  extra_rdoc_files: []
117
131
  files:
132
+ - ".github/workflows/ci.yml"
118
133
  - ".gitignore"
119
134
  - ".rspec"
120
135
  - ".rubocop.yml"
@@ -128,10 +143,8 @@ files:
128
143
  - bin/setup
129
144
  - cloudwatch_scheduler.gemspec
130
145
  - gemfiles/.bundle/config
131
- - gemfiles/rails_4.2.gemfile
132
- - gemfiles/rails_5.0.gemfile
133
- - gemfiles/rails_5.1.gemfile
134
146
  - gemfiles/rails_5.2.gemfile
147
+ - gemfiles/rails_6.0.gemfile
135
148
  - lib/cloudwatch_scheduler.rb
136
149
  - lib/cloudwatch_scheduler/configuration.rb
137
150
  - lib/cloudwatch_scheduler/engine.rb
@@ -143,23 +156,23 @@ files:
143
156
  homepage: https://github.com/paul/cloudwatch_scheduler
144
157
  licenses: []
145
158
  metadata: {}
146
- post_install_message:
159
+ post_install_message:
147
160
  rdoc_options: []
148
161
  require_paths:
149
162
  - lib
150
163
  required_ruby_version: !ruby/object:Gem::Requirement
151
164
  requirements:
152
- - - ">="
165
+ - - "~>"
153
166
  - !ruby/object:Gem::Version
154
- version: '0'
167
+ version: '2.5'
155
168
  required_rubygems_version: !ruby/object:Gem::Requirement
156
169
  requirements:
157
170
  - - ">="
158
171
  - !ruby/object:Gem::Version
159
172
  version: '0'
160
173
  requirements: []
161
- rubygems_version: 3.0.3
162
- signing_key:
174
+ rubygems_version: 3.2.15
175
+ signing_key:
163
176
  specification_version: 4
164
177
  summary: Use AWS CloudWatch events to trigger recurring jobs.
165
178
  test_files: []
@@ -1,14 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 5.0.0"
6
-
7
- group :development, :test do
8
- gem "awesome_print"
9
- gem "guard"
10
- gem "guard-rspec"
11
- gem "appraisal"
12
- end
13
-
14
- gemspec path: "../"
@@ -1,14 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 5.1.0"
6
-
7
- group :development, :test do
8
- gem "awesome_print"
9
- gem "guard"
10
- gem "guard-rspec"
11
- gem "appraisal"
12
- end
13
-
14
- gemspec path: "../"