souls 0.51.1 → 0.52.2

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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -1
  3. data/exe/souls +3 -200
  4. data/lib/souls/api/generate/application.rb +97 -94
  5. data/lib/souls/api/generate/connection.rb +5 -4
  6. data/lib/souls/api/generate/edge.rb +5 -4
  7. data/lib/souls/api/generate/index.rb +0 -1
  8. data/lib/souls/api/generate/manager.rb +9 -7
  9. data/lib/souls/api/generate/model.rb +16 -18
  10. data/lib/souls/api/generate/mutation.rb +217 -218
  11. data/lib/souls/api/generate/policy.rb +5 -5
  12. data/lib/souls/api/generate/query.rb +51 -51
  13. data/lib/souls/api/generate/resolver.rb +115 -115
  14. data/lib/souls/api/generate/rspec_factory.rb +53 -53
  15. data/lib/souls/api/generate/rspec_model.rb +5 -5
  16. data/lib/souls/api/generate/rspec_mutation.rb +178 -178
  17. data/lib/souls/api/generate/rspec_policy.rb +5 -5
  18. data/lib/souls/api/generate/rspec_query.rb +111 -111
  19. data/lib/souls/api/generate/rspec_resolver.rb +163 -163
  20. data/lib/souls/api/generate/type.rb +66 -66
  21. data/lib/souls/api/index.rb +7 -4
  22. data/lib/souls/api/update/index.rb +15 -0
  23. data/lib/souls/api/update/mutation.rb +68 -64
  24. data/lib/souls/api/update/resolver.rb +59 -60
  25. data/lib/souls/api/update/rspec_factory.rb +40 -39
  26. data/lib/souls/api/update/rspec_mutation.rb +84 -83
  27. data/lib/souls/api/update/rspec_resolver.rb +70 -69
  28. data/lib/souls/api/update/type.rb +39 -38
  29. data/lib/souls/cli/console/index.rb +13 -1
  30. data/lib/souls/cli/create/index.rb +98 -94
  31. data/lib/souls/cli/db/index.rb +122 -1
  32. data/lib/souls/cli/docker/index.rb +30 -38
  33. data/lib/souls/cli/gcloud/compute/index.rb +100 -98
  34. data/lib/souls/cli/gcloud/iam/index.rb +84 -69
  35. data/lib/souls/cli/gcloud/index.rb +36 -35
  36. data/lib/souls/cli/gcloud/pubsub/subscriptions.rb +40 -27
  37. data/lib/souls/cli/gcloud/pubsub/topics.rb +16 -10
  38. data/lib/souls/cli/gcloud/run/index.rb +23 -17
  39. data/lib/souls/cli/gcloud/sql/index.rb +66 -47
  40. data/lib/souls/cli/index.rb +3 -20
  41. data/lib/souls/cli/init/index.rb +140 -140
  42. data/lib/souls/cli/release/release.rb +106 -105
  43. data/lib/souls/cli/server/index.rb +12 -1
  44. data/lib/souls/cli/sync/conf.rb +39 -38
  45. data/lib/souls/cli/sync/model.rb +19 -20
  46. data/lib/souls/cli/sync/pubsub.rb +69 -70
  47. data/lib/souls/cli/upgrade/gemfile.rb +108 -0
  48. data/lib/souls/cli/upgrade/index.rb +1 -1
  49. data/lib/souls/cli.rb +57 -0
  50. data/lib/souls/index.rb +1 -5
  51. data/lib/souls/version.rb +1 -1
  52. data/lib/souls/versions/.souls_api_version +1 -1
  53. data/lib/souls/versions/.souls_worker_version +1 -1
  54. data/lib/souls/worker/generate/index.rb +1 -1
  55. data/lib/souls/worker/generate/job.rb +45 -0
  56. data/lib/souls/worker/generate/mailer.rb +38 -43
  57. data/lib/souls/worker/index.rb +3 -1
  58. data/lib/souls.rb +2 -0
  59. metadata +19 -5
  60. data/lib/souls/api/generate/migration.rb +0 -51
  61. data/lib/souls/cli/upgrade/gem_update.rb +0 -107
  62. data/lib/souls/worker/generate/mutation.rb +0 -44
@@ -1,127 +1,128 @@
1
1
  module Souls
2
- module Release
3
- class << self
4
- def gem_release
5
- system("gem install souls")
6
- sleep(3)
7
- current_souls_ver = Souls::VERSION.strip.split(".").map(&:to_i)
8
- prompt = TTY::Prompt.new
9
- choices = [
10
- "1. Patch(#{Souls.version_detector(current_ver: current_souls_ver, update_kind: 'patch')})",
11
- "2. Minor(#{Souls.version_detector(current_ver: current_souls_ver, update_kind: 'minor')})",
12
- "3. Major(#{Souls.version_detector(current_ver: current_souls_ver, update_kind: 'major')})"
13
- ]
14
- choice_num = prompt.select("Select Version: ", choices)[0].to_i
15
- update_kinds = %w[patch minor major]
16
- update_kind = update_kinds[choice_num - 1]
17
- souls_new_ver = Souls.version_detector(current_ver: current_souls_ver, update_kind: update_kind)
18
- status = Paint["Saving Repo...", :yellow]
19
- Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do
20
- Whirly.status = status
21
- %w[api worker].each do |s_name|
22
- update_service_gemfile(service_name: s_name, version: souls_new_ver)
23
- result = Paint[update_repo(service_name: s_name, update_kind: update_kind), :green]
24
- Whirly.status = result
25
- end
26
- overwrite_version(new_version: souls_new_ver)
27
- puts("before add")
28
- system("git add .")
29
- puts("before commit")
30
- system("git commit -m 'souls update v#{souls_new_ver}'")
31
- puts("before build")
32
- system("rake build")
33
- system("rake release")
34
- Whirly.status = Paint["soul-v#{souls_new_ver} successfully updated!"]
2
+ class CLI < Thor
3
+ desc "release", "Release Gem"
4
+ def release
5
+ system("gem install souls")
6
+ sleep(3)
7
+ current_souls_ver = Souls::VERSION.strip.split(".").map(&:to_i)
8
+ prompt = TTY::Prompt.new
9
+ choices = [
10
+ "1. Patch(#{Souls.version_detector(current_ver: current_souls_ver, update_kind: 'patch')})",
11
+ "2. Minor(#{Souls.version_detector(current_ver: current_souls_ver, update_kind: 'minor')})",
12
+ "3. Major(#{Souls.version_detector(current_ver: current_souls_ver, update_kind: 'major')})"
13
+ ]
14
+ choice_num = prompt.select("Select Version: ", choices)[0].to_i
15
+ update_kinds = %w[patch minor major]
16
+ update_kind = update_kinds[choice_num - 1]
17
+ souls_new_ver = Souls.version_detector(current_ver: current_souls_ver, update_kind: update_kind)
18
+ status = Paint["Saving Repo...", :yellow]
19
+ Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do
20
+ Whirly.status = status
21
+ %w[api worker].each do |s_name|
22
+ update_service_gemfile(service_name: s_name, version: souls_new_ver)
23
+ result = Paint[update_repo(service_name: s_name, update_kind: update_kind), :green]
24
+ Whirly.status = result
35
25
  end
26
+ overwrite_version(new_version: souls_new_ver)
27
+ puts("before add")
28
+ system("git add .")
29
+ puts("before commit")
30
+ system("git commit -m 'souls update v#{souls_new_ver}'")
31
+ puts("before build")
32
+ system("rake build")
33
+ system("rake release")
34
+ Whirly.status = Paint["soul-v#{souls_new_ver} successfully updated!"]
36
35
  end
36
+ end
37
37
 
38
- def update_repo(service_name: "api", update_kind: "patch")
39
- current_dir_name = FileUtils.pwd.to_s.match(%r{/([^/]+)/?$})[1]
40
- current_ver = Souls.get_latest_version_txt(service_name: service_name)
41
- new_ver = Souls.version_detector(current_ver: current_ver, update_kind: update_kind)
42
- bucket_url = "gs://souls-bucket/boilerplates"
43
- file_name = "#{service_name}-v#{new_ver}.tgz"
44
- release_name = "#{service_name}-latest.tgz"
38
+ private
45
39
 
46
- case current_dir_name
47
- when "souls"
48
- system("echo '#{new_ver}' > lib/souls/versions/.souls_#{service_name}_version")
49
- system("echo '#{new_ver}' > apps/#{service_name}/.souls_#{service_name}_version")
50
- system("cd apps/ && tar -czf ../#{service_name}.tgz #{service_name}/ && cd ..")
51
- when "api", "worker", "console", "admin", "media"
52
- system("echo '#{new_ver}' > lib/souls/versions/.souls_#{service_name}_version")
53
- system("echo '#{new_ver}' > .souls_#{service_name}_version")
54
- system("cd .. && tar -czf ../#{service_name}.tgz #{service_name}/ && cd #{service_name}")
55
- else
56
- raise(StandardError, "You are at wrong directory!")
57
- end
40
+ def update_repo(service_name: "api", update_kind: "patch")
41
+ current_dir_name = FileUtils.pwd.to_s.match(%r{/([^/]+)/?$})[1]
42
+ current_ver = Souls.get_latest_version_txt(service_name: service_name)
43
+ new_ver = Souls.version_detector(current_ver: current_ver, update_kind: update_kind)
44
+ bucket_url = "gs://souls-bucket/boilerplates"
45
+ file_name = "#{service_name}-v#{new_ver}.tgz"
46
+ release_name = "#{service_name}-latest.tgz"
58
47
 
59
- system("gsutil cp #{service_name}.tgz #{bucket_url}/#{service_name.pluralize}/#{file_name}")
60
- system("gsutil cp #{service_name}.tgz #{bucket_url}/#{service_name.pluralize}/#{release_name}")
61
- system("gsutil cp .rubocop.yml #{bucket_url}/.rubocop.yml")
62
- FileUtils.rm("#{service_name}.tgz")
63
- "#{service_name}-v#{new_ver} Succefully Stored to GCS! "
48
+ case current_dir_name
49
+ when "souls"
50
+ system("echo '#{new_ver}' > lib/souls/versions/.souls_#{service_name}_version")
51
+ system("echo '#{new_ver}' > apps/#{service_name}/.souls_#{service_name}_version")
52
+ system("cd apps/ && tar -czf ../#{service_name}.tgz #{service_name}/ && cd ..")
53
+ when "api", "worker", "console", "admin", "media"
54
+ system("echo '#{new_ver}' > lib/souls/versions/.souls_#{service_name}_version")
55
+ system("echo '#{new_ver}' > .souls_#{service_name}_version")
56
+ system("cd .. && tar -czf ../#{service_name}.tgz #{service_name}/ && cd #{service_name}")
57
+ else
58
+ raise(StandardError, "You are at wrong directory!")
64
59
  end
65
60
 
66
- def update_service_gemfile(service_name: "api", version: "0.0.1")
67
- file_dir = "./apps/#{service_name}"
68
- file_path = "#{file_dir}/Gemfile"
69
- gemfile_lock = "#{file_dir}/Gemfile.lock"
70
- tmp_file = "#{file_dir}/tmp/Gemfile"
71
- File.open(file_path, "r") do |f|
72
- File.open(tmp_file, "w") do |new_line|
73
- f.each_line do |line|
74
- gem = line.gsub("gem ", "").gsub("\"", "").gsub("\n", "").gsub(" ", "").split(",")
75
- if gem[0] == "souls"
76
- old_ver = gem[1].split(".")
77
- old_ver[2] = (old_ver[2].to_i + 1).to_s
78
- new_line.write(" gem \"souls\", \"#{version}\"\n")
79
- else
80
- new_line.write(line)
81
- end
61
+ system("gsutil cp #{service_name}.tgz #{bucket_url}/#{service_name.pluralize}/#{file_name}")
62
+ system("gsutil cp #{service_name}.tgz #{bucket_url}/#{service_name.pluralize}/#{release_name}")
63
+ system("gsutil cp .rubocop.yml #{bucket_url}/.rubocop.yml")
64
+ FileUtils.rm("#{service_name}.tgz")
65
+ "#{service_name}-v#{new_ver} Succefully Stored to GCS! "
66
+ end
67
+
68
+ def update_service_gemfile(service_name: "api", version: "0.0.1")
69
+ file_dir = "./apps/#{service_name}"
70
+ file_path = "#{file_dir}/Gemfile"
71
+ gemfile_lock = "#{file_dir}/Gemfile.lock"
72
+ tmp_file = "#{file_dir}/tmp/Gemfile"
73
+ File.open(file_path, "r") do |f|
74
+ File.open(tmp_file, "w") do |new_line|
75
+ f.each_line do |line|
76
+ gem = line.gsub("gem ", "").gsub("\"", "").gsub("\n", "").gsub(" ", "").split(",")
77
+ if gem[0] == "souls"
78
+ old_ver = gem[1].split(".")
79
+ old_ver[2] = (old_ver[2].to_i + 1).to_s
80
+ new_line.write(" gem \"souls\", \"#{version}\"\n")
81
+ else
82
+ new_line.write(line)
82
83
  end
83
84
  end
84
85
  end
85
- FileUtils.rm(file_path)
86
- FileUtils.rm(gemfile_lock) if File.exist?(gemfile_lock)
87
- FileUtils.mv(tmp_file, file_path)
88
- puts(Paint["\nSuccessfully Updated #{service_name} Gemfile!", :green])
89
86
  end
87
+ FileUtils.rm(file_path)
88
+ FileUtils.rm(gemfile_lock) if File.exist?(gemfile_lock)
89
+ FileUtils.mv(tmp_file, file_path)
90
+ puts(Paint["\nSuccessfully Updated #{service_name} Gemfile!", :green])
91
+ end
90
92
 
91
- def overwrite_version(new_version: "0.1.1")
92
- FileUtils.rm("./lib/souls/version.rb")
93
- file_path = "./lib/souls/version.rb"
94
- File.open(file_path, "w") do |f|
95
- f.write(<<~TEXT)
96
- module Souls
97
- VERSION = "#{new_version}".freeze
98
- public_constant :VERSION
99
- end
100
- TEXT
101
- end
102
- overwrite_gemfile_lock(new_version: new_version)
103
- true
104
- rescue StandardError, e
105
- raise(StandardError, e)
93
+ def overwrite_version(new_version: "0.1.1")
94
+ FileUtils.rm("./lib/souls/version.rb")
95
+ file_path = "./lib/souls/version.rb"
96
+ File.open(file_path, "w") do |f|
97
+ f.write(<<~TEXT)
98
+ module Souls
99
+ VERSION = "#{new_version}".freeze
100
+ public_constant :VERSION
101
+ end
102
+ TEXT
106
103
  end
104
+ overwrite_gemfile_lock(new_version: new_version)
105
+ true
106
+ rescue StandardError, e
107
+ raise(StandardError, e)
108
+ end
107
109
 
108
- def overwrite_gemfile_lock(new_version: "0.1.1")
109
- file_path = "Gemfile.lock"
110
- new_file_path = "Gemfile.lock.tmp"
111
- File.open(file_path, "r") do |f|
112
- File.open(new_file_path, "w") do |new_line|
113
- f.each_line.with_index do |line, i|
114
- if i == 3
115
- new_line.write(" souls (#{new_version})\n")
116
- else
117
- new_line.write(line)
118
- end
110
+ def overwrite_gemfile_lock(new_version: "0.1.1")
111
+ file_path = "Gemfile.lock"
112
+ new_file_path = "Gemfile.lock.tmp"
113
+ File.open(file_path, "r") do |f|
114
+ File.open(new_file_path, "w") do |new_line|
115
+ f.each_line.with_index do |line, i|
116
+ if i == 3
117
+ new_line.write(" souls (#{new_version})\n")
118
+ else
119
+ new_line.write(line)
119
120
  end
120
121
  end
121
122
  end
122
- FileUtils.rm(file_path)
123
- FileUtils.mv(new_file_path, file_path)
124
123
  end
124
+ FileUtils.rm(file_path)
125
+ FileUtils.mv(new_file_path, file_path)
125
126
  end
126
127
  end
127
128
  end
@@ -1,4 +1,15 @@
1
1
  module Souls
2
- module Server
2
+ class CLI < Thor
3
+ desc "server", "Run SOULs APP"
4
+ method_option all: :boolean, alias: "--all", default: false, desc: "Run All API & Workers"
5
+ def server
6
+ if options[:all]
7
+ Dir.chdir(Souls.get_mother_path.to_s) do
8
+ system("foreman start -f Procfile.dev")
9
+ end
10
+ else
11
+ system("foreman start -f Procfile.dev")
12
+ end
13
+ end
3
14
  end
4
15
  end
@@ -1,61 +1,62 @@
1
1
  module Souls
2
- module Sync
3
- class << self
4
- def conf
5
- update_conf
6
- update_conf(strain: "api")
7
- end
2
+ class Sync < Thor
3
+ desc "conf", "Sync config/souls.rb Endpoint with Google Cloud Run"
4
+ def conf
5
+ update_conf
6
+ update_conf(strain: "api")
7
+ end
8
+
9
+ private
8
10
 
9
- def update_conf(strain: "mother")
10
- require("#{Souls.get_mother_path}/config/souls")
11
- workers = Souls.configuration.workers
12
- Dir.chdir(Souls.get_mother_path.to_s) do
13
- file_path = strain == "mother" ? "config/souls.rb" : "apps/api/config/souls.rb"
14
- new_file_path = "souls.rb"
15
- worker_switch = false
16
- File.open(new_file_path, "w") do |new_line|
17
- File.open(file_path, "r") do |f|
18
- f.each_line do |line|
19
- worker_switch = true if line.include?("config.workers")
20
- next if line.strip == "end"
11
+ def update_conf(strain: "mother")
12
+ require("#{Souls.get_mother_path}/config/souls")
13
+ workers = Souls.configuration.workers
14
+ Dir.chdir(Souls.get_mother_path.to_s) do
15
+ file_path = strain == "mother" ? "config/souls.rb" : "apps/api/config/souls.rb"
16
+ new_file_path = "souls.rb"
17
+ worker_switch = false
18
+ File.open(new_file_path, "w") do |new_line|
19
+ File.open(file_path, "r") do |f|
20
+ f.each_line do |line|
21
+ worker_switch = true if line.include?("config.workers")
22
+ next if line.strip == "end"
21
23
 
22
- new_line.write(line) unless worker_switch
24
+ new_line.write(line) unless worker_switch
23
25
 
24
- next unless worker_switch
26
+ next unless worker_switch
25
27
 
26
- new_line.write(" config.workers = [\n")
27
- workers.each_with_index do |worker, i|
28
- base_url = Souls::Gcloud::Run.get_endpoint(worker_name: worker[:name])
29
- endpoint = Souls.configuration.endpoint
30
- if (i + 1) == workers.size
31
- new_line.write(<<-TEXT)
28
+ new_line.write(" config.workers = [\n")
29
+ workers.each_with_index do |worker, i|
30
+ base_url = Souls::Gcloud::Run.new.get_endpoint(worker_name: worker[:name])
31
+ endpoint = Souls.configuration.endpoint
32
+ if (i + 1) == workers.size
33
+ new_line.write(<<-TEXT)
32
34
  {
33
35
  name: "#{worker[:name]}",
34
36
  endpoint: "#{base_url.strip}#{endpoint}",
35
37
  port: #{worker[:port]}
36
38
  }
37
- TEXT
38
- else
39
- new_line.write(<<-TEXT)
39
+ TEXT
40
+ else
41
+ new_line.write(<<-TEXT)
40
42
  {
41
43
  name: "#{worker[:name]}",
42
44
  endpoint: "#{base_url.strip}#{endpoint}",
43
45
  port: #{worker[:port]}
44
46
  },
45
- TEXT
46
- end
47
+ TEXT
47
48
  end
48
- break
49
49
  end
50
+ break
50
51
  end
51
- new_line.write(<<~TEXT)
52
- ]
53
- end
54
- TEXT
55
52
  end
56
- FileUtils.rm(file_path)
57
- FileUtils.mv(new_file_path, file_path)
53
+ new_line.write(<<~TEXT)
54
+ ]
55
+ end
56
+ TEXT
58
57
  end
58
+ FileUtils.rm(file_path)
59
+ FileUtils.mv(new_file_path, file_path)
59
60
  end
60
61
  end
61
62
  end
@@ -1,27 +1,26 @@
1
1
  module Souls
2
- module Sync
3
- class << self
4
- def model
5
- cp_dir = %w[db app/models spec/factories]
6
- cp_dir.each do |dir|
7
- cp_and_dl_files(dir: dir)
8
- end
2
+ class Sync < Thor
3
+ desc "model", "Sync Model, DB, Factory Files with API"
4
+ def model
5
+ cp_dir = %w[db app/models spec/factories]
6
+ cp_dir.each do |dir|
7
+ cp_and_dl_files(dir: dir)
9
8
  end
9
+ end
10
10
 
11
- private
11
+ private
12
12
 
13
- def cp_and_dl_files(dir: "db")
14
- require("#{Souls.get_mother_path}/config/souls")
15
- worker_paths = Souls.configuration.workers.map { |n| n[:name] }
16
- worker_paths.each do |path|
17
- cp_path = "./apps/api/#{dir}"
18
- old_path = "./apps/#{path}/#{dir}"
19
- system("rm -rf #{old_path}", chdir: Souls.get_mother_path)
20
- system("mkdir -p #{old_path}", chdir: Souls.get_mother_path)
21
- system("cp -r #{cp_path}/* #{old_path}", chdir: Souls.get_mother_path)
22
- rescue StandardError
23
- # Do nothing
24
- end
13
+ def cp_and_dl_files(dir: "db")
14
+ require("#{Souls.get_mother_path}/config/souls")
15
+ worker_paths = Souls.configuration.workers.map { |n| n[:name] }
16
+ worker_paths.each do |path|
17
+ cp_path = "./apps/api/#{dir}"
18
+ old_path = "./apps/#{path}/#{dir}"
19
+ system("rm -rf #{old_path}", chdir: Souls.get_mother_path)
20
+ system("mkdir -p #{old_path}", chdir: Souls.get_mother_path)
21
+ system("cp -r #{cp_path}/* #{old_path}", chdir: Souls.get_mother_path)
22
+ rescue StandardError
23
+ # Do nothing
25
24
  end
26
25
  end
27
26
  end
@@ -1,93 +1,92 @@
1
1
  module Souls
2
- module Sync
3
- class << self
4
- def pubsub
5
- get_topics(workers: get_workers)
6
- end
7
-
8
- private
9
-
10
- def get_topics(workers: {})
11
- project_id = Souls.configuration.project_id
12
- pubsub = Google::Cloud::Pubsub.new
13
- topics = pubsub.topics
2
+ class Sync < Thor
3
+ desc "pubsub", "Sync Worker Jobs & Google Cloud Pubsub Subscriptions"
4
+ def pubsub
5
+ get_topics(workers: get_workers)
6
+ end
14
7
 
15
- topic_names =
16
- topics.map do |topic|
17
- topic.name.gsub("projects/#{project_id}/topics/", "")
18
- end
8
+ private
19
9
 
20
- topic_names.each do |name|
21
- value = workers[name.to_sym] || 0
22
- workers[name.to_sym] = value - 1
23
- end
10
+ def get_topics(workers: {})
11
+ project_id = Souls.configuration.project_id
12
+ pubsub = Google::Cloud::Pubsub.new
13
+ topics = pubsub.topics
24
14
 
25
- workers.each do |key, value|
26
- if value == 1
27
- create_topic(topic_id: key.to_s)
28
- create_push_subscription(topic_id: key.to_s)
29
- end
30
- delete_topic(topic_id: key.to_s) if value == -1
15
+ topic_names =
16
+ topics.map do |topic|
17
+ topic.name.gsub("projects/#{project_id}/topics/", "")
31
18
  end
32
- workers
33
- end
34
19
 
35
- def create_topic(topic_id: "mailer")
36
- pubsub = Google::Cloud::Pubsub.new
37
- topic = pubsub.create_topic(topic_id)
38
- puts("Topic #{topic.name} created.")
20
+ topic_names.each do |name|
21
+ value = workers[name.to_sym] || 0
22
+ workers[name.to_sym] = value - 1
39
23
  end
40
24
 
41
- def delete_topic(topic_id: "mailer")
42
- pubsub = Google::Cloud::Pubsub.new
43
- topic = pubsub.topic(topic_id)
44
- topic.delete
45
- puts("Topic #{topic_id} deleted.")
25
+ workers.each do |key, value|
26
+ if value == 1
27
+ create_topic(topic_id: key.to_s)
28
+ create_push_subscription(topic_id: key.to_s)
29
+ end
30
+ delete_topic(topic_id: key.to_s) if value == -1
46
31
  end
32
+ workers
33
+ end
47
34
 
48
- def create_push_subscription(topic_id: "mailer")
49
- require("#{Souls.get_mother_path}/config/souls")
50
- worker_name = topic_id.split("_")[0]
35
+ def create_topic(topic_id: "mailer")
36
+ pubsub = Google::Cloud::Pubsub.new
37
+ topic = pubsub.create_topic(topic_id)
38
+ puts("Topic #{topic.name} created.")
39
+ end
51
40
 
52
- subscription_id = "#{topic_id}_sub"
53
- endpoint = ""
54
- worker_paths = Souls.configuration.workers
55
- worker_paths.each do |worker|
56
- endpoint = worker[:endpoint] if worker[:name] == worker_name
57
- end
41
+ def delete_topic(topic_id: "mailer")
42
+ pubsub = Google::Cloud::Pubsub.new
43
+ topic = pubsub.topic(topic_id)
44
+ topic.delete
45
+ puts("Topic #{topic_id} deleted.")
46
+ end
58
47
 
59
- pubsub = Google::Cloud::Pubsub.new
48
+ def create_push_subscription(topic_id: "mailer")
49
+ require("#{Souls.get_mother_path}/config/souls")
50
+ worker_name = topic_id.split("_")[0]
60
51
 
61
- topic = pubsub.topic(topic_id)
62
- sub = topic.subscribe(subscription_id, endpoint: endpoint, deadline: 20)
63
- sub.expires_in = nil
64
- puts("Push subscription #{subscription_id} created.")
52
+ subscription_id = "#{topic_id}_sub"
53
+ endpoint = ""
54
+ worker_paths = Souls.configuration.workers
55
+ worker_paths.each do |worker|
56
+ endpoint = worker[:endpoint] if worker[:name] == worker_name
65
57
  end
66
58
 
67
- def get_workers
68
- require("#{Souls.get_mother_path}/config/souls")
69
- worker_paths = Souls.configuration.workers.map { |n| n[:name] }
70
- response = {}
71
- Dir.chdir(Souls.get_mother_path.to_s) do
72
- worker_paths.each do |worker|
73
- mailers =
74
- Dir["apps/#{worker}/app/graphql/mutations/mailers/*.rb"].map do |file|
75
- file.gsub("apps/#{worker}/app/graphql/mutations/mailers/", "").gsub(".rb", "")
76
- end
59
+ pubsub = Google::Cloud::Pubsub.new
60
+
61
+ topic = pubsub.topic(topic_id)
62
+ sub = topic.subscribe(subscription_id, endpoint: endpoint, deadline: 20)
63
+ sub.expires_in = nil
64
+ puts("Push subscription #{subscription_id} created.")
65
+ end
66
+
67
+ def get_workers
68
+ require("#{Souls.get_mother_path}/config/souls")
69
+ worker_paths = Souls.configuration.workers.map { |n| n[:name] }
70
+ response = {}
71
+ Dir.chdir(Souls.get_mother_path.to_s) do
72
+ worker_paths.each do |worker|
73
+ mailers =
74
+ Dir["apps/#{worker}/app/graphql/mutations/mailers/*.rb"].map do |file|
75
+ file.gsub("apps/#{worker}/app/graphql/mutations/mailers/", "").gsub(".rb", "")
76
+ end
77
77
 
78
- workers =
79
- Dir["apps/#{worker}/app/graphql/mutations/*.rb"].map do |file|
80
- file.gsub("apps/#{worker}/app/graphql/mutations/", "").gsub(".rb", "")
81
- end
82
- workers.delete("base_mutation")
83
- local_files = mailers + workers
84
- local_files.each do |file|
85
- response[:"#{worker}_#{file}"] = 1
78
+ workers =
79
+ Dir["apps/#{worker}/app/graphql/mutations/*.rb"].map do |file|
80
+ file.gsub("apps/#{worker}/app/graphql/mutations/", "").gsub(".rb", "")
86
81
  end
82
+ workers.delete("base_mutation")
83
+ local_files = mailers + workers
84
+ local_files.each do |file|
85
+ response[:"#{worker}_#{file}"] = 1
87
86
  end
88
87
  end
89
- response
90
88
  end
89
+ response
91
90
  end
92
91
  end
93
92
  end