gcp_scheduler 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/rspec.yml +28 -0
- data/.gitignore +56 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +114 -0
- data/MIT-LICENSE +21 -0
- data/README.md +76 -0
- data/Rakefile +7 -0
- data/exe/gcp_scheduler +6 -0
- data/gcp_scheduler.gemspec +26 -0
- data/lib/gcp_scheduler/cli.rb +59 -0
- data/lib/gcp_scheduler/command.rb +43 -0
- data/lib/gcp_scheduler/scheduler.rb +57 -0
- data/lib/gcp_scheduler.rb +30 -0
- data/spec/fixtures/scheduler.yml +2 -0
- data/spec/gcp_scheduler/scheduler_spec.rb +11 -0
- data/spec/gcp_scheduler_spec.rb +7 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/path.rb +13 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 62cbc3423620cda69674fa0d2b0d84eba999a2b9b7c4644770461721d798e6b7
|
4
|
+
data.tar.gz: 237263736fd1e7786d65749bf0a3d4b297ee045ad37371a704ac08ae23c0de59
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e3431c095b0806934a1288c5f0e781037f38bc0890e394e5b9ed8aabb01ab1573abfa01016474db7ed487d653446044950b12865c2ef4290817581c7388d035
|
7
|
+
data.tar.gz: 231ed0ea3846239aa1b95b34372325481a18325afa51ef9973479caa9b4c73779a8ee1a2c83e7d911386f4ab501b96328164d38c620dbeb030bc3791c87a5fa1
|
@@ -0,0 +1,28 @@
|
|
1
|
+
name: rspec
|
2
|
+
|
3
|
+
on:
|
4
|
+
workflow_dispatch:
|
5
|
+
push:
|
6
|
+
branches: [ master ]
|
7
|
+
pull_request:
|
8
|
+
branches: [ master ]
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
build:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby-version: ['3.1']
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
bundler-cache: true
|
25
|
+
- name: Install dependencies
|
26
|
+
run: bundle install
|
27
|
+
- name: Run tests
|
28
|
+
run: bundle exec rspec
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
.rubocop-https?--*
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.2
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gcp_scheduler (0.0.1)
|
5
|
+
activesupport
|
6
|
+
google-cloud-scheduler-v1 (>= 0.7.0)
|
7
|
+
thor
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (7.0.4.3)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 1.6, < 2)
|
15
|
+
minitest (>= 5.1)
|
16
|
+
tzinfo (~> 2.0)
|
17
|
+
addressable (2.8.4)
|
18
|
+
public_suffix (>= 2.0.2, < 6.0)
|
19
|
+
byebug (11.1.3)
|
20
|
+
coderay (1.1.3)
|
21
|
+
concurrent-ruby (1.2.2)
|
22
|
+
diff-lcs (1.5.0)
|
23
|
+
faraday (2.7.4)
|
24
|
+
faraday-net_http (>= 2.0, < 3.1)
|
25
|
+
ruby2_keywords (>= 0.0.4)
|
26
|
+
faraday-net_http (3.0.2)
|
27
|
+
faraday-retry (2.1.0)
|
28
|
+
faraday (~> 2.0)
|
29
|
+
gapic-common (0.18.0)
|
30
|
+
faraday (>= 1.9, < 3.a)
|
31
|
+
faraday-retry (>= 1.0, < 3.a)
|
32
|
+
google-protobuf (~> 3.14)
|
33
|
+
googleapis-common-protos (>= 1.3.12, < 2.a)
|
34
|
+
googleapis-common-protos-types (>= 1.3.1, < 2.a)
|
35
|
+
googleauth (~> 1.0)
|
36
|
+
grpc (~> 1.36)
|
37
|
+
google-cloud-errors (1.3.1)
|
38
|
+
google-cloud-location (0.4.0)
|
39
|
+
gapic-common (>= 0.17.1, < 2.a)
|
40
|
+
google-cloud-errors (~> 1.0)
|
41
|
+
google-cloud-scheduler-v1 (0.7.0)
|
42
|
+
gapic-common (>= 0.18.0, < 2.a)
|
43
|
+
google-cloud-errors (~> 1.0)
|
44
|
+
google-cloud-location (>= 0.4, < 2.a)
|
45
|
+
google-protobuf (3.22.3-x86_64-darwin)
|
46
|
+
google-protobuf (3.22.3-x86_64-linux)
|
47
|
+
googleapis-common-protos (1.4.0)
|
48
|
+
google-protobuf (~> 3.14)
|
49
|
+
googleapis-common-protos-types (~> 1.2)
|
50
|
+
grpc (~> 1.27)
|
51
|
+
googleapis-common-protos-types (1.5.0)
|
52
|
+
google-protobuf (~> 3.14)
|
53
|
+
googleauth (1.5.2)
|
54
|
+
faraday (>= 0.17.3, < 3.a)
|
55
|
+
jwt (>= 1.4, < 3.0)
|
56
|
+
memoist (~> 0.16)
|
57
|
+
multi_json (~> 1.11)
|
58
|
+
os (>= 0.9, < 2.0)
|
59
|
+
signet (>= 0.16, < 2.a)
|
60
|
+
grpc (1.54.0-x86_64-darwin)
|
61
|
+
google-protobuf (~> 3.21)
|
62
|
+
googleapis-common-protos-types (~> 1.0)
|
63
|
+
grpc (1.54.0-x86_64-linux)
|
64
|
+
google-protobuf (~> 3.21)
|
65
|
+
googleapis-common-protos-types (~> 1.0)
|
66
|
+
i18n (1.12.0)
|
67
|
+
concurrent-ruby (~> 1.0)
|
68
|
+
jwt (2.7.0)
|
69
|
+
memoist (0.16.2)
|
70
|
+
method_source (1.0.0)
|
71
|
+
minitest (5.18.0)
|
72
|
+
multi_json (1.15.0)
|
73
|
+
os (1.1.4)
|
74
|
+
pry (0.14.2)
|
75
|
+
coderay (~> 1.1)
|
76
|
+
method_source (~> 1.0)
|
77
|
+
pry-byebug (3.10.1)
|
78
|
+
byebug (~> 11.0)
|
79
|
+
pry (>= 0.13, < 0.15)
|
80
|
+
public_suffix (5.0.1)
|
81
|
+
rspec (3.12.0)
|
82
|
+
rspec-core (~> 3.12.0)
|
83
|
+
rspec-expectations (~> 3.12.0)
|
84
|
+
rspec-mocks (~> 3.12.0)
|
85
|
+
rspec-core (3.12.2)
|
86
|
+
rspec-support (~> 3.12.0)
|
87
|
+
rspec-expectations (3.12.2)
|
88
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
89
|
+
rspec-support (~> 3.12.0)
|
90
|
+
rspec-mocks (3.12.5)
|
91
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
92
|
+
rspec-support (~> 3.12.0)
|
93
|
+
rspec-support (3.12.0)
|
94
|
+
ruby2_keywords (0.0.5)
|
95
|
+
signet (0.17.0)
|
96
|
+
addressable (~> 2.8)
|
97
|
+
faraday (>= 0.17.5, < 3.a)
|
98
|
+
jwt (>= 1.5, < 3.0)
|
99
|
+
multi_json (~> 1.10)
|
100
|
+
thor (1.2.1)
|
101
|
+
tzinfo (2.0.6)
|
102
|
+
concurrent-ruby (~> 1.0)
|
103
|
+
|
104
|
+
PLATFORMS
|
105
|
+
x86_64-darwin-21
|
106
|
+
x86_64-linux
|
107
|
+
|
108
|
+
DEPENDENCIES
|
109
|
+
gcp_scheduler!
|
110
|
+
pry-byebug
|
111
|
+
rspec (~> 3.9)
|
112
|
+
|
113
|
+
BUNDLED WITH
|
114
|
+
2.5.0.dev
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Akira Kusumoto
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# gcp_scheduler
|
2
|
+
|
3
|
+
gcp_schedulerは、Google Cloud Schedulerを簡単に操作できるコマンドラインツールです。
|
4
|
+
create、list、deleteのコマンドでCloud Schedulerのジョブを追加、表示、削除できます。
|
5
|
+
|
6
|
+
## インストール
|
7
|
+
|
8
|
+
```
|
9
|
+
gem install gcp_scheduler
|
10
|
+
```
|
11
|
+
|
12
|
+
## 使い方
|
13
|
+
|
14
|
+
以下のコマンド例を参考にして、CLIを使用してください。
|
15
|
+
|
16
|
+
各コマンドは認証情報を下記のように環境変数で設定してある状態で実行する必要があります。
|
17
|
+
|
18
|
+
```
|
19
|
+
export GOOGLE_APPLICATION_CREDENTIALS=your_credential.json
|
20
|
+
```
|
21
|
+
|
22
|
+
### ジョブの作成
|
23
|
+
|
24
|
+
```
|
25
|
+
gcp_scheduler create --gcp_project your_project_name --scheduler_file path/to/scheduler.yml --uri https://your_domain.example.com --prefix development- --region asia-northeast1 --secret your_secret_token
|
26
|
+
```
|
27
|
+
|
28
|
+
- scheduler_fileを元にジョブを作成します。
|
29
|
+
- prefixは、ジョブ名に付与されるプレフィックスです。
|
30
|
+
- regionは、Cloud Schedulerのリージョンです。
|
31
|
+
- uriは、スケジューラーがHTTP POSTを実行するURLです。
|
32
|
+
- すべてのジョブは一つのURLにapplication/jsonでリクエストパラメータのjob_nameにscheduler_fileのjob名が入ります。
|
33
|
+
- secretは、Http Authorization Header Bearer tokenです。
|
34
|
+
|
35
|
+
### ジョブの一覧表示
|
36
|
+
|
37
|
+
```
|
38
|
+
gcp_scheduler list --gcp_project your_project_name --prefix development- --region asia-northeast1
|
39
|
+
```
|
40
|
+
|
41
|
+
### ジョブの削除
|
42
|
+
|
43
|
+
```
|
44
|
+
gcp_scheduler delete --gcp_project your_project_name --prefix development- --region asia-northeast1
|
45
|
+
```
|
46
|
+
|
47
|
+
- prefixで指定した文字列から始まるジョブ名のジョブをすべて削除します。
|
48
|
+
|
49
|
+
## コマンドオプション
|
50
|
+
|
51
|
+
| Option | Description |
|
52
|
+
|---|-------------------------------------------------------------------------------------------|
|
53
|
+
| `--gcp_project` | Google Cloud project name |
|
54
|
+
| `--scheduler_file` | Path to the scheduler configuration file (used with `create` command) |
|
55
|
+
| `--uri` | URL of the endpoint to be executed by the job (used with `create` command) |
|
56
|
+
| `--prefix` | Prefix for the job name (used with `create`, `list`, and `delete` commands) |
|
57
|
+
| `--region` | Cloud Scheduler region |
|
58
|
+
| `--secret` | Http Authorization Header Bearer token to be sent by the job (used with `create` command) |
|
59
|
+
|
60
|
+
## scheduler.yml file
|
61
|
+
|
62
|
+
scheduler.ymlファイルは、ジョブのスケジュール情報を定義するために使用されます。以下は、scheduler.ymlファイルのサンプルです。
|
63
|
+
|
64
|
+
```yaml
|
65
|
+
weekly_job:
|
66
|
+
cron: '0 9 * * 1'
|
67
|
+
```
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bluerabbit/gcp_scheduler.
|
72
|
+
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/exe/gcp_scheduler
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path("lib", __dir__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "gcp_scheduler"
|
5
|
+
s.version = "0.0.1"
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.authors = ["Akira Kusumoto"]
|
8
|
+
s.email = ["akirakusumo10@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/bluerabbit/gcp_scheduler"
|
10
|
+
s.summary = "A command-line interface for managing Google Cloud Scheduler jobs with ease"
|
11
|
+
s.description = "GCP Scheduler CLI is a Ruby gem that provides a simple command-line interface for managing Google Cloud Scheduler jobs. With this tool, you can create, list, and delete Cloud Scheduler jobs using intuitive commands. It streamlines job management tasks by allowing you to define job schedules in a YAML file and supports custom job prefixes, regions, and authentication tokens."
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
s.licenses = ["MIT"]
|
16
|
+
|
17
|
+
s.bindir = "exe"
|
18
|
+
s.executables = s.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
19
|
+
s.add_runtime_dependency "thor"
|
20
|
+
|
21
|
+
s.add_dependency "activesupport"
|
22
|
+
s.add_dependency "google-cloud-scheduler-v1", [">= 0.7.0"]
|
23
|
+
s.add_development_dependency "pry-byebug"
|
24
|
+
s.add_development_dependency "rspec", "~> 3.9"
|
25
|
+
s.metadata["rubygems_mfa_required"] = "true"
|
26
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "active_support/all"
|
2
|
+
require "thor"
|
3
|
+
require "gcp_scheduler"
|
4
|
+
|
5
|
+
# require environment variables for GCP API
|
6
|
+
# export GOOGLE_APPLICATION_CREDENTIALS=credential.json
|
7
|
+
module GcpScheduler
|
8
|
+
class Cli < Thor
|
9
|
+
def self.exit_on_failure?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
default_command :list
|
14
|
+
|
15
|
+
desc "list", "Show schedules"
|
16
|
+
method_option :gcp_project, type: :string, required: true
|
17
|
+
method_option :region, type: :string, default: "asia-northeast1"
|
18
|
+
method_option :prefix, type: :string, default: ""
|
19
|
+
def list
|
20
|
+
GcpScheduler.list(gcp_project: options[:gcp_project],
|
21
|
+
region: options[:region],
|
22
|
+
prefix: options[:prefix])
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "delete", "Delete schedules"
|
26
|
+
method_option :gcp_project, type: :string, required: true
|
27
|
+
method_option :region, type: :string, default: "asia-northeast1"
|
28
|
+
method_option :prefix, type: :string, default: ""
|
29
|
+
def delete
|
30
|
+
GcpScheduler.delete(gcp_project: options[:gcp_project],
|
31
|
+
region: options[:region],
|
32
|
+
prefix: options[:prefix])
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "create", "Create schedules from scheduler.yml"
|
36
|
+
method_option :gcp_project, type: :string, required: true
|
37
|
+
method_option :region, type: :string, default: "asia-northeast1"
|
38
|
+
method_option :prefix, type: :string, default: ""
|
39
|
+
method_option :scheduler_file, type: :string, required: true
|
40
|
+
method_option :uri, type: :string, required: true
|
41
|
+
method_option :secret, type: :string, default: ""
|
42
|
+
method_option :time_zone, type: :string, default: "Etc/UTC"
|
43
|
+
def create
|
44
|
+
GcpScheduler.create(gcp_project: options[:gcp_project],
|
45
|
+
region: options[:region],
|
46
|
+
prefix: options[:prefix],
|
47
|
+
scheduler_file_path: options[:scheduler_file],
|
48
|
+
uri: options[:uri],
|
49
|
+
secret: options[:secret],
|
50
|
+
time_zone: options[:time_zone])
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "version", "Show Version"
|
54
|
+
|
55
|
+
def version
|
56
|
+
say "Version: #{GcpScheduler::VERSION}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module GcpScheduler
|
2
|
+
class Command
|
3
|
+
class << self
|
4
|
+
def list(gcp_project:, region:, prefix: "")
|
5
|
+
scheduler = Scheduler.new(project: gcp_project, location: region)
|
6
|
+
scheduler.jobs.each do |job|
|
7
|
+
scheduler_name = job.name.split("/").last
|
8
|
+
next unless scheduler_name.start_with?(prefix)
|
9
|
+
|
10
|
+
puts "- name:#{scheduler_name} description:#{job.description} schedule:#{job.schedule}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def delete(gcp_project:, region:, prefix: "")
|
15
|
+
scheduler = Scheduler.new(project: gcp_project, location: region)
|
16
|
+
scheduler.jobs.each do |job|
|
17
|
+
scheduler_name = job.name.split("/").last
|
18
|
+
next unless scheduler_name.start_with?(prefix)
|
19
|
+
|
20
|
+
puts "Delete #{scheduler_name}"
|
21
|
+
scheduler.delete_job(scheduler_name)
|
22
|
+
puts "Deleted #{scheduler_name}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def create(gcp_project:, region:, scheduler_file_path:, uri:, secret:, time_zone:, prefix: "")
|
27
|
+
scheduler = Scheduler.new(project: gcp_project, location: region)
|
28
|
+
Scheduler.scheduler_config(scheduler_file_path).each do |name, h|
|
29
|
+
scheduler_name = "#{prefix}#{name}"
|
30
|
+
puts "Create #{scheduler_name}"
|
31
|
+
scheduler.create_job(name: scheduler_name,
|
32
|
+
description: "#{h["class"]} CreatedAt:#{Time.current.strftime("%Y/%m/%d %-H:%M")}",
|
33
|
+
uri: uri,
|
34
|
+
schedule: h["cron"],
|
35
|
+
params: { job_name: name },
|
36
|
+
secret: secret,
|
37
|
+
time_zone: time_zone)
|
38
|
+
puts "Created #{scheduler_name}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module GcpScheduler
|
2
|
+
class Scheduler
|
3
|
+
attr_reader :parent
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def scheduler_config(file_path)
|
7
|
+
YAML.load(ERB.new(File.read(file_path)).result).with_indifferent_access
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(project:, location:)
|
12
|
+
@parent = "projects/#{project}/locations/#{location}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def client
|
16
|
+
@client ||= ::Google::Cloud::Scheduler::V1::CloudScheduler::Client.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def jobs
|
20
|
+
client.list_jobs(parent: parent).map {|job| job }
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_job(name:,
|
24
|
+
description:,
|
25
|
+
uri:,
|
26
|
+
schedule:,
|
27
|
+
secret:, time_zone:, params: {},
|
28
|
+
http_method: :POST,
|
29
|
+
headers: {})
|
30
|
+
|
31
|
+
job = {
|
32
|
+
name: "#{parent}/jobs/#{name}",
|
33
|
+
description: description,
|
34
|
+
schedule: schedule,
|
35
|
+
time_zone: time_zone,
|
36
|
+
http_target: {
|
37
|
+
uri: uri,
|
38
|
+
http_method: http_method,
|
39
|
+
body: params.to_json,
|
40
|
+
headers: headers.merge(
|
41
|
+
{
|
42
|
+
"Authorization" => "Bearer #{secret}",
|
43
|
+
"Content-Type" => "application/json",
|
44
|
+
"User-Agent" => "Google-Cloud-Scheduler",
|
45
|
+
},
|
46
|
+
),
|
47
|
+
},
|
48
|
+
}
|
49
|
+
|
50
|
+
client.create_job parent: parent, job: job
|
51
|
+
end
|
52
|
+
|
53
|
+
def delete_job(name)
|
54
|
+
client.delete_job name: "#{parent}/jobs/#{name}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "active_support/all"
|
2
|
+
require "google/cloud/scheduler/v1"
|
3
|
+
|
4
|
+
require_relative "gcp_scheduler/cli"
|
5
|
+
require_relative "gcp_scheduler/command"
|
6
|
+
require_relative "gcp_scheduler/scheduler"
|
7
|
+
|
8
|
+
module GcpScheduler
|
9
|
+
VERSION = Gem.loaded_specs["gcp_scheduler"].version.to_s
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def list(gcp_project:, region:, prefix: "")
|
13
|
+
GcpScheduler::Command.list(gcp_project: gcp_project, prefix: prefix, region: region)
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete(gcp_project:, region:, prefix: "")
|
17
|
+
GcpScheduler::Command.delete(gcp_project: gcp_project, prefix: prefix, region: region)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(gcp_project:, region:, scheduler_file_path:, uri:, secret:, time_zone:, prefix: "")
|
21
|
+
GcpScheduler::Command.create(gcp_project: gcp_project,
|
22
|
+
region: region,
|
23
|
+
prefix: prefix,
|
24
|
+
scheduler_file_path: scheduler_file_path,
|
25
|
+
uri: uri,
|
26
|
+
secret: secret,
|
27
|
+
time_zone: time_zone)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GcpScheduler::Scheduler do
|
4
|
+
describe "#scheduler_config" do
|
5
|
+
it do
|
6
|
+
path = fixture_path("scheduler.yml")
|
7
|
+
config = GcpScheduler::Scheduler.scheduler_config(path)
|
8
|
+
expect(config).to eq({ "weekly_job" => { "cron" => "0 9 * * 1" } })
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gcp_scheduler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Akira Kusumoto
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: google-cloud-scheduler-v1
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.7.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.7.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.9'
|
83
|
+
description: GCP Scheduler CLI is a Ruby gem that provides a simple command-line interface
|
84
|
+
for managing Google Cloud Scheduler jobs. With this tool, you can create, list,
|
85
|
+
and delete Cloud Scheduler jobs using intuitive commands. It streamlines job management
|
86
|
+
tasks by allowing you to define job schedules in a YAML file and supports custom
|
87
|
+
job prefixes, regions, and authentication tokens.
|
88
|
+
email:
|
89
|
+
- akirakusumo10@gmail.com
|
90
|
+
executables:
|
91
|
+
- gcp_scheduler
|
92
|
+
extensions: []
|
93
|
+
extra_rdoc_files: []
|
94
|
+
files:
|
95
|
+
- ".github/workflows/rspec.yml"
|
96
|
+
- ".gitignore"
|
97
|
+
- ".ruby-version"
|
98
|
+
- Gemfile
|
99
|
+
- Gemfile.lock
|
100
|
+
- MIT-LICENSE
|
101
|
+
- README.md
|
102
|
+
- Rakefile
|
103
|
+
- exe/gcp_scheduler
|
104
|
+
- gcp_scheduler.gemspec
|
105
|
+
- lib/gcp_scheduler.rb
|
106
|
+
- lib/gcp_scheduler/cli.rb
|
107
|
+
- lib/gcp_scheduler/command.rb
|
108
|
+
- lib/gcp_scheduler/scheduler.rb
|
109
|
+
- spec/fixtures/scheduler.yml
|
110
|
+
- spec/gcp_scheduler/scheduler_spec.rb
|
111
|
+
- spec/gcp_scheduler_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/support/path.rb
|
114
|
+
homepage: https://github.com/bluerabbit/gcp_scheduler
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata:
|
118
|
+
rubygems_mfa_required: 'true'
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubygems_version: 3.4.8
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: A command-line interface for managing Google Cloud Scheduler jobs with ease
|
138
|
+
test_files: []
|