elastic_whenever 0.4.1 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +30 -0
- data/CHANGELOG.md +38 -0
- data/README.md +24 -1
- data/elastic_whenever.gemspec +1 -1
- data/lib/elastic_whenever/cli.rb +1 -1
- data/lib/elastic_whenever/option.rb +13 -0
- data/lib/elastic_whenever/task/role.rb +3 -4
- data/lib/elastic_whenever/task/rule.rb +28 -7
- data/lib/elastic_whenever/version.rb +1 -1
- metadata +6 -6
- data/.travis.yml +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 448f6e4c937fdc568cf15f2bd0c488f89c2d65fc83396f5cec02f7b8cdb791a7
|
4
|
+
data.tar.gz: 0d48b483b1dfc7991398ce6b499426b21657466c62588235ed155ab3acf7fecd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05a39822bd08957051d973ab2ca2fe1f39a976962bcb73e4381831b2c18660c9880f0034ba491749618601429494bb53ba1877bc07501d495f2f3304c3b1c139
|
7
|
+
data.tar.gz: 8a3ca786d459492a724a9cfe65e9616d009ad5ffd7982e8517a2e44ddbed3d8a6892f89aef879fc8a8f6369d18c3d44c69a8d606135eedeb7cc2e2f9b141d27c
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: build
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
schedule:
|
11
|
+
- cron: "0 0 * * *"
|
12
|
+
|
13
|
+
jobs:
|
14
|
+
spec:
|
15
|
+
name: Ruby ${{ matrix.ruby_version }}
|
16
|
+
runs-on: ubuntu-latest
|
17
|
+
strategy:
|
18
|
+
matrix:
|
19
|
+
ruby_version: ['2.5.x', '2.6.x', '2.7.x']
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v2
|
22
|
+
- name: Set up Ruby ${{ matrix.ruby_version }}
|
23
|
+
uses: actions/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby_version }}
|
26
|
+
- name: Run spec
|
27
|
+
run: |
|
28
|
+
gem install bundler
|
29
|
+
bundle install --jobs 4 --retry 3
|
30
|
+
bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,41 @@
|
|
1
|
+
## v0.6.1 (2020-11-08)
|
2
|
+
|
3
|
+
### BugFixes
|
4
|
+
|
5
|
+
- [#51](https://github.com/wata727/elastic_whenever/pull/51): Avoid hitting rate limits fetching credentials when running under ECS or with an IAM profile ([@stevenwilliamson](https://github.com/stevenwilliamson))
|
6
|
+
|
7
|
+
### Chores
|
8
|
+
|
9
|
+
- [#53](https://github.com/wata727/elastic_whenever/pull/53): Migrate CI to GitHub Actions from Travis CI
|
10
|
+
|
11
|
+
## v0.6.0 (2019-10-16)
|
12
|
+
|
13
|
+
### Enhancements
|
14
|
+
|
15
|
+
- [#46](https://github.com/wata727/elastic_whenever/pull/46): Add option to disable rule ([@tobscher](https://github.com/tobscher))
|
16
|
+
|
17
|
+
## v0.5.1 (2019-10-09)
|
18
|
+
|
19
|
+
### Enhancements
|
20
|
+
|
21
|
+
- [#45](https://github.com/wata727/elastic_whenever/pull/45): Add description to CloudWatch rule ([@tobscher](https://github.com/tobscher))
|
22
|
+
|
23
|
+
## v0.5.0 (2019-09-19)
|
24
|
+
|
25
|
+
### Enhancements
|
26
|
+
|
27
|
+
- [#44](https://github.com/wata727/elastic_whenever/pull/44): Make CloudWatch Events IAM role name configurable ([@domcleal](https://github.com/domcleal))
|
28
|
+
|
29
|
+
## v0.4.2 (2019-09-17)
|
30
|
+
|
31
|
+
### BugFixes
|
32
|
+
|
33
|
+
- [#43](https://github.com/wata727/elastic_whenever/pull/43): Add expression to task rule name hash computation ([@korbin](https://github.com/korbin))
|
34
|
+
|
35
|
+
### Chore
|
36
|
+
|
37
|
+
- [#42](https://github.com/wata727/elastic_whenever/pull/42): Fix typo in clear task log line ([@HistoireDeBabar](https://github.com/HistoireDeBabar))
|
38
|
+
|
1
39
|
## v0.4.1 (2019-07-23)
|
2
40
|
|
3
41
|
### BugFixes
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Elastic Whenever
|
2
|
-
[![Build Status](https://
|
2
|
+
[![Build Status](https://github.com/wata727/elastic_whenever/workflows/build/badge.svg?branch=master)](https://github.com/wata727/elastic_whenever/actions)
|
3
3
|
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE.txt)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/elastic_whenever.svg)](https://badge.fury.io/rb/elastic_whenever)
|
5
5
|
|
@@ -42,6 +42,8 @@ Usage: elastic_whenever [options]
|
|
42
42
|
--subnets subnets Example: --subnets 'subnet-4973d63f,subnet-45827d1d' (FARGATE only)
|
43
43
|
--platform-version version Optionally specify the platform version. Default: LATEST (FARGATE only)
|
44
44
|
-f, --file schedule_file Default: config/schedule.rb
|
45
|
+
--iam-role name IAM role name used by CloudWatch Events. Default: ecsEventsRole
|
46
|
+
--rule-state state The state of the CloudWatch Events Rule (ENABLED or DISABLED), default: ENABLED
|
45
47
|
--profile profile_name AWS shared profile name
|
46
48
|
--access-key aws_access_key_id
|
47
49
|
AWS access key ID
|
@@ -62,6 +64,27 @@ cron(0 3 * * ? *) ecs-test example:2 cron bundle exec rake hoge:run
|
|
62
64
|
## [message] Run `elastic_whenever --help' for more options.
|
63
65
|
```
|
64
66
|
|
67
|
+
### Setting variables
|
68
|
+
Elastic Whenever supports setting variables via the `--set` option [as Whenever does](https://github.com/javan/whenever/wiki/Setting-variables-on-the-fly).
|
69
|
+
|
70
|
+
Example:
|
71
|
+
|
72
|
+
`elastic_whenever --set 'environment=staging&some_var=foo'`
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
if @environment == 'staging'
|
76
|
+
every '0 1 * * *' do
|
77
|
+
rake 'some_task_on_staging'
|
78
|
+
end
|
79
|
+
elsif @some_var == 'foo'
|
80
|
+
every '0 10 * * *' do
|
81
|
+
rake 'some_task'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
Especially, `@environment` defaults to `"production"`.
|
87
|
+
|
65
88
|
## How it works
|
66
89
|
Elastic Whenever creates CloudWatch Events as many as `every` block. Each event has as many targets as there are commands in the block.
|
67
90
|
|
data/elastic_whenever.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 2.0"
|
24
|
-
spec.add_development_dependency "rake", "~>
|
24
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
25
25
|
spec.add_development_dependency "rspec", "~> 3.0"
|
26
26
|
|
27
27
|
spec.add_dependency "aws-sdk-ecs", "~> 1.0"
|
data/lib/elastic_whenever/cli.rb
CHANGED
@@ -22,7 +22,7 @@ module ElasticWhenever
|
|
22
22
|
with_concurrent_modification_handling do
|
23
23
|
clear_tasks(option)
|
24
24
|
end
|
25
|
-
Logger.instance.log("write", "
|
25
|
+
Logger.instance.log("write", "scheduled tasks cleared")
|
26
26
|
when Option::LIST_MODE
|
27
27
|
list_tasks(option)
|
28
28
|
Logger.instance.message("Above is your scheduled tasks.")
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module ElasticWhenever
|
2
2
|
class Option
|
3
|
+
POSSIBLE_RULE_STATES = %w[ENABLED DISABLED].freeze
|
4
|
+
|
3
5
|
DRYRUN_MODE = 1
|
4
6
|
UPDATE_MODE = 2
|
5
7
|
CLEAR_MODE = 3
|
@@ -19,6 +21,8 @@ module ElasticWhenever
|
|
19
21
|
attr_reader :security_groups
|
20
22
|
attr_reader :subnets
|
21
23
|
attr_reader :schedule_file
|
24
|
+
attr_reader :iam_role
|
25
|
+
attr_reader :rule_state
|
22
26
|
|
23
27
|
class InvalidOptionException < StandardError; end
|
24
28
|
|
@@ -36,6 +40,8 @@ module ElasticWhenever
|
|
36
40
|
@security_groups = []
|
37
41
|
@subnets = []
|
38
42
|
@schedule_file = 'config/schedule.rb'
|
43
|
+
@iam_role = 'ecsEventsRole'
|
44
|
+
@rule_state = 'ENABLED'
|
39
45
|
@profile = nil
|
40
46
|
@access_key = nil
|
41
47
|
@secret_key = nil
|
@@ -92,6 +98,12 @@ module ElasticWhenever
|
|
92
98
|
opts.on('-f', '--file schedule_file', 'Default: config/schedule.rb') do |file|
|
93
99
|
@schedule_file = file
|
94
100
|
end
|
101
|
+
opts.on('--iam-role name', 'IAM role name used by CloudWatch Events. Default: ecsEventsRole') do |role|
|
102
|
+
@iam_role = role
|
103
|
+
end
|
104
|
+
opts.on('--rule-state state', 'The state of the CloudWatch Events Rule. Default: ENABLED') do |state|
|
105
|
+
@rule_state = state
|
106
|
+
end
|
95
107
|
opts.on('--profile profile_name', 'AWS shared profile name') do |profile|
|
96
108
|
@profile = profile
|
97
109
|
end
|
@@ -128,6 +140,7 @@ module ElasticWhenever
|
|
128
140
|
raise InvalidOptionException.new("You must set cluster") unless cluster
|
129
141
|
raise InvalidOptionException.new("You must set task definition") unless task_definition
|
130
142
|
raise InvalidOptionException.new("You must set container") unless container
|
143
|
+
raise InvalidOptionException.new("Invalid rule state. Possible values are #{POSSIBLE_RULE_STATES.join(", ")}") unless POSSIBLE_RULE_STATES.include?(rule_state)
|
131
144
|
end
|
132
145
|
|
133
146
|
private
|
@@ -1,17 +1,16 @@
|
|
1
1
|
module ElasticWhenever
|
2
2
|
class Task
|
3
3
|
class Role
|
4
|
-
NAME = "ecsEventsRole"
|
5
|
-
|
6
4
|
def initialize(option)
|
7
5
|
client = Aws::IAM::Client.new(option.aws_config)
|
8
6
|
@resource = Aws::IAM::Resource.new(client: client)
|
9
|
-
@
|
7
|
+
@role_name = option.iam_role
|
8
|
+
@role = resource.role(@role_name)
|
10
9
|
end
|
11
10
|
|
12
11
|
def create
|
13
12
|
@role = resource.create_role(
|
14
|
-
role_name:
|
13
|
+
role_name: @role_name,
|
15
14
|
assume_role_policy_document: role_json,
|
16
15
|
)
|
17
16
|
role.attach_policy(
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module ElasticWhenever
|
2
2
|
class Task
|
3
3
|
class Rule
|
4
|
+
attr_reader :option
|
4
5
|
attr_reader :name
|
5
6
|
attr_reader :expression
|
7
|
+
attr_reader :description
|
6
8
|
|
7
9
|
class UnsupportedOptionException < StandardError; end
|
8
10
|
|
@@ -13,6 +15,8 @@ module ElasticWhenever
|
|
13
15
|
option,
|
14
16
|
name: rule.name,
|
15
17
|
expression: rule.schedule_expression,
|
18
|
+
description: rule.description,
|
19
|
+
client: client
|
16
20
|
)
|
17
21
|
end
|
18
22
|
end
|
@@ -20,22 +24,31 @@ module ElasticWhenever
|
|
20
24
|
def self.convert(option, task)
|
21
25
|
self.new(
|
22
26
|
option,
|
23
|
-
name: rule_name(option.identifier, task.commands),
|
24
|
-
expression: task.expression
|
27
|
+
name: rule_name(option.identifier, task.expression, task.commands),
|
28
|
+
expression: task.expression,
|
29
|
+
description: rule_description(option.identifier, task.expression, task.commands)
|
25
30
|
)
|
26
31
|
end
|
27
32
|
|
28
|
-
def initialize(option, name:, expression:)
|
33
|
+
def initialize(option, name:, expression:, description:, client: nil)
|
34
|
+
@option = option
|
29
35
|
@name = name
|
30
36
|
@expression = expression
|
31
|
-
@
|
37
|
+
@description = description
|
38
|
+
if client != nil
|
39
|
+
@client = client
|
40
|
+
else
|
41
|
+
@client = Aws::CloudWatchEvents::Client.new(option.aws_config)
|
42
|
+
end
|
32
43
|
end
|
33
44
|
|
34
45
|
def create
|
46
|
+
# See https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_PutRule.html#API_PutRule_RequestSyntax
|
35
47
|
client.put_rule(
|
36
48
|
name: name,
|
37
49
|
schedule_expression: expression,
|
38
|
-
|
50
|
+
description: truncate(description, 512),
|
51
|
+
state: option.rule_state,
|
39
52
|
)
|
40
53
|
end
|
41
54
|
|
@@ -47,8 +60,16 @@ module ElasticWhenever
|
|
47
60
|
|
48
61
|
private
|
49
62
|
|
50
|
-
def self.rule_name(identifier, commands)
|
51
|
-
"#{identifier}_#{Digest::SHA1.hexdigest(commands.map { |command| command.join("-") }.join("-"))}"
|
63
|
+
def self.rule_name(identifier, expression, commands)
|
64
|
+
"#{identifier}_#{Digest::SHA1.hexdigest([expression, commands.map { |command| command.join("-") }.join("-")].join("-"))}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.rule_description(identifier, expression, commands)
|
68
|
+
"#{identifier} - #{expression} - #{commands.map { |command| command.join(" ") }.join(" - ")}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def truncate(string, max)
|
72
|
+
string.length > max ? string[0...max] : string
|
52
73
|
end
|
53
74
|
|
54
75
|
attr_reader :client
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic_whenever
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuma Watanabe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,9 +130,9 @@ executables:
|
|
130
130
|
extensions: []
|
131
131
|
extra_rdoc_files: []
|
132
132
|
files:
|
133
|
+
- ".github/workflows/build.yml"
|
133
134
|
- ".gitignore"
|
134
135
|
- ".rspec"
|
135
|
-
- ".travis.yml"
|
136
136
|
- CHANGELOG.md
|
137
137
|
- Gemfile
|
138
138
|
- LICENSE.txt
|
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: '0'
|
174
174
|
requirements: []
|
175
|
-
rubygems_version: 3.
|
175
|
+
rubygems_version: 3.1.2
|
176
176
|
signing_key:
|
177
177
|
specification_version: 4
|
178
178
|
summary: Manage ECS Scheduled Tasks like Whenever
|