souls 1.20.0 → 1.20.4

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: 690c4e033ba2db83f5f7889ac33cd199dbd4cd6b9b69f83c9d55cdd97ff5d3b3
4
- data.tar.gz: aaf41d5d0ffaf0610c1cf99f26eb67df7e8c1d59e0bf40dd4b2eb525e3839ae4
3
+ metadata.gz: b0d0a4fbbf0be1899a5c0b8a8b6c6f6a64342c882a9254a7fb382484cb0b67d9
4
+ data.tar.gz: f6c7d30d7cf6e7898a05603846c94d6f460e8f726bd40300b88762a3b4aefc55
5
5
  SHA512:
6
- metadata.gz: f0a118b3bedfa8fdf60f6f7125b05dd05a9a49d2e818dad1bcfab50f98586fa173fdbbaa0417083dc0fa857c12461a18e54d628b365b40e57d693d6aa9323f96
7
- data.tar.gz: ec064cf74ce3992b7169aca42b2f208eb3c81ce7dd2855df4b0c9f1a474028ca8d1b1631ac057d0864e81214fec48c71786bb8ebf6c6f1d358a48567d3d13818
6
+ metadata.gz: 8b66aba97ed7631f61dc44ea3b05ab66f9bf263a9638a2f87889b4fa32cf1f303753228d53b4eb7cd7380068dd40ab20fc97a4789cf391f8823f6a43d0cc0c22
7
+ data.tar.gz: 35a69e66fbf2768a19189802a94d0751cfca7b40d39e0532d81b7384b1e544d82d708ba0aea39fce4c9f5da00f226cc91de5dc91d325798d5c34cd5773c92615
@@ -1,5 +1,23 @@
1
1
  module SOULs
2
2
  class SOULsMutation < GraphQL::Schema::RelayClassicMutation
3
+ def self.post(url:, payload: {}, content_type: "application/json")
4
+ response = Faraday.post(url, payload.to_json, "Content-Type": content_type)
5
+ response.body
6
+ end
7
+
8
+ def self.souls_worker_trigger(worker_name:, query_file_name:)
9
+ query_file_name = query_file_name.gsub("_", "-")
10
+ topic_name = "souls-#{worker_name}-#{query_file_name}"
11
+ query = query_file_name.underscore.camelize(:lower)
12
+ query_string = souls_make_graphql_query(query: query)
13
+ case ENV["RACK_ENV"]
14
+ when "production"
15
+ souls_publish_pubsub_queue(topic_name: topic_name, message: query_string)
16
+ when "development"
17
+ puts(souls_post_to_dev(worker_name: worker_name, query_string: query_string))
18
+ end
19
+ end
20
+
3
21
  def self.souls_check_user_permissions(user, obj, method)
4
22
  raise(StandardError, "Invalid or Missing Token") unless user
5
23
 
@@ -43,8 +61,7 @@ module SOULs
43
61
  end
44
62
 
45
63
  def self.souls_post_to_dev(worker_name: "", query_string: "")
46
- app = SOULs.configuration.app
47
- port = souls_get_worker(worker_name: "souls-#{app}-#{worker_name}")[0][:port]
64
+ port = souls_get_worker(worker_name: worker_name)[0][:port]
48
65
  endpoint = SOULs.configuration.endpoint
49
66
  res = Net::HTTP.post_form(URI.parse("http://localhost:#{port}#{endpoint}"), { query: query_string })
50
67
  res.body
@@ -59,11 +76,11 @@ module SOULs
59
76
  raise(GraphQL::ExecutionError, "You need to sign in!!") if context[:user].nil?
60
77
  end
61
78
 
62
- def production?
79
+ def self.production?
63
80
  ENV["RACK_ENV"] == "production"
64
81
  end
65
82
 
66
- def get_instance_id
83
+ def self.get_instance_id
67
84
  `curl http://metadata.google.internal/computeMetadata/v1/instance/id -H Metadata-Flavor:Google`
68
85
  end
69
86
  end
@@ -5,6 +5,11 @@ module SOULs
5
5
  attr_accessor :schedule
6
6
  end
7
7
 
8
+ def self.post(url:, payload: {}, content_type: "application/json")
9
+ response = Faraday.post(url, payload.to_json, "Content-Type": content_type)
10
+ response.body
11
+ end
12
+
8
13
  def self.check_user_permissions(user, obj, method)
9
14
  raise(StandardError, "Invalid or Missing Token") unless user
10
15
 
@@ -47,6 +47,19 @@ module SOULs
47
47
  SOULs::Painter.create_file(file_path)
48
48
  end
49
49
  create_env_yaml(file_dir: file_dir)
50
+ endroll = <<~TEXT
51
+
52
+ ♤ Deploy Cloud Functions ♤
53
+
54
+ $ cd apps/cf-#{version_string}-#{function_name}
55
+ $ souls functions deploy
56
+
57
+ $ souls functions help
58
+
59
+
60
+ Doc: https://souls.elsoul.nl
61
+ TEXT
62
+ puts(Paint[endroll, :white])
50
63
  end
51
64
 
52
65
  private
@@ -10,12 +10,10 @@ module SOULs
10
10
  raise(StandardError, "Same Worker Already Exist!") if Dir.exist?(file_dir)
11
11
 
12
12
  workers = SOULs.configuration.workers
13
- app = SOULs.configuration.app
14
13
  port = 3000 + workers.size
15
- souls_worker_name = "souls-#{app}-#{worker_name}"
16
14
  download_worker(worker_name: worker_name)
17
- souls_conf_update(worker_name: souls_worker_name)
18
- souls_conf_update(worker_name: souls_worker_name, strain: "api")
15
+ souls_conf_update(worker_name: worker_name)
16
+ souls_conf_update(worker_name: worker_name, strain: "api")
19
17
  workflow(worker_name: worker_name)
20
18
  procfile(worker_name: worker_name, port: port)
21
19
  mother_procfile(worker_name: worker_name)
@@ -11,7 +11,7 @@ module SOULs
11
11
  end
12
12
 
13
13
  runtime = current_dir.match(/cf-(\D+\d+)-/)[1]
14
- runtime_lang = current_dir.match(/^cf-(\D+)\d+-/)
14
+ runtime_lang = current_dir.match(/^cf-(\D+)\d+-/)[1]
15
15
  entry_point =
16
16
  case runtime_lang
17
17
  when "nodejs"
@@ -21,11 +21,12 @@ module SOULs
21
21
  when "go"
22
22
  current_dir.underscore.camelize
23
23
  else
24
+ system("bundle install")
24
25
  current_dir
25
26
  end
26
27
  system(
27
28
  "
28
- gcloud functions deploy #{current_dir} --entry-point=#{entry_point} --project=#{project_id} \
29
+ gcloud functions deploy #{current_dir} --entry-point='#{entry_point}' --project=#{project_id} \
29
30
  --runtime #{runtime} --trigger-http --allow-unauthenticated --env-vars-file .env.yaml
30
31
  "
31
32
  )
@@ -47,7 +48,7 @@ module SOULs
47
48
  Dir.chdir(SOULs.get_mother_path.to_s) do
48
49
  FileUtils.rm_rf("apps/#{name}")
49
50
  end
50
- SOULs::Painter.success("Deleted #{name} functions!")
51
+ SOULs::Painter.warning("Deleted #{name} functions!", "✨")
51
52
  end
52
53
 
53
54
  desc "url", "Get SOULs Functions URL"
@@ -1,12 +1,11 @@
1
1
  module SOULs
2
2
  class CloudScheduler < Thor
3
- desc "awake", "Set Ping Every 15min by Google Cloud Scheduler"
4
- method_option :url, default: "https://souls.souls.nl", aliases: "--url", desc: "Set URL"
5
- def awake
3
+ desc "awake [url]", "Set Ping Every 15min by Google Cloud Scheduler"
4
+ def awake(url)
6
5
  app_name = SOULs.configuration.app
7
6
  system(
8
7
  "gcloud scheduler jobs create http #{app_name}-awake
9
- --schedule '0,10,20,30,40,50 * * * *' --uri #{options[:url]} --http-method GET"
8
+ --schedule '0,10,20,30,40,50 * * * *' --uri #{url} --http-method GET"
10
9
  )
11
10
  end
12
11
 
@@ -18,11 +17,11 @@ module SOULs
18
17
  project_id = SOULs.configuration.project_id
19
18
 
20
19
  schedules_list = current_schedules
21
- worker_name = FileUtils.pwd.split("/").last
20
+ worker_name = FileUtils.pwd.split("/").last.underscore
22
21
  Queries::BaseQuery.all_schedules.each do |k, v|
23
22
  worker_name = FileUtils.pwd.split("/").last
24
- job_name = "souls_#{worker_name}_#{k.to_s.underscore}".to_sym
25
- topic = "souls_#{worker_name}_#{k.to_s.underscore}"
23
+ job_name = "souls-#{worker_name}-#{k.to_s.underscore}".to_sym
24
+ topic = "souls-#{worker_name}-#{k.to_s.underscore}"
26
25
  message_body = "query { #{k.to_s.camelize(:lower)} { response }}"
27
26
 
28
27
  if schedules_list.include?(job_name)
@@ -43,7 +42,7 @@ module SOULs
43
42
  end
44
43
 
45
44
  schedules_list.each do |k, _|
46
- next unless k.match?(/^souls_#{worker_name}/)
45
+ next unless k.match?(/^souls-#{worker_name}/)
47
46
 
48
47
  system("gcloud scheduler jobs delete #{k} -q >/dev/null 2>&1")
49
48
  end
@@ -13,19 +13,41 @@ module SOULs
13
13
 
14
14
  zone = "#{region}-b"
15
15
  system("gcloud config set project #{project_id} >/dev/null 2>&1")
16
- Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do
17
- system(
18
- "gcloud sql instances create #{instance_name} \
16
+ system(
17
+ "gcloud sql instances create #{instance_name} \
19
18
  --database-version=#{db_type} --cpu=1 --memory=4096MB --zone=#{zone} \
20
19
  --root-password='#{password}' --database-flags cloudsql.iam_authentication=on"
21
- )
22
- SOULs::Sql.new.env(password: password)
23
- SOULs::Github.new.secret_set
24
- Whirly.status = Paint["Cloud SQL #{instance_name} is successfully created! You can push to deploy!", :green]
25
- end
20
+ )
21
+ SOULs::Sql.new.env(password: password)
22
+ SOULs::Github.new.secret_set
23
+ SOULs::Painter.success("Cloud SQL #{instance_name} is successfully created! You can push to deploy!")
26
24
  true
27
25
  end
28
26
 
27
+ desc "stop", "Stop Cloud SQL Instance"
28
+ def stop
29
+ project_id = SOULs.configuration.project_id
30
+ instance_name = SOULs.configuration.instance_name
31
+ system("gcloud sql instances patch #{instance_name} --project=#{project_id} --activation-policy=NEVER")
32
+ SOULs::Painter.warning("Cloud SQL #{instance_name} is stopped!")
33
+ end
34
+
35
+ desc "restart", "Restart Cloud SQL Instance"
36
+ def restart
37
+ project_id = SOULs.configuration.project_id
38
+ instance_name = SOULs.configuration.instance_name
39
+ system("gcloud sql instances restart #{instance_name} --project=#{project_id}")
40
+ SOULs::Painter.success("Cloud SQL #{instance_name} is restarted!")
41
+ end
42
+
43
+ desc "delete", "Delete Cloud SQL Instance"
44
+ def delete
45
+ project_id = SOULs.configuration.project_id
46
+ instance_name = SOULs.configuration.instance_name
47
+ system("gcloud sql instances delete #{instance_name} --project=#{project_id}")
48
+ SOULs::Painter.warning("Cloud SQL #{instance_name} is deleted!", "✨")
49
+ end
50
+
29
51
  desc "env", "Generate .env.production file to deploy"
30
52
  def env(password: "Password")
31
53
  require(SOULs.get_mother_path.to_s + "/config/souls")
@@ -5,6 +5,8 @@ module SOULs
5
5
  desc "release", "Release Gem"
6
6
  def release
7
7
  SOULs::Painter.error("hey! It's Broken!") unless system("rspec")
8
+ FileUtils.rm("apps/api/Gemfile.lock") if File.exist?("apps/api/Gemfile.lock")
9
+ FileUtils.rm("apps/worker/Gemfile.lock") if File.exist?("apps/worker/Gemfile.lock")
8
10
 
9
11
  system("gem install souls")
10
12
  sleep(3)
data/lib/souls/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module SOULs
2
- VERSION = "1.20.0".freeze
2
+ VERSION = "1.20.4".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 1.20.0
1
+ 1.20.4
@@ -1 +1 @@
1
- 1.20.0
1
+ 1.20.4
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: souls
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.20.0
4
+ version: 1.20.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI
8
8
  - KishiTheMechanic
9
9
  - James Neve
10
- autorequire:
10
+ autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2022-01-07 00:00:00.000000000 Z
13
+ date: 2022-01-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -299,7 +299,7 @@ licenses:
299
299
  - Apache-2.0
300
300
  metadata:
301
301
  rubygems_mfa_required: 'true'
302
- post_install_message:
302
+ post_install_message:
303
303
  rdoc_options: []
304
304
  require_paths:
305
305
  - lib
@@ -315,7 +315,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
315
315
  version: '0'
316
316
  requirements: []
317
317
  rubygems_version: 3.2.32
318
- signing_key:
318
+ signing_key:
319
319
  specification_version: 4
320
320
  summary: Ruby Serverless Framework 'SOULs' | Ruby サーバーレスフレームワーク SOULs. Powered by
321
321
  Ruby GraphQL, RBS/Steep, Active Record, RSpec, RuboCop, and Google Cloud.