souls 1.16.1 → 1.17.0

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: 519f43da77592c6ab41222c6d6360c4714956a798eadc81ca366348728671bad
4
- data.tar.gz: 112fba381d121ee4d6ea7cc553135ac3a75e99d2599b394c193c7eff24491f03
3
+ metadata.gz: f4cc729425eab2ed36694f36ccf139073767e24704cf28ca9aacf29667e1eb3e
4
+ data.tar.gz: 6966f1f77c229a66e38b8cf3466ae7677f0c56256094871b659bf1cee6f8e694
5
5
  SHA512:
6
- metadata.gz: 4b87c00166c78b696858f3d1f5fee6a9efa9cf04423d8468b7a6f19e28a312170de538770b06655c747674b3792adf4b2f5040593cf153f2f76683a31f02d4ce
7
- data.tar.gz: 615cb63fb293900589e113d418d5af710a9e34cf55494f76b287b2b597e64ff769c61af03582a63b58ed1315caa4e1192f5cb4d704bbc25daa545129cd898a45
6
+ metadata.gz: 79ee3df57517aa7342591da910fe7b853bde51819070cb4c0aae49c972e3500b194f50ccf1b3e8e33f36af733503c5a6c8d7217698a7809f76a5125ed5ac1e9a
7
+ data.tar.gz: fdeb3916a7cd4449254fe9c0e2d4d76fe627c8784af93b1d9ce6ada36b1fb1f061b22bf2aa39cbb24724534340588cecb145b09f32bb761543a267457f86107c
@@ -6,7 +6,7 @@ end
6
6
 
7
7
  module Souls
8
8
  class Create < Thor
9
- desc "functions", "Create SOULs functions"
9
+ desc "functions [name]", "Create SOULs functions"
10
10
  def functions(function_name)
11
11
  supported_languages = {
12
12
  ruby: %w[2.6 2.7],
@@ -1,36 +1,36 @@
1
1
  require_relative "./functions"
2
2
  module Souls
3
3
  class Create < Thor
4
- desc "worker", "Create SOULs Worker"
5
- method_option :name, aliases: "--name", desc: "Worker Name", required: true
6
- def worker
4
+ desc "worker [name]", "Create SOULs Worker"
5
+ def worker(name)
7
6
  require("#{Souls.get_mother_path}/config/souls")
8
7
  Dir.chdir(Souls.get_mother_path.to_s) do
9
- file_dir = "apps/#{options[:name]}"
8
+ worker_name = "worker-#{name}"
9
+ file_dir = "apps/worker-#{name}"
10
10
  raise(StandardError, "Same Worker Already Exist!") if Dir.exist?(file_dir)
11
11
 
12
12
  workers = Souls.configuration.workers
13
13
  app = Souls.configuration.app
14
14
  port = 3000 + workers.size
15
- souls_worker_name = "souls-#{app}-#{options[:name]}"
16
- download_worker(worker_name: options[:name])
15
+ souls_worker_name = "souls-#{app}-#{worker_name}"
16
+ download_worker(worker_name: worker_name)
17
17
  souls_conf_update(worker_name: souls_worker_name)
18
18
  souls_conf_update(worker_name: souls_worker_name, strain: "api")
19
- workflow(worker_name: options[:name])
20
- procfile(worker_name: options[:name], port: port)
21
- mother_procfile(worker_name: options[:name])
22
- souls_config_init(worker_name: options[:name])
23
- steepfile(worker_name: options[:name])
24
- souls_helper_rbs(worker_name: options[:name])
25
- system("cd apps/#{options[:name]} && bundle")
26
- souls_worker_credit(worker_name: options[:name])
19
+ workflow(worker_name: worker_name)
20
+ procfile(worker_name: worker_name, port: port)
21
+ mother_procfile(worker_name: worker_name)
22
+ souls_config_init(worker_name: worker_name)
23
+ steepfile(worker_name: worker_name)
24
+ souls_helper_rbs(worker_name: worker_name)
25
+ system("cd #{file_dir} && bundle")
26
+ souls_worker_credit(worker_name: worker_name)
27
27
  end
28
28
  true
29
29
  end
30
30
 
31
31
  private
32
32
 
33
- def steepfile(worker_name: "mailer")
33
+ def steepfile(worker_name: "worker-mailer")
34
34
  file_path = "./Steepfile"
35
35
 
36
36
  write_txt = ""
@@ -49,21 +49,21 @@ module Souls
49
49
  File.open(file_path, "w") { |f| f.write(write_txt) }
50
50
  end
51
51
 
52
- def procfile(worker_name: "mailer", port: 123)
52
+ def procfile(worker_name: "worker-mailer", port: 123)
53
53
  file_path = "apps/#{worker_name}/Procfile.dev"
54
54
  File.open(file_path, "w") do |f|
55
55
  f.write("#{worker_name}: bundle exec puma -p #{port} -e development")
56
56
  end
57
57
  end
58
58
 
59
- def mother_procfile(worker_name: "mailer")
59
+ def mother_procfile(worker_name: "worker-mailer")
60
60
  file_path = "Procfile.dev"
61
61
  File.open(file_path, "a") do |f|
62
62
  f.write("\n#{worker_name}: foreman start -f ./apps/#{worker_name}/Procfile.dev")
63
63
  end
64
64
  end
65
65
 
66
- def souls_conf_update(worker_name: "mailer", strain: "mother")
66
+ def souls_conf_update(worker_name: "worker-mailer", strain: "mother")
67
67
  workers = Souls.configuration.workers
68
68
  port = 3000 + workers.size
69
69
  file_path = strain == "mother" ? "config/souls.rb" : "apps/api/config/souls.rb"
@@ -84,7 +84,6 @@ module Souls
84
84
  write_txt += <<-TEXT
85
85
  {
86
86
  name: "#{worker[:name]}",
87
- endpoint: "#{worker[:endpoint]}",
88
87
  port: #{worker[:port]}
89
88
  },
90
89
  TEXT
@@ -95,7 +94,6 @@ module Souls
95
94
  write_txt += <<-TEXT
96
95
  {
97
96
  name: "#{worker_name}",
98
- endpoint: "",
99
97
  port: #{port}
100
98
  }
101
99
  ]
@@ -105,12 +103,11 @@ end
105
103
  File.open(file_path, "w") { |f| f.write(write_txt) }
106
104
  end
107
105
 
108
- def workflow(worker_name: "mailer")
106
+ def workflow(worker_name: "worker-mailer")
109
107
  file_dir = ".github/workflows"
110
108
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
111
109
  file_path = "#{file_dir}/#{worker_name}.yml"
112
- worker_name = worker_name.underscore
113
- worker_name_camelize = worker_name.camelize
110
+ worker_name_camelize = worker_name.gsub("-", "_").camelize
114
111
  File.open(file_path, "w") do |f|
115
112
  f.write(<<~TEXT)
116
113
  name: #{worker_name_camelize}
@@ -176,6 +173,9 @@ end
176
173
  - name: Sync Tasks
177
174
  run: cd apps/#{worker_name} && souls gcloud scheduler sync_schedules --timezone=${{ secrets.TZ }}
178
175
 
176
+ - name: Sync PubSub
177
+ run: cd apps/#{worker_name} && souls sync pubsub
178
+
179
179
  - name: Configure Docker
180
180
  run: gcloud auth configure-docker --quiet
181
181
 
@@ -210,7 +210,7 @@ end
210
210
  file_path
211
211
  end
212
212
 
213
- def souls_config_init(worker_name: "mailer")
213
+ def souls_config_init(worker_name: "worker-mailer")
214
214
  app_name = Souls.configuration.app
215
215
  project_id = Souls.configuration.project_id
216
216
  config_dir = "apps/#{worker_name}/config"
@@ -232,7 +232,7 @@ end
232
232
  end
233
233
  end
234
234
 
235
- def souls_helper_rbs(worker_name: "mailer")
235
+ def souls_helper_rbs(worker_name: "worker-mailer")
236
236
  file_dir = "./sig/#{worker_name}/app/utils"
237
237
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
238
238
  file_path = "#{file_dir}/souls_helper.rbs"
@@ -273,7 +273,7 @@ end
273
273
  end
274
274
  end
275
275
 
276
- def download_worker(worker_name: "mailer")
276
+ def download_worker(worker_name: "worker-mailer")
277
277
  version = Souls.get_latest_version_txt(service_name: "worker").join(".")
278
278
  file_name = "worker-v#{version}.tgz"
279
279
  url = "https://storage.googleapis.com/souls-bucket/boilerplates/workers/#{file_name}"
@@ -285,7 +285,7 @@ end
285
285
  FileUtils.rm_f(file_name)
286
286
  end
287
287
 
288
- def souls_worker_credit(worker_name: "mailer")
288
+ def souls_worker_credit(worker_name: "worker-mailer")
289
289
  line = Paint["====================================", :yellow]
290
290
  puts("\n")
291
291
  puts(line)
@@ -1,6 +1,6 @@
1
1
  module Template
2
2
  module Ruby
3
- def self.index(file_name)
3
+ def self.app(file_name)
4
4
  <<~APP
5
5
  require "functions_framework"
6
6
  require "sinatra/base"
@@ -3,6 +3,7 @@ module Souls
3
3
  desc "deploy", "Deploy Cloud Functions"
4
4
  def deploy
5
5
  require(Souls.get_mother_path.to_s + "/config/souls")
6
+ project_id = Souls.configuration.project_id
6
7
  current_dir = FileUtils.pwd.split("/").last
7
8
  unless current_dir.match?(/^cf_/)
8
9
  Souls::Painter.error("You are at wrong dir!\nPlease go to `apps/functions` dir!")
@@ -25,6 +26,17 @@ module Souls
25
26
  system("gcloud functions describe souls_functions --project=#{project_id}")
26
27
  end
27
28
 
29
+ desc "delete", "Delete SOULs Functions"
30
+ def delete(name)
31
+ require(Souls.get_mother_path.to_s + "/config/souls")
32
+ project_id = Souls.configuration.project_id
33
+ system("gcloud functions delete #{name} --project=#{project_id}")
34
+ Dir.chdir(Souls.get_mother_path.to_s) do
35
+ FileUtils.rm_rf("apps/#{name}")
36
+ end
37
+ Souls::Painter.success("Deleted #{name} functions!")
38
+ end
39
+
28
40
  desc "url", "Get SOULs Functions URL"
29
41
  def url
30
42
  require(Souls.get_mother_path.to_s + "/config/souls")
@@ -89,8 +89,7 @@ module Souls
89
89
 
90
90
  def update_workers_env(key:, value:, dqm: false)
91
91
  Dir.chdir(Souls.get_mother_path.to_s) do
92
- workers = Dir["apps/*"]
93
- workers.delete("apps/api")
92
+ workers = Dir["apps/worker-*"]
94
93
  workers.each do |worker_path|
95
94
  file_path = "#{worker_path}/.env"
96
95
  File.open(file_path, "a") do |line|
@@ -1,37 +1,38 @@
1
1
  module Souls
2
2
  class Sync < Thor
3
- desc "pubsub", "Sync Worker Jobs & Google Cloud Pubsub Subscriptions"
3
+ desc "pubsub", "Sync Worker Jobs & Google Cloud Pubsub Topics/Subscriptions"
4
4
  def pubsub
5
- get_worker_endpoints
6
- Souls::Gcloud.new.config_set
7
- get_topics(workers: get_workers)
5
+ worker_name = FileUtils.pwd.split("/").last
6
+
7
+ unless worker_name.match(/^worker-(\d|\w)+(-)*(\d|\w)+$/)
8
+ Souls::Painter.error("You are at wrong dir!\nPlease go to worker-* dir!")
9
+ return false
10
+ end
11
+
12
+ url = `gcloud run services list |grep souls-#{project_id}-#{worker_name}| awk '{print $4}'`.strip
13
+ return false if url.blank?
14
+
15
+ worker_file_names = get_workers_file_paths
16
+ return false if worker_file_names.blank?
17
+
18
+ sync_pubsub_topics_and_subscriptions(workers: worker_file_names, worker_url: url)
8
19
  Souls::Painter.sync("All Jobs with PubSub Subscription!")
9
20
  end
10
21
 
11
22
  private
12
23
 
13
- def get_worker_endpoints
14
- require("#{Souls.get_mother_path}/config/souls")
15
- worker_paths = Souls.configuration.workers
16
- worker_paths.each do |worker|
17
- endpoint = worker[:endpoint]
18
- unless endpoint.include?("https://")
19
- raise(StandardError, "You need to set endpoint.\nPlease Run:\n\n$ souls sync conf\n\n")
20
- end
21
- end
22
- end
23
-
24
- def get_topics(workers: {})
24
+ def sync_pubsub_topics_and_subscriptions(worker_url:, workers: {})
25
25
  project_id = Souls.configuration.project_id
26
26
  pubsub = Google::Cloud::Pubsub.new(project_id: project_id)
27
27
  topics = pubsub.topics
28
+ worker_name = FileUtils.pwd.split("/").last
28
29
 
29
30
  topic_names =
30
31
  topics.map do |topic|
31
32
  topic.name.gsub("projects/#{project_id}/topics/", "")
32
33
  end
33
34
 
34
- souls_topics = topic_names.select { |n| n.include?("souls_") }
35
+ souls_topics = topic_names.select { |n| n.include?("souls-#{worker_name}") }
35
36
 
36
37
  souls_topics.each do |name|
37
38
  value = workers[name.to_sym] || 0
@@ -39,24 +40,25 @@ module Souls
39
40
  end
40
41
 
41
42
  workers.each do |key, value|
43
+ topic_id = key.to_s.gsub("_", "-")
42
44
  if value == 1
43
- create_topic(topic_id: key.to_s)
44
- create_push_subscription(topic_id: key.to_s)
45
+ create_topic(topic_id: topic_id)
46
+ create_push_subscription(worker_url: worker_url, topic_id: topic_id)
45
47
  end
46
- delete_topic(topic_id: key.to_s) if value == -1
47
- delete_subscription(topic_id: key.to_s) if value == -1
48
+ delete_topic(topic_id: topic_id) if value == -1
49
+ delete_subscription(topic_id: topic_id) if value == -1
48
50
  end
49
51
  workers
50
52
  end
51
53
 
52
- def create_topic(topic_id: "mailer")
54
+ def create_topic(topic_id: "worker-mailer")
53
55
  project_id = Souls.configuration.project_id
54
56
  pubsub = Google::Cloud::Pubsub.new(project_id: project_id)
55
57
  topic = pubsub.create_topic(topic_id.to_s)
56
58
  puts("Topic #{topic.name} created.")
57
59
  end
58
60
 
59
- def delete_topic(topic_id: "mailer")
61
+ def delete_topic(topic_id: "worker-mailer")
60
62
  project_id = Souls.configuration.project_id
61
63
  pubsub = Google::Cloud::Pubsub.new(project_id: project_id)
62
64
  topic = pubsub.topic(topic_id.to_s)
@@ -64,25 +66,18 @@ module Souls
64
66
  puts("Topic #{topic_id} deleted.")
65
67
  end
66
68
 
67
- def delete_subscription(topic_id: "mailer")
69
+ def delete_subscription(topic_id: "worker-mailer")
68
70
  project_id = Souls.configuration.project_id
69
71
  pubsub = Google::Cloud::Pubsub.new(project_id: project_id)
70
- subscription_id = "#{topic_id}_sub"
72
+ subscription_id = "#{topic_id}-sub"
71
73
  subscription = pubsub.subscription(subscription_id)
72
74
  subscription.delete
73
75
  end
74
76
 
75
- def create_push_subscription(topic_id: "mailer")
76
- app = Souls.configuration.app
77
- require("#{Souls.get_mother_path}/config/souls")
78
- worker_name = topic_id.split("_")[1]
79
-
80
- subscription_id = "#{topic_id}_sub"
81
- endpoint = ""
82
- worker_paths = Souls.configuration.workers
83
- worker_paths.each do |worker|
84
- endpoint = worker[:endpoint] if worker[:name] == "souls-#{app}-#{worker_name}"
85
- end
77
+ def create_push_subscription(worker_url:, topic_id: "worker-mailer")
78
+ souls_endpoint = Souls.configuration.endpoint
79
+ subscription_id = "#{topic_id}-sub"
80
+ endpoint = "#{worker_url}/#{souls_endpoint}"
86
81
 
87
82
  project_id = Souls.configuration.project_id
88
83
  pubsub = Google::Cloud::Pubsub.new(project_id: project_id)
@@ -93,21 +88,16 @@ module Souls
93
88
  puts("Push subscription #{subscription_id} created.")
94
89
  end
95
90
 
96
- def get_workers
97
- require("#{Souls.get_mother_path}/config/souls")
98
- worker_paths = Souls.configuration.workers.map { |n| n[:name].split("-").last }
91
+ def get_workers_file_paths
92
+ worker_name = FileUtils.pwd.split("/").last
99
93
  response = {}
100
- Dir.chdir(Souls.get_mother_path.to_s) do
101
- worker_paths.each do |worker|
102
- workers =
103
- Dir["apps/#{worker}/app/graphql/queries/*.rb"].map do |file|
104
- file.gsub("apps/#{worker}/app/graphql/queries/", "").gsub(".rb", "")
105
- end
106
- workers.delete("base_query")
107
- workers.each do |file|
108
- response[:"souls_#{worker}_#{file}"] = 1
109
- end
94
+ workers =
95
+ Dir["app/graphql/queries/*.rb"].map do |file|
96
+ file.split("/").last.gsub(".rb", "")
110
97
  end
98
+ workers.delete("base_query")
99
+ workers.each do |file|
100
+ response[:"souls_#{worker_name}_#{file}"] = 1
111
101
  end
112
102
  response
113
103
  end
data/lib/souls/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Souls
2
- VERSION = "1.16.1".freeze
2
+ VERSION = "1.17.0".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 1.16.1
1
+ 1.17.0
@@ -1 +1 @@
1
- 1.16.1
1
+ 1.17.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: souls
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.1
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2022-01-03 00:00:00.000000000 Z
13
+ date: 2022-01-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -183,8 +183,8 @@ files:
183
183
  - lib/souls/cli/create/templates/nodejs/package.rb
184
184
  - lib/souls/cli/create/templates/python/main.rb
185
185
  - lib/souls/cli/create/templates/python/requirements.rb
186
+ - lib/souls/cli/create/templates/ruby/app.rb
186
187
  - lib/souls/cli/create/templates/ruby/gemfile.rb
187
- - lib/souls/cli/create/templates/ruby/index.rb
188
188
  - lib/souls/cli/db/create_migration.rb
189
189
  - lib/souls/cli/db/create_migration_rbs.rb
190
190
  - lib/souls/cli/db/index.rb