virtuaservices 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/virtuaservices/utils/micro_service.rb +14 -14
- data/lib/virtuaservices/utils/seeder.rb +4 -4
- data/lib/virtuaservices/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb059e789bd366ef871e57251808b7d6f7a7f1605008f7ab7afe12169becf477
|
4
|
+
data.tar.gz: 277f3210c31440030234400b95cc1af645afbefab05fa194b1a20e61fdeef088
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5fdca969d3b8280c9ef4e76b34682fab5ed70431d08150ee08b10b99e36f2160339ad0b1e008013ff4e83b7fd5c051b75986505a4014c0685097ea7252eed05
|
7
|
+
data.tar.gz: 996825708dfd4fbc9b6dc1f52d723d92f8e9ef7be414fed6fb4feec16aff9dcc041ec30c8036c7ec5d0b1c1cbd21bed4abc7e0930705aef66c85ce1bf7bc9968
|
@@ -15,7 +15,7 @@ module Virtuaservices
|
|
15
15
|
# @return [String] the name of the service, used later to instantiate it when the mongoid configuration is fully loaded.
|
16
16
|
attr_reader :name
|
17
17
|
# @!attribute [r] instance
|
18
|
-
# @return [
|
18
|
+
# @return [Virtuaservices::Monitoring::Instance] the instance of the service currently deployed.
|
19
19
|
attr_reader :instance
|
20
20
|
# @!attribute [r] type
|
21
21
|
# @return [Symbol] the type of instance the application is declaring
|
@@ -54,7 +54,7 @@ module Virtuaservices
|
|
54
54
|
|
55
55
|
# Look for the service and sets it if it's found in the database, or set it to nil if not found.
|
56
56
|
# @param [String] service_name - the name of the service to look for in the database.
|
57
|
-
# @return [
|
57
|
+
# @return [Virtuaservices::utils::MicroService] the instance of the micro-service to chain other calls.
|
58
58
|
def register_as(service_name)
|
59
59
|
@name = service_name
|
60
60
|
return self
|
@@ -62,32 +62,32 @@ module Virtuaservices
|
|
62
62
|
|
63
63
|
# Sets the location of the file calling the micro service and initializing it so that it's used as root.
|
64
64
|
# @param filename [String] the full naame of the file with the extension.
|
65
|
-
# @return [
|
65
|
+
# @return [Virtuaservices::utils::MicroService] the instance of the micro-service to chain other calls.
|
66
66
|
def from_location(filename)
|
67
67
|
@location = File.dirname(filename)
|
68
68
|
return self
|
69
69
|
end
|
70
70
|
|
71
71
|
# Loads the application in standard (production/development) mode, without the test files.
|
72
|
-
# @return [
|
72
|
+
# @return [Virtuaservices::utils::MicroService] the instance of the micro-service to chain other calls.
|
73
73
|
def in_standard_mode
|
74
74
|
return load_application(test_mode: false)
|
75
75
|
end
|
76
76
|
|
77
77
|
# Loads the application in test mode, by adding the needed files to run the test suite to the standard loading process.
|
78
|
-
# @return [
|
78
|
+
# @return [Virtuaservices::utils::MicroService] the instance of the micro-service to chain other calls.
|
79
79
|
def in_test_mode
|
80
80
|
@location = File.join(location, '..')
|
81
81
|
return load_application(test_mode: true)
|
82
82
|
end
|
83
83
|
|
84
84
|
# Loads the application as a websockets service. Only the websockets application should use that.
|
85
|
-
# @return [
|
85
|
+
# @return [Virtuaservices::utils::MicroService] the instance of the micro-service to chain other calls.
|
86
86
|
def in_websocket_mode
|
87
87
|
load_mongoid_configuration
|
88
88
|
load_standard_files
|
89
89
|
|
90
|
-
|
90
|
+
Virtuaservices::Monitoring::Websocket.find_or_create_by(url: ENV['WEBSOCKET_URL']).save
|
91
91
|
return self
|
92
92
|
end
|
93
93
|
|
@@ -101,15 +101,15 @@ module Virtuaservices
|
|
101
101
|
|
102
102
|
# Registers the service in the database if it has not been created already.
|
103
103
|
def register_service
|
104
|
-
@service =
|
104
|
+
@service = Virtuaservices::Monitoring::Service.create(key: @name, path: "/#{@name}")
|
105
105
|
end
|
106
106
|
|
107
107
|
# Register the instance of the currently deployed service in the database.
|
108
|
-
# @return [
|
108
|
+
# @return [Virtuaservices::Monitoring::Instance] the instance of the micro service currently running.
|
109
109
|
def register_instance
|
110
110
|
@instance = @service.instances.where(url: ENV['SERVICE_URL']).first
|
111
111
|
if @instance.nil?
|
112
|
-
@instance =
|
112
|
+
@instance = Virtuaservices::Monitoring::Instance.create(service: @service, url: ENV['SERVICE_URL'], type: type)
|
113
113
|
end
|
114
114
|
@instance.update_attribute(:running, true)
|
115
115
|
return @instance
|
@@ -117,12 +117,12 @@ module Virtuaservices
|
|
117
117
|
|
118
118
|
# Loads the configuration for Mongoid, the files of the application, and registers the service and the instance in the database.
|
119
119
|
# @param test_mode [Boolean] TRUE to run in test mode (from /spec), FALSE otherwise.
|
120
|
-
# @return [
|
120
|
+
# @return [Virtuaservices::Utils::MicroService] the current instance of the micro service to chain other calls.
|
121
121
|
def load_application(test_mode: false)
|
122
122
|
Dotenv.load
|
123
123
|
load_mongoid_configuration(test_mode: test_mode)
|
124
124
|
if !!(@name && location)
|
125
|
-
@service =
|
125
|
+
@service = Virtuaservices::Monitoring::Service.where(key: @name).first
|
126
126
|
register_service if @service.nil?
|
127
127
|
if ENV['TEST_MODE']
|
128
128
|
@service.update_attribute(:test_mode, true)
|
@@ -139,8 +139,8 @@ module Virtuaservices
|
|
139
139
|
|
140
140
|
def load_plugin!
|
141
141
|
plugin = ENV['ADDITIONAL_PLUGIN']
|
142
|
-
if !plugin.nil? &&
|
143
|
-
|
142
|
+
if !plugin.nil? && Virtuaservices::Utils::Plugins.constants.include?(plugin)
|
143
|
+
Virtuaservices::Utils::Plugins.const_get(plugin).load!(@instance)
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
@@ -6,16 +6,16 @@ module Virtuaservices
|
|
6
6
|
include Singleton
|
7
7
|
|
8
8
|
# Creates the service if it does not exist, and the instance if it does not exist.
|
9
|
-
# @return [
|
9
|
+
# @return [Virtuaservices::Monitoring::Service] the created, or found, service corresponding to this micro-service.
|
10
10
|
def create_service(key)
|
11
|
-
service =
|
11
|
+
service = Virtuaservices::Monitoring::Service.where(key: key).first
|
12
12
|
|
13
13
|
if service.nil?
|
14
|
-
service =
|
14
|
+
service = Virtuaservices::Monitoring::Service.create!(key: key, path: "/#{key}", premium: true, active: true)
|
15
15
|
end
|
16
16
|
|
17
17
|
if service.instances.where(url: ENV['SERVICE_URL']).first.nil?
|
18
|
-
|
18
|
+
Virtuaservices::Monitoring::Instance.create!(url: ENV['SERVICE_URL'], running: true, service: service, active: true)
|
19
19
|
end
|
20
20
|
|
21
21
|
return service
|