gcp_scheduler 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45a9e2f3c9ca228ac9fa5751a87c9beba2ec73b8e38e0c2b1ef513d766178fc5
4
- data.tar.gz: 255d18bd2a649d13fc24b1103c209aeaf2c29268f3f887e5720de376192059b8
3
+ metadata.gz: 7af3f302364000fb0d985aba456e67f317d5440a88bb0fa5d8a3ca1244d88d7a
4
+ data.tar.gz: 4c9ff3b6de8d2a3a2d7fb85325ff225f4b2732b8eb25d3a83b826aad6bfce166
5
5
  SHA512:
6
- metadata.gz: 4a1a0bb5870a8fcbd739b00f394b6be7abb39b62142531383e200e5f8c2b7c2930b9bbadcbe73dc16482400de3e05898c520bdc2449c358d842aff35a4d23ee1
7
- data.tar.gz: fc388ea4d13736d703a92f7f4098918c41c8d8648b03ac96f3549f78c5a9c3377f7db7e228f9e4cece9d0636a49bc9813fbf68d20bd2574e3060f16fe45aa01c
6
+ metadata.gz: 8507df6b58fd4d850012b0bb6b07718520aa530eb16eb4f6f593a9f2dbc0eaa4a116d2ad08384e90a0c90b227a723596dc63a846bd860b9ec7cb2b995cc1eb8e
7
+ data.tar.gz: '0685803c80df3a9f6ceb7c8dcd8f4031111bc8afce323b9f1d4ac9f185337904f2d7c077a2dba2c3aa5708d9f74e3d3a31af4e5217635db79d466b1961aa1ea0'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gcp_scheduler (0.1.0)
4
+ gcp_scheduler (0.2.1)
5
5
  activesupport
6
6
  google-cloud-scheduler-v1 (>= 0.7.0)
7
7
  thor
@@ -9,7 +9,7 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (7.0.4.3)
12
+ activesupport (7.0.7.2)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 1.6, < 2)
15
15
  minitest (>= 5.1)
@@ -42,14 +42,14 @@ GEM
42
42
  gapic-common (>= 0.18.0, < 2.a)
43
43
  google-cloud-errors (~> 1.0)
44
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)
45
+ google-protobuf (3.25.2-x86_64-darwin)
46
+ google-protobuf (3.25.2-x86_64-linux)
47
47
  googleapis-common-protos (1.4.0)
48
48
  google-protobuf (~> 3.14)
49
49
  googleapis-common-protos-types (~> 1.2)
50
50
  grpc (~> 1.27)
51
- googleapis-common-protos-types (1.5.0)
52
- google-protobuf (~> 3.14)
51
+ googleapis-common-protos-types (1.11.0)
52
+ google-protobuf (~> 3.18)
53
53
  googleauth (1.5.2)
54
54
  faraday (>= 0.17.3, < 3.a)
55
55
  jwt (>= 1.4, < 3.0)
@@ -57,18 +57,18 @@ GEM
57
57
  multi_json (~> 1.11)
58
58
  os (>= 0.9, < 2.0)
59
59
  signet (>= 0.16, < 2.a)
60
- grpc (1.54.0-x86_64-darwin)
61
- google-protobuf (~> 3.21)
60
+ grpc (1.61.0-x86_64-darwin)
61
+ google-protobuf (~> 3.25)
62
62
  googleapis-common-protos-types (~> 1.0)
63
- grpc (1.54.0-x86_64-linux)
64
- google-protobuf (~> 3.21)
63
+ grpc (1.61.0-x86_64-linux)
64
+ google-protobuf (~> 3.25)
65
65
  googleapis-common-protos-types (~> 1.0)
66
- i18n (1.12.0)
66
+ i18n (1.14.1)
67
67
  concurrent-ruby (~> 1.0)
68
68
  jwt (2.7.0)
69
69
  memoist (0.16.2)
70
70
  method_source (1.0.0)
71
- minitest (5.18.0)
71
+ minitest (5.19.0)
72
72
  multi_json (1.15.0)
73
73
  os (1.1.4)
74
74
  pry (0.14.2)
@@ -103,6 +103,7 @@ GEM
103
103
 
104
104
  PLATFORMS
105
105
  x86_64-darwin-21
106
+ x86_64-darwin-22
106
107
  x86_64-linux
107
108
 
108
109
  DEPENDENCIES
data/README.md CHANGED
@@ -59,16 +59,16 @@ gcp_scheduler delete --gcp_project your_project_name --prefix development- --reg
59
59
  ```yaml
60
60
  jobs:
61
61
  - name: WeeklyJob
62
- description: "Runs every week at 9:00 a.m. Created:<%= Time.now.strftime("%Y/%m/%d %-H:%M") %>"
62
+ description: 'Runs every week at 9:00 a.m. Created:<%= Time.now.strftime("%Y/%m/%d %-H:%M") %>'
63
63
  schedule: '0 9 * * *'
64
64
  time_zone: Asia/Tokyo
65
- uri: "https://yourdomain.example.com/api/v1/jobs"
65
+ uri: https://yourdomain.example.com/api/v1/jobs
66
66
  http_method: POST
67
67
  params:
68
68
  job_name: weekly_job
69
69
  http_headers:
70
70
  Content-Type: application/json
71
- Authorization: "Bearer <%= ENV['SECRET'] %>"
71
+ Authorization: 'Bearer <%= ENV["SECRET"] %>'
72
72
  ```
73
73
 
74
74
  ## Contributing
@@ -2,7 +2,7 @@ $LOAD_PATH.push File.expand_path("lib", __dir__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "gcp_scheduler"
5
- s.version = "0.1.0"
5
+ s.version = "0.2.1"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Akira Kusumoto"]
8
8
  s.email = ["akirakusumo10@gmail.com"]
@@ -27,10 +27,9 @@ module GcpScheduler
27
27
  end
28
28
 
29
29
  def create(scheduler_file_path:, prefix: "")
30
- Scheduler.scheduler_config(scheduler_file_path)[:jobs].each do |job|
31
- scheduler_name = "#{prefix}#{job[:name]}"
32
- puts "Create #{scheduler_name}"
33
- scheduler.create_job(name: scheduler_name,
30
+ Scheduler.scheduler_config_jobs(file_path: scheduler_file_path, job_name_prefix: prefix).each do |job|
31
+ puts "Create #{job[:name]}"
32
+ scheduler.create_job(name: job[:name],
34
33
  description: job[:description],
35
34
  uri: job[:uri],
36
35
  schedule: job[:schedule],
@@ -38,7 +37,7 @@ module GcpScheduler
38
37
  params: job[:params],
39
38
  http_method: job[:http_method],
40
39
  headers: job[:http_headers])
41
- puts "Created #{scheduler_name}"
40
+ puts "Created #{job[:name]}"
42
41
  end
43
42
  end
44
43
  end
@@ -6,6 +6,13 @@ module GcpScheduler
6
6
  def scheduler_config(file_path)
7
7
  YAML.safe_load(ERB.new(File.read(file_path)).result, aliases: true).with_indifferent_access
8
8
  end
9
+
10
+ def scheduler_config_jobs(file_path:, job_name_prefix: "")
11
+ config = scheduler_config(file_path)
12
+ config[:jobs].map do |job|
13
+ (config[:defaults] || {}).merge(job.merge(name: "#{job_name_prefix}#{job[:name]}")).with_indifferent_access
14
+ end
15
+ end
9
16
  end
10
17
 
11
18
  def initialize(project:, location:)
@@ -37,11 +44,15 @@ module GcpScheduler
37
44
  http_target: {
38
45
  uri: uri,
39
46
  http_method: http_method,
40
- body: params.to_json,
47
+ body: params,
41
48
  headers: headers
42
49
  },
43
50
  }
44
51
 
52
+ if params.present? && headers["Content-Type"] == "application/json"
53
+ job[:http_target][:body] = params.to_json
54
+ end
55
+
45
56
  client.create_job parent: parent, job: job
46
57
  end
47
58
 
@@ -1,12 +1,12 @@
1
1
  jobs:
2
2
  - name: WeeklyJob
3
- description: "Runs every week at 9:00 a.m. Created:<%= Time.now.strftime("%Y/%m/%d %-H:%M") %>"
3
+ description: 'Runs every week at 9:00 a.m. Created:<%= Time.now.strftime("%Y/%m/%d %-H:%M") %>'
4
4
  schedule: '0 9 * * *'
5
5
  time_zone: Asia/Tokyo
6
- uri: "https://yourdomain.example.com/api/v1/jobs"
6
+ uri: https://yourdomain.example.com/api/v1/jobs
7
7
  http_method: POST
8
8
  params:
9
9
  job_name: weekly_job
10
10
  http_headers:
11
11
  Content-Type: application/json
12
- Authorization: "Bearer <%= ENV['SECRET'] %>"
12
+ Authorization: 'Bearer <%= ENV["SECRET"] %>'
@@ -0,0 +1,19 @@
1
+ defaults:
2
+ uri: https://yourdomain.example.com/api/v1/jobs
3
+ http_method: POST
4
+ time_zone: Asia/Tokyo
5
+ http_headers:
6
+ Authorization: 'Bearer <%= ENV["SECRET"] %>'
7
+ Content-Type: application/json
8
+
9
+ jobs:
10
+ - name: WeeklyJob
11
+ description: 'Runs every week at 9:00 a.m. Created:<%= Time.now.strftime("%Y/%m/%d %-H:%M") %>'
12
+ schedule: '0 9 * * *'
13
+ params:
14
+ job_name: weekly_job
15
+ - name: DailyJob
16
+ description: 'Runs every day at 10:30 a.m. Created:<%= Time.now.strftime("%Y/%m/%d %-H:%M") %>'
17
+ schedule: '30 10 * * *'
18
+ params:
19
+ job_name: daily_job
@@ -27,4 +27,60 @@ describe GcpScheduler::Scheduler do
27
27
  expect(job[:uri]).to eq("https://yourdomain.example.com/api/v1/jobs")
28
28
  end
29
29
  end
30
+
31
+ describe "#scheduler_config_jobs" do
32
+ before do
33
+ travel_to Time.parse("2023/4/1 11:00")
34
+ ENV["SECRET"] = "secret_key"
35
+ end
36
+
37
+ after do
38
+ travel_back
39
+ end
40
+
41
+ it "Configuration file with default settings" do
42
+ path = fixture_path("scheduler_with_defaults.yml")
43
+ jobs = GcpScheduler::Scheduler.scheduler_config_jobs(file_path: path,
44
+ job_name_prefix: "rspec-")
45
+
46
+ expect(jobs.size).to eq(2)
47
+ weekly_job = jobs.first
48
+ expect(weekly_job[:name]).to eq("rspec-WeeklyJob")
49
+ expect(weekly_job[:params]).to eq({ "job_name" => "weekly_job" })
50
+ expect(weekly_job[:description]).to eq("Runs every week at 9:00 a.m. Created:2023/04/01 11:00")
51
+ expect(weekly_job[:schedule]).to eq("0 9 * * *")
52
+
53
+ daily_job = jobs.last
54
+ expect(daily_job[:name]).to eq("rspec-DailyJob")
55
+ expect(daily_job[:params]).to eq({ "job_name" => "daily_job" })
56
+ expect(daily_job[:description]).to eq("Runs every day at 10:30 a.m. Created:2023/04/01 11:00")
57
+ expect(daily_job[:schedule]).to eq("30 10 * * *")
58
+
59
+ # defaults
60
+ jobs.each do |job|
61
+ expect(job[:uri]).to eq("https://yourdomain.example.com/api/v1/jobs")
62
+ expect(job[:http_method]).to eq("POST")
63
+ expect(job[:time_zone]).to eq("Asia/Tokyo")
64
+ http_headers = { "Authorization" => "Bearer secret_key", "Content-Type" => "application/json" }
65
+ expect(job[:http_headers]).to eq(http_headers)
66
+ end
67
+ end
68
+
69
+ it "Configuration file without default settings" do
70
+ path = fixture_path("scheduler.yml")
71
+ jobs = GcpScheduler::Scheduler.scheduler_config_jobs(file_path: path,
72
+ job_name_prefix: "rspec-")
73
+
74
+ expect(jobs.size).to eq(1)
75
+ job = jobs.first
76
+ expect(job[:name]).to eq("rspec-WeeklyJob")
77
+ expect(job[:description]).to eq("Runs every week at 9:00 a.m. Created:2023/04/01 11:00")
78
+ expect(job[:schedule]).to eq("0 9 * * *")
79
+ expect(job[:time_zone]).to eq("Asia/Tokyo")
80
+ expect(job[:uri]).to eq("https://yourdomain.example.com/api/v1/jobs")
81
+ expect(job[:http_method]).to eq("POST")
82
+ expect(job[:params]).to eq({ "job_name" => "weekly_job" })
83
+ expect(job[:http_headers]).to eq("Authorization" => "Bearer secret_key", "Content-Type" => "application/json")
84
+ end
85
+ end
30
86
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcp_scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Kusumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-21 00:00:00.000000000 Z
11
+ date: 2024-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -106,6 +106,7 @@ files:
106
106
  - lib/gcp_scheduler/command.rb
107
107
  - lib/gcp_scheduler/scheduler.rb
108
108
  - spec/fixtures/scheduler.yml
109
+ - spec/fixtures/scheduler_with_defaults.yml
109
110
  - spec/gcp_scheduler/scheduler_spec.rb
110
111
  - spec/gcp_scheduler_spec.rb
111
112
  - spec/spec_helper.rb
@@ -130,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
131
  - !ruby/object:Gem::Version
131
132
  version: '0'
132
133
  requirements: []
133
- rubygems_version: 3.4.8
134
+ rubygems_version: 3.4.22
134
135
  signing_key:
135
136
  specification_version: 4
136
137
  summary: A command-line interface for managing Google Cloud Scheduler jobs with ease