rubypitaya 3.0.0 → 3.1.0
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 +4 -4
- data/lib/rubypitaya/app-template/Gemfile +3 -2
- data/lib/rubypitaya/app-template/Gemfile.lock +20 -28
- data/lib/rubypitaya/app-template/Makefile +1 -1
- data/lib/rubypitaya/app-template/app/app_initializer.rb +3 -1
- data/lib/rubypitaya/app-template/app/handlers/player_handler.rb +9 -3
- data/lib/rubypitaya/app-template/app/setup/rubypitaya.yml +1 -0
- data/lib/rubypitaya/app-template/docker/prod/Dockerfile +12 -3
- data/lib/rubypitaya/app-template/docker-compose.yml +4 -4
- data/lib/rubypitaya/app-template/helm/templates/deployments/rubypitaya.yaml +2 -0
- data/lib/rubypitaya/app-template/helm/templates/statefulsets/etcd.yaml +1 -1
- data/lib/rubypitaya/app-template/helm/templates/statefulsets/nats.yaml +1 -1
- data/lib/rubypitaya/app-template/helm/values.yaml +1 -0
- data/lib/rubypitaya/app-template/kubernetes/statefulset-etcd.yaml +1 -1
- data/lib/rubypitaya/app-template/kubernetes/statefulset-nats.yaml +1 -1
- data/lib/rubypitaya/app-template/kubernetes/statefulset-postgres.yaml +1 -1
- data/lib/rubypitaya/core/database_connector.rb +2 -1
- data/lib/rubypitaya/core/handler_base.rb +6 -5
- data/lib/rubypitaya/core/handler_router.rb +7 -2
- data/lib/rubypitaya/core/http_base.rb +20 -0
- data/lib/rubypitaya/core/http_routes.rb +1 -1
- data/lib/rubypitaya/core/instance_holder.rb +1 -1
- data/lib/rubypitaya/core/main.rb +5 -7
- data/lib/rubypitaya/core/nats_connector.rb +12 -57
- data/lib/rubypitaya/core/postman.rb +3 -1
- data/lib/rubypitaya/core/protos/nats_connector.proto +47 -0
- data/lib/rubypitaya/core/protos/nats_connector_pb.rb +56 -0
- data/lib/rubypitaya/core/spec-helpers/handler_spec_helper.rb +2 -1
- data/lib/rubypitaya/core/spec-helpers/setup_spec_helper.rb +4 -0
- data/lib/rubypitaya/core/templates/template_migration.rb.erb +4 -1
- data/lib/rubypitaya/version.rb +1 -1
- metadata +34 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7911d38f37f2dacf4f2e333312203b193910883ab4cbe3721f870e84b9c1bb6
|
4
|
+
data.tar.gz: d98bdeb07b6d3977b9dba2ac6fa2d3c5cfbb108b5e7d62b5e5453e3941e81a56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae45d9c08694c45d1825c0c6d741ce9080de86507de221fc9ba11e4d4cc5c2b53ad8a95e12b52be281e16b1ebf8a1278adbf6e07dca2445a0aecfa4d83455184
|
7
|
+
data.tar.gz: f8d1d8f3fff471f226cb2bae91d42aa135d26a4e0ffe253801344d9c55e6849f78adc7c861bb52302349a127a0da3adebad1c128eb00ea65cbe453b91ddb3fce
|
@@ -1,11 +1,12 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
gem 'rubypitaya', '3.
|
3
|
+
gem 'rubypitaya', '3.1.0'
|
4
4
|
|
5
5
|
group :development do
|
6
6
|
gem 'pry', '0.14.1'
|
7
|
-
gem 'bundler', '2.2.22'
|
8
7
|
gem 'rspec', '3.10.0'
|
9
8
|
gem 'listen', '3.7.0'
|
9
|
+
gem 'bundler', '2.2.22'
|
10
10
|
gem 'cucumber', '7.0.0'
|
11
|
+
gem 'sinatra-contrib', '2.1.0'
|
11
12
|
end
|
@@ -33,8 +33,8 @@ GEM
|
|
33
33
|
cucumber-gherkin (~> 20.0, >= 20.0.1)
|
34
34
|
cucumber-messages (~> 17.0, >= 17.0.1)
|
35
35
|
cucumber-tag-expressions (~> 3.0, >= 3.0.1)
|
36
|
-
cucumber-create-meta (6.0.
|
37
|
-
cucumber-messages (~> 17.
|
36
|
+
cucumber-create-meta (6.0.4)
|
37
|
+
cucumber-messages (~> 17.1, >= 17.1.1)
|
38
38
|
sys-uname (~> 1.2, >= 1.2.2)
|
39
39
|
cucumber-cucumber-expressions (12.1.3)
|
40
40
|
cucumber-gherkin (20.0.1)
|
@@ -52,24 +52,23 @@ GEM
|
|
52
52
|
grpc (~> 1.17)
|
53
53
|
eventmachine (1.2.7)
|
54
54
|
ffi (1.15.4)
|
55
|
-
google-protobuf (3.18.
|
56
|
-
googleapis-common-protos-types (1.
|
55
|
+
google-protobuf (3.18.1-x86_64-linux)
|
56
|
+
googleapis-common-protos-types (1.3.0)
|
57
57
|
google-protobuf (~> 3.14)
|
58
|
-
grpc (1.
|
59
|
-
google-protobuf (~> 3.
|
58
|
+
grpc (1.41.1-x86_64-linux)
|
59
|
+
google-protobuf (~> 3.17)
|
60
60
|
googleapis-common-protos-types (~> 1.0)
|
61
|
-
i18n (1.8.
|
61
|
+
i18n (1.8.11)
|
62
62
|
concurrent-ruby (~> 1.0)
|
63
63
|
listen (3.7.0)
|
64
64
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
65
65
|
rb-inotify (~> 0.9, >= 0.9.10)
|
66
66
|
method_source (1.0.0)
|
67
|
-
|
68
|
-
mime-types (3.3.1)
|
67
|
+
mime-types (3.4.1)
|
69
68
|
mime-types-data (~> 3.2015)
|
70
|
-
mime-types-data (3.2021.
|
69
|
+
mime-types-data (3.2021.1115)
|
71
70
|
minitest (5.14.4)
|
72
|
-
mongo (2.
|
71
|
+
mongo (2.16.0)
|
73
72
|
bson (>= 4.8.2, < 5.0.0)
|
74
73
|
multi_json (1.15.0)
|
75
74
|
multi_test (0.1.2)
|
@@ -79,11 +78,6 @@ GEM
|
|
79
78
|
eventmachine (~> 1.2, >= 1.2)
|
80
79
|
ostruct (0.4.0)
|
81
80
|
pg (1.2.3)
|
82
|
-
protobuf (3.10.4)
|
83
|
-
activesupport (>= 3.2)
|
84
|
-
middleware
|
85
|
-
thor
|
86
|
-
thread_safe
|
87
81
|
pry (0.14.1)
|
88
82
|
coderay (~> 1.1)
|
89
83
|
method_source (~> 1.0)
|
@@ -94,7 +88,7 @@ GEM
|
|
94
88
|
rb-fsevent (0.11.0)
|
95
89
|
rb-inotify (0.10.1)
|
96
90
|
ffi (~> 1.0)
|
97
|
-
redis (4.
|
91
|
+
redis (4.5.1)
|
98
92
|
rspec (3.10.0)
|
99
93
|
rspec-core (~> 3.10.0)
|
100
94
|
rspec-expectations (~> 3.10.0)
|
@@ -107,20 +101,19 @@ GEM
|
|
107
101
|
rspec-mocks (3.10.2)
|
108
102
|
diff-lcs (>= 1.2.0, < 2.0)
|
109
103
|
rspec-support (~> 3.10.0)
|
110
|
-
rspec-support (3.10.
|
104
|
+
rspec-support (3.10.3)
|
111
105
|
ruby2_keywords (0.0.5)
|
112
|
-
rubypitaya (3.
|
106
|
+
rubypitaya (3.1.0)
|
113
107
|
activerecord (= 6.1.4.1)
|
114
108
|
etcdv3 (= 0.11.4)
|
115
|
-
|
109
|
+
google-protobuf (= 3.18.1)
|
110
|
+
mongo (= 2.16.0)
|
116
111
|
nats (= 0.11.0)
|
117
112
|
ostruct (= 0.4.0)
|
118
113
|
pg (= 1.2.3)
|
119
|
-
protobuf (= 3.10.4)
|
120
114
|
rake (= 13.0.6)
|
121
|
-
redis (= 4.
|
115
|
+
redis (= 4.5.1)
|
122
116
|
sinatra (= 2.1.0)
|
123
|
-
sinatra-contrib (= 2.1.0)
|
124
117
|
webrick (= 1.7.0)
|
125
118
|
sinatra (2.1.0)
|
126
119
|
mustermann (~> 1.0)
|
@@ -135,16 +128,14 @@ GEM
|
|
135
128
|
tilt (~> 2.0)
|
136
129
|
sys-uname (1.2.2)
|
137
130
|
ffi (~> 1.1)
|
138
|
-
thor (1.1.0)
|
139
|
-
thread_safe (0.3.6)
|
140
131
|
tilt (2.0.10)
|
141
132
|
tzinfo (2.0.4)
|
142
133
|
concurrent-ruby (~> 1.0)
|
143
134
|
webrick (1.7.0)
|
144
|
-
zeitwerk (2.
|
135
|
+
zeitwerk (2.5.1)
|
145
136
|
|
146
137
|
PLATFORMS
|
147
|
-
|
138
|
+
x86_64-linux
|
148
139
|
|
149
140
|
DEPENDENCIES
|
150
141
|
bundler (= 2.2.22)
|
@@ -152,7 +143,8 @@ DEPENDENCIES
|
|
152
143
|
listen (= 3.7.0)
|
153
144
|
pry (= 0.14.1)
|
154
145
|
rspec (= 3.10.0)
|
155
|
-
rubypitaya (= 3.
|
146
|
+
rubypitaya (= 3.1.0)
|
147
|
+
sinatra-contrib (= 2.1.0)
|
156
148
|
|
157
149
|
BUNDLED WITH
|
158
150
|
2.2.22
|
@@ -36,7 +36,7 @@ test-rspec:
|
|
36
36
|
|
37
37
|
## Run cucumber tests. FILE=something.feature
|
38
38
|
test-cucumber:
|
39
|
-
@docker-compose run --service-ports --rm rubypitaya bundle exec cucumber $(FILE)
|
39
|
+
@docker-compose run --service-ports --rm rubypitaya bundle exec cucumber --publish-quiet $(FILE)
|
40
40
|
|
41
41
|
## Update gems dependencies on Gemfile.lock
|
42
42
|
update-dependencies:
|
@@ -5,9 +5,11 @@ class AppInitializer < RubyPitaya::InitializerBase
|
|
5
5
|
# attributes:
|
6
6
|
# - redis
|
7
7
|
# - link: https://github.com/redis/redis-rb/
|
8
|
+
#
|
8
9
|
# - mongo
|
9
10
|
# - class: Mongo::Client
|
10
11
|
# - link: https://docs.mongodb.com/ruby-driver/current/tutorials/quick-start/
|
12
|
+
#
|
11
13
|
# - config
|
12
14
|
# - class: RubyPitaya::Config
|
13
15
|
# - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/config.rb
|
@@ -30,7 +32,7 @@ class AppInitializer < RubyPitaya::InitializerBase
|
|
30
32
|
def run(initializer_content)
|
31
33
|
playerBll = PlayerBLL.new
|
32
34
|
|
33
|
-
PlayerHandler.
|
35
|
+
PlayerHandler.objects.add(:bll, playerBll)
|
34
36
|
end
|
35
37
|
|
36
38
|
def self.path
|
@@ -2,11 +2,11 @@ class PlayerHandler < RubyPitaya::HandlerBase
|
|
2
2
|
|
3
3
|
# class: HandlerBase
|
4
4
|
# attributes:
|
5
|
-
# - @
|
5
|
+
# - @objects
|
6
6
|
# - class: InstanceHolder
|
7
7
|
# - methods:
|
8
8
|
# - [](key)
|
9
|
-
# - info: get
|
9
|
+
# - info: get object by key
|
10
10
|
#
|
11
11
|
# - @redis
|
12
12
|
# - link: https://github.com/redis/redis-rb/
|
@@ -51,7 +51,7 @@ class PlayerHandler < RubyPitaya::HandlerBase
|
|
51
51
|
user_id = @params[:userId]
|
52
52
|
|
53
53
|
player = Player.find_by_user_id(user_id)
|
54
|
-
player =
|
54
|
+
player = bll.create_new_player(@setup, @config) if player.nil?
|
55
55
|
|
56
56
|
@session.uid = player.user_id
|
57
57
|
|
@@ -80,4 +80,10 @@ class PlayerHandler < RubyPitaya::HandlerBase
|
|
80
80
|
data: player.to_hash,
|
81
81
|
}
|
82
82
|
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def bll
|
87
|
+
@bll ||= @objects[:bll]
|
88
|
+
end
|
83
89
|
end
|
@@ -15,6 +15,18 @@ RUN bundle config --global jobs 4 && \
|
|
15
15
|
bundle config --global without "development test" && \
|
16
16
|
bundle install
|
17
17
|
|
18
|
+
RUN rm -rf /usr/local/bundle/cache && \
|
19
|
+
rm -rf /usr/local/bundle/build_info && \
|
20
|
+
rm -rf /usr/local/bundle/doc && \
|
21
|
+
rm -rf /usr/local/bundle/doc && \
|
22
|
+
find /usr/local/bundle/gems/grpc-*/src/ruby/lib/grpc/2.4/ -name "*.so" -delete && \
|
23
|
+
find /usr/local/bundle/gems/grpc-*/src/ruby/lib/grpc/2.5/ -name "*.so" -delete && \
|
24
|
+
find /usr/local/bundle/gems/grpc-*/src/ruby/lib/grpc/2.6/ -name "*.so" -delete && \
|
25
|
+
find /usr/local/bundle/gems/grpc-*/src/ruby/lib/grpc/2.7/ -name "*.so" -delete && \
|
26
|
+
find /usr/local/bundle/gems/ -name "*.c" -delete && \
|
27
|
+
find /usr/local/bundle/gems/ -name "*.o" -delete && \
|
28
|
+
find /usr/local/bundle/gems/ -name "spec" -exec rm -rv {} +
|
29
|
+
|
18
30
|
# RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
|
19
31
|
|
20
32
|
FROM ruby:3.0.2-slim
|
@@ -29,9 +41,6 @@ RUN apt update && \
|
|
29
41
|
&& rm -rf /var/lib/apt/lists/*
|
30
42
|
|
31
43
|
COPY --from=builder /usr/local/bundle /usr/local/bundle
|
32
|
-
RUN rm -rf /usr/local/bundle/cache
|
33
|
-
RUN rm -rf /usr/local/bundle/build_info
|
34
|
-
RUN rm -rf /usr/local/bundle/doc
|
35
44
|
|
36
45
|
# COPY --from=builder /kubectl /usr/local/bin/kubectl
|
37
46
|
# RUN chmod +x /usr/local/bin/kubectl
|
@@ -1,12 +1,12 @@
|
|
1
1
|
version: '3'
|
2
2
|
services:
|
3
3
|
nats:
|
4
|
-
image: 'nats:2.
|
4
|
+
image: 'nats:2.6.2-alpine'
|
5
5
|
ports:
|
6
6
|
- '4222:4222'
|
7
7
|
|
8
8
|
etcd:
|
9
|
-
image: 'appcelerator/etcd:3.
|
9
|
+
image: 'appcelerator/etcd:3.3.3'
|
10
10
|
ports:
|
11
11
|
- '2379:2379'
|
12
12
|
- '2380:2380'
|
@@ -17,7 +17,7 @@ services:
|
|
17
17
|
- '9001:6379'
|
18
18
|
|
19
19
|
db:
|
20
|
-
image: 'postgres:
|
20
|
+
image: 'postgres:14.0-alpine'
|
21
21
|
volumes:
|
22
22
|
- 'postgres:/var/lib/postgresql/data'
|
23
23
|
environment:
|
@@ -27,7 +27,7 @@ services:
|
|
27
27
|
- '9100:5432'
|
28
28
|
|
29
29
|
mongo:
|
30
|
-
image: mongo:5.0.
|
30
|
+
image: mongo:5.0.3
|
31
31
|
restart: always
|
32
32
|
ports:
|
33
33
|
- 27017:27017
|
@@ -27,6 +27,8 @@ spec:
|
|
27
27
|
env:
|
28
28
|
- name: RUBYPITAYA_SERVER_ENVIRONMENT
|
29
29
|
value: {{ .Values.rubypitaya.server.environment | quote }}
|
30
|
+
- name: RUBYPITAYA_SERVER_CHEATS
|
31
|
+
value: {{ .Values.rubypitaya.server.cheats | quote }}
|
30
32
|
- name: RUBYPITAYA_NATS_URL
|
31
33
|
value: "nats://nats.{{ .Values.namespace }}.svc.cluster.local:4222"
|
32
34
|
- name: RUBYPITAYA_ETCD_URL
|
@@ -5,9 +5,9 @@ module RubyPitaya
|
|
5
5
|
class HandlerBase
|
6
6
|
|
7
7
|
class_attribute :non_authenticated_routes, default: []
|
8
|
-
class_attribute :
|
8
|
+
class_attribute :handler_objects, default: nil, instance_reader: false, instance_writer: false, instance_accessor: false, instance_predicate: false
|
9
9
|
|
10
|
-
attr_reader :
|
10
|
+
attr_reader :objects, :log, :redis, :setup, :config, :params, :session, :postman
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
@log = nil
|
@@ -18,7 +18,7 @@ module RubyPitaya
|
|
18
18
|
@session = nil
|
19
19
|
@postman = nil
|
20
20
|
|
21
|
-
@
|
21
|
+
@objects = self.class.objects
|
22
22
|
end
|
23
23
|
|
24
24
|
def set_attributes(log, redis, mongo, setup, config, params, session, postman)
|
@@ -32,8 +32,9 @@ module RubyPitaya
|
|
32
32
|
@postman = postman
|
33
33
|
end
|
34
34
|
|
35
|
-
def self.
|
36
|
-
self.
|
35
|
+
def self.objects
|
36
|
+
self.handler_objects ||= InstanceHolder.new
|
37
|
+
return self.handler_objects
|
37
38
|
end
|
38
39
|
|
39
40
|
def self.non_authenticated_actions(*action_names)
|
@@ -8,7 +8,9 @@ module RubyPitaya
|
|
8
8
|
|
9
9
|
INVALID_ACTION_NAMES = ['initialize', 'set_attributes']
|
10
10
|
|
11
|
-
def initialize()
|
11
|
+
def initialize(is_cheats_enabled)
|
12
|
+
@is_cheats_enabled = is_cheats_enabled
|
13
|
+
|
12
14
|
routes_path = Path::ROUTES_FILE_PATH
|
13
15
|
handler_folder_paths = Path::Plugins::HANDLERS_FOLDER_PATHS + [Path::HANDLERS_FOLDER_PATH]
|
14
16
|
|
@@ -35,7 +37,10 @@ module RubyPitaya
|
|
35
37
|
end
|
36
38
|
|
37
39
|
def import_handler_files(handler_folder_path)
|
38
|
-
Gem.find_files("#{handler_folder_path}/*.rb")
|
40
|
+
handler_files = Gem.find_files("#{handler_folder_path}/*.rb")
|
41
|
+
handler_files = handler_files.select { |a| !a[/.+_cheats.rb/] && !a[/.+_cheat.rb/] } unless @is_cheats_enabled
|
42
|
+
|
43
|
+
handler_files.each { |path| require path }
|
39
44
|
end
|
40
45
|
|
41
46
|
def import_handler_classes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubypitaya/core/instance_holder'
|
2
|
+
|
3
|
+
module RubyPitaya
|
4
|
+
|
5
|
+
class HttpBase
|
6
|
+
|
7
|
+
class_attribute :handler_objects, default: nil, instance_reader: false, instance_writer: false, instance_accessor: false, instance_predicate: false
|
8
|
+
|
9
|
+
attr_reader :objects
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@objects = self.class.objects
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.objects
|
16
|
+
self.handler_objects ||= InstanceHolder.new
|
17
|
+
return self.handler_objects
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -23,12 +23,12 @@ module RubyPitaya
|
|
23
23
|
before do
|
24
24
|
content_type :json
|
25
25
|
|
26
|
-
@bll = settings.bll
|
27
26
|
@log = settings.log
|
28
27
|
@mongo = settings.mongo
|
29
28
|
@setup = settings.setup
|
30
29
|
@redis = settings.redis
|
31
30
|
@config = settings.config
|
31
|
+
@objects = settings.objects
|
32
32
|
@session = nil
|
33
33
|
@postman = nil
|
34
34
|
|
data/lib/rubypitaya/core/main.rb
CHANGED
@@ -28,8 +28,6 @@ module RubyPitaya
|
|
28
28
|
|
29
29
|
class Main
|
30
30
|
|
31
|
-
attr_reader :redis_connector, :config, :bll
|
32
|
-
|
33
31
|
def initialize
|
34
32
|
@setup = Setup.new
|
35
33
|
@environment_name = @setup.fetch('rubypitaya.server.environment', 'development')
|
@@ -69,7 +67,7 @@ module RubyPitaya
|
|
69
67
|
@redis_connector.connect
|
70
68
|
|
71
69
|
@database_config = DatabaseConfig.new
|
72
|
-
@database_connector = DatabaseConnector.new(@database_config)
|
70
|
+
@database_connector = DatabaseConnector.new(@database_config, @log)
|
73
71
|
@database_connector.connect
|
74
72
|
|
75
73
|
@mongo_address = @setup['rubypitaya.mongo.url']
|
@@ -85,7 +83,7 @@ module RubyPitaya
|
|
85
83
|
@config = Config.new
|
86
84
|
@config.auto_reload if @is_development_environment
|
87
85
|
|
88
|
-
@
|
86
|
+
@objects = InstanceHolder.new
|
89
87
|
|
90
88
|
@initializer_content = InitializerContent.new(@log,
|
91
89
|
@redis_connector.redis,
|
@@ -95,7 +93,8 @@ module RubyPitaya
|
|
95
93
|
@initializer_broadcast = InitializerBroadcast.new
|
96
94
|
@initializer_broadcast.run(@initializer_content)
|
97
95
|
|
98
|
-
@
|
96
|
+
@is_cheats_enabled = @setup.fetch('rubypitaya.server.cheats', false)
|
97
|
+
@handler_router = HandlerRouter.new(@is_cheats_enabled)
|
99
98
|
|
100
99
|
run_http
|
101
100
|
run_server
|
@@ -104,12 +103,12 @@ module RubyPitaya
|
|
104
103
|
private
|
105
104
|
|
106
105
|
def run_http
|
107
|
-
HttpRoutes.set :bll, @bll
|
108
106
|
HttpRoutes.set :log, @log
|
109
107
|
HttpRoutes.set :redis, @redis_connector.redis
|
110
108
|
HttpRoutes.set :mongo, @mongo_connector.mongo
|
111
109
|
HttpRoutes.set :setup, @setup
|
112
110
|
HttpRoutes.set :config, @config
|
111
|
+
HttpRoutes.set :objects, @objects
|
113
112
|
HttpRoutes.set :views, [Path::HTTP_VIEWS_PATH] + Path::Plugins::HTTP_VIEWS_PATHS
|
114
113
|
|
115
114
|
HttpRoutes.auto_reload if @is_development_environment
|
@@ -173,7 +172,6 @@ module RubyPitaya
|
|
173
172
|
@session.update(session_id, session_uid, session_data, metadata,
|
174
173
|
frontend_id)
|
175
174
|
|
176
|
-
# TODO: Validate if handler and action names are not nil
|
177
175
|
handler_name, action_name = message_route.scan(/\A\w+\.(\w+)\.(\w+)\z/)[0]
|
178
176
|
|
179
177
|
@log.info "request -> route: #{message_route}"
|
@@ -1,5 +1,7 @@
|
|
1
|
-
require 'protobuf'
|
2
1
|
require 'nats/client'
|
2
|
+
require 'google/protobuf'
|
3
|
+
|
4
|
+
require 'rubypitaya/core/protos/nats_connector_pb'
|
3
5
|
|
4
6
|
module RubyPitaya
|
5
7
|
|
@@ -23,14 +25,16 @@ module RubyPitaya
|
|
23
25
|
NATS.start(:servers => [@nats_address]) do |nc|
|
24
26
|
|
25
27
|
NATS.subscribe(subscribe_topic) do |message, reply, a, b|
|
26
|
-
request = NatsRequest.decode(message).
|
28
|
+
request = NatsRequest.decode(message).to_h
|
27
29
|
|
28
30
|
Fiber.new do
|
29
31
|
response = yield request
|
30
32
|
|
31
33
|
nats_response = NatsResponse.new(data: response.to_json)
|
32
34
|
|
33
|
-
|
35
|
+
response = NatsResponse.encode(nats_response)
|
36
|
+
|
37
|
+
NATS.publish(reply, response)
|
34
38
|
end.resume
|
35
39
|
end
|
36
40
|
|
@@ -61,8 +65,11 @@ module RubyPitaya
|
|
61
65
|
metadata: session.metadata.to_json,
|
62
66
|
)
|
63
67
|
|
64
|
-
|
65
|
-
|
68
|
+
request = NatsRequest.encode(nats_request)
|
69
|
+
|
70
|
+
nats_response = NATS.request(frontend_topic, request)
|
71
|
+
|
72
|
+
response = NatsResponse.decode(nats_response).to_h
|
66
73
|
|
67
74
|
response
|
68
75
|
end
|
@@ -93,56 +100,4 @@ module RubyPitaya
|
|
93
100
|
"pitaya/connector/user/#{uid}/push"
|
94
101
|
end
|
95
102
|
end
|
96
|
-
|
97
|
-
class NatsSession < ::Protobuf::Message; end
|
98
|
-
class NatsMessage < ::Protobuf::Message; end
|
99
|
-
class NatsRequest < ::Protobuf::Message; end
|
100
|
-
class NatsResponse < ::Protobuf::Message; end
|
101
|
-
class NatsError < ::Protobuf::Message; end
|
102
|
-
class NatsBindMsg < ::Protobuf::Message; end
|
103
|
-
class NatsPush < ::Protobuf::Message; end
|
104
|
-
|
105
|
-
class NatsSession
|
106
|
-
optional :int32, :id, 1
|
107
|
-
optional :bytes, :uid, 2
|
108
|
-
optional :bytes, :data, 3
|
109
|
-
end
|
110
|
-
|
111
|
-
class NatsMessage
|
112
|
-
optional :int32, :id, 1
|
113
|
-
optional :bytes, :route, 2
|
114
|
-
optional :bytes, :data, 3
|
115
|
-
optional :bytes, :reply, 4
|
116
|
-
optional :int32, :type, 5
|
117
|
-
end
|
118
|
-
|
119
|
-
class NatsRequest
|
120
|
-
optional :int32, :type, 1
|
121
|
-
optional NatsSession, :session, 2
|
122
|
-
optional NatsMessage, :msg, 3
|
123
|
-
optional :bytes, :frontendID, 4
|
124
|
-
optional :bytes, :metadata, 5
|
125
|
-
end
|
126
|
-
|
127
|
-
class NatsError
|
128
|
-
optional :bytes, :code, 1
|
129
|
-
optional :bytes, :message, 2
|
130
|
-
optional :bytes, :metadata, 3
|
131
|
-
end
|
132
|
-
|
133
|
-
class NatsResponse
|
134
|
-
optional :bytes, :data, 1
|
135
|
-
optional NatsError, :error, 2
|
136
|
-
end
|
137
|
-
|
138
|
-
class NatsBindMsg
|
139
|
-
optional :bytes, :uid, 1
|
140
|
-
optional :bytes, :fid, 2
|
141
|
-
end
|
142
|
-
|
143
|
-
class NatsPush
|
144
|
-
optional :bytes, :route, 1
|
145
|
-
optional :bytes, :uid, 2
|
146
|
-
optional :bytes, :data, 3
|
147
|
-
end
|
148
103
|
end
|
@@ -19,7 +19,9 @@ module RubyPitaya
|
|
19
19
|
data: session.data.to_json,
|
20
20
|
)
|
21
21
|
|
22
|
-
|
22
|
+
payload = NatsSession.encode(nats_session)
|
23
|
+
|
24
|
+
response = @nats_connector.push_to_frontend(session, route, payload)
|
23
25
|
|
24
26
|
response
|
25
27
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
syntax = "proto3";
|
2
|
+
|
3
|
+
package RubyPitaya;
|
4
|
+
|
5
|
+
message NatsSession {
|
6
|
+
optional int32 id = 1;
|
7
|
+
optional bytes uid = 2;
|
8
|
+
optional bytes data = 3;
|
9
|
+
}
|
10
|
+
|
11
|
+
message NatsMessage {
|
12
|
+
optional int32 id = 1;
|
13
|
+
optional bytes route = 2;
|
14
|
+
optional bytes data = 3;
|
15
|
+
optional bytes reply = 4;
|
16
|
+
optional int32 type = 5;
|
17
|
+
}
|
18
|
+
|
19
|
+
message NatsRequest {
|
20
|
+
optional int32 type = 1;
|
21
|
+
optional NatsSession session = 2;
|
22
|
+
optional NatsMessage msg = 3;
|
23
|
+
optional bytes frontendID = 4;
|
24
|
+
optional bytes metadata = 5;
|
25
|
+
}
|
26
|
+
|
27
|
+
message NatsError {
|
28
|
+
optional bytes code = 1;
|
29
|
+
optional bytes message = 2;
|
30
|
+
optional bytes metadata = 3;
|
31
|
+
}
|
32
|
+
|
33
|
+
message NatsResponse {
|
34
|
+
optional bytes data = 1;
|
35
|
+
optional NatsError error = 2;
|
36
|
+
}
|
37
|
+
|
38
|
+
message NatsBindMsg {
|
39
|
+
optional bytes uid = 1;
|
40
|
+
optional bytes fid = 2;
|
41
|
+
}
|
42
|
+
|
43
|
+
message NatsPush {
|
44
|
+
optional bytes route = 1;
|
45
|
+
optional bytes uid = 2;
|
46
|
+
optional bytes data = 3;
|
47
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: nats_connector.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
+
add_file("nats_connector.proto", :syntax => :proto3) do
|
8
|
+
add_message "RubyPitaya.NatsSession" do
|
9
|
+
proto3_optional :id, :int32, 1
|
10
|
+
proto3_optional :uid, :bytes, 2
|
11
|
+
proto3_optional :data, :bytes, 3
|
12
|
+
end
|
13
|
+
add_message "RubyPitaya.NatsMessage" do
|
14
|
+
proto3_optional :id, :int32, 1
|
15
|
+
proto3_optional :route, :bytes, 2
|
16
|
+
proto3_optional :data, :bytes, 3
|
17
|
+
proto3_optional :reply, :bytes, 4
|
18
|
+
proto3_optional :type, :int32, 5
|
19
|
+
end
|
20
|
+
add_message "RubyPitaya.NatsRequest" do
|
21
|
+
proto3_optional :type, :int32, 1
|
22
|
+
proto3_optional :session, :message, 2, "RubyPitaya.NatsSession"
|
23
|
+
proto3_optional :msg, :message, 3, "RubyPitaya.NatsMessage"
|
24
|
+
proto3_optional :frontendID, :bytes, 4
|
25
|
+
proto3_optional :metadata, :bytes, 5
|
26
|
+
end
|
27
|
+
add_message "RubyPitaya.NatsError" do
|
28
|
+
proto3_optional :code, :bytes, 1
|
29
|
+
proto3_optional :message, :bytes, 2
|
30
|
+
proto3_optional :metadata, :bytes, 3
|
31
|
+
end
|
32
|
+
add_message "RubyPitaya.NatsResponse" do
|
33
|
+
proto3_optional :data, :bytes, 1
|
34
|
+
proto3_optional :error, :message, 2, "RubyPitaya.NatsError"
|
35
|
+
end
|
36
|
+
add_message "RubyPitaya.NatsBindMsg" do
|
37
|
+
proto3_optional :uid, :bytes, 1
|
38
|
+
proto3_optional :fid, :bytes, 2
|
39
|
+
end
|
40
|
+
add_message "RubyPitaya.NatsPush" do
|
41
|
+
proto3_optional :route, :bytes, 1
|
42
|
+
proto3_optional :uid, :bytes, 2
|
43
|
+
proto3_optional :data, :bytes, 3
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
module RubyPitaya
|
49
|
+
NatsSession = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("RubyPitaya.NatsSession").msgclass
|
50
|
+
NatsMessage = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("RubyPitaya.NatsMessage").msgclass
|
51
|
+
NatsRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("RubyPitaya.NatsRequest").msgclass
|
52
|
+
NatsError = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("RubyPitaya.NatsError").msgclass
|
53
|
+
NatsResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("RubyPitaya.NatsResponse").msgclass
|
54
|
+
NatsBindMsg = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("RubyPitaya.NatsBindMsg").msgclass
|
55
|
+
NatsPush = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("RubyPitaya.NatsPush").msgclass
|
56
|
+
end
|
@@ -23,7 +23,8 @@ module RubyPitaya
|
|
23
23
|
initialize_redis
|
24
24
|
initialize_mongo
|
25
25
|
|
26
|
-
|
26
|
+
is_cheats_enabled = @@setup.fetch('rubypitaya.server.cheats', false)
|
27
|
+
@@handler_router ||= HandlerRouter.new(is_cheats_enabled)
|
27
28
|
|
28
29
|
|
29
30
|
@@initializer_content = InitializerContent.new(@@log,
|
@@ -2,11 +2,14 @@ require 'active_record'
|
|
2
2
|
|
3
3
|
class <%= class_name %> < ActiveRecord::Migration[6.1]
|
4
4
|
|
5
|
-
enable_extension 'pgcrypto'
|
5
|
+
enable_extension 'pgcrypto' unless extension_enabled?('pgcrypto')
|
6
|
+
|
7
|
+
# Migration suported types reference: https://guides.rubyonrails.org/v3.2/migrations.html#supported-types
|
6
8
|
|
7
9
|
def change
|
8
10
|
create_table :[table-name-here-in-plural], id: :uuid do |t|
|
9
11
|
# t.belongs_to :user, type: :uuid, foreing_key: true
|
12
|
+
# t.belongs_to :user, type: :uuid, foreing_key: true, index: { unique: true }
|
10
13
|
t.timestamps null: false
|
11
14
|
end
|
12
15
|
end
|
data/lib/rubypitaya/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubypitaya
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luciano Prestes Cavalcanti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -58,28 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 2.
|
61
|
+
version: 2.16.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 2.
|
68
|
+
version: 2.16.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: redis
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 4.
|
75
|
+
version: 4.5.1
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 4.
|
82
|
+
version: 4.5.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: etcdv3
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,117 +137,117 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 1.7.0
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: activerecord
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - '='
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
145
|
+
version: 6.1.4.1
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - '='
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
152
|
+
version: 6.1.4.1
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: google-protobuf
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - '='
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
159
|
+
version: 3.18.1
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - '='
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
166
|
+
version: 3.18.1
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
168
|
+
name: pry
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - '='
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
174
|
-
type: :
|
173
|
+
version: 0.14.1
|
174
|
+
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - '='
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
180
|
+
version: 0.14.1
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
182
|
+
name: rspec
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
185
|
- - '='
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
187
|
+
version: 3.10.0
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - '='
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version:
|
194
|
+
version: 3.10.0
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
|
-
name:
|
196
|
+
name: listen
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
199
|
- - '='
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version:
|
201
|
+
version: 3.7.0
|
202
202
|
type: :development
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
206
|
- - '='
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version:
|
208
|
+
version: 3.7.0
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
|
-
name:
|
210
|
+
name: bundler
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
213
|
- - '='
|
214
214
|
- !ruby/object:Gem::Version
|
215
|
-
version:
|
215
|
+
version: 2.2.22
|
216
216
|
type: :development
|
217
217
|
prerelease: false
|
218
218
|
version_requirements: !ruby/object:Gem::Requirement
|
219
219
|
requirements:
|
220
220
|
- - '='
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
version:
|
222
|
+
version: 2.2.22
|
223
223
|
- !ruby/object:Gem::Dependency
|
224
|
-
name:
|
224
|
+
name: cucumber
|
225
225
|
requirement: !ruby/object:Gem::Requirement
|
226
226
|
requirements:
|
227
227
|
- - '='
|
228
228
|
- !ruby/object:Gem::Version
|
229
|
-
version:
|
229
|
+
version: 7.0.0
|
230
230
|
type: :development
|
231
231
|
prerelease: false
|
232
232
|
version_requirements: !ruby/object:Gem::Requirement
|
233
233
|
requirements:
|
234
234
|
- - '='
|
235
235
|
- !ruby/object:Gem::Version
|
236
|
-
version:
|
236
|
+
version: 7.0.0
|
237
237
|
- !ruby/object:Gem::Dependency
|
238
|
-
name:
|
238
|
+
name: sinatra-contrib
|
239
239
|
requirement: !ruby/object:Gem::Requirement
|
240
240
|
requirements:
|
241
241
|
- - '='
|
242
242
|
- !ruby/object:Gem::Version
|
243
|
-
version:
|
243
|
+
version: 2.1.0
|
244
244
|
type: :development
|
245
245
|
prerelease: false
|
246
246
|
version_requirements: !ruby/object:Gem::Requirement
|
247
247
|
requirements:
|
248
248
|
- - '='
|
249
249
|
- !ruby/object:Gem::Version
|
250
|
-
version:
|
250
|
+
version: 2.1.0
|
251
251
|
description: RubyPitaya is an application to create servers using the pitaya protocol.
|
252
252
|
email:
|
253
253
|
- lucianopcbr@gmail.com
|
@@ -342,6 +342,7 @@ files:
|
|
342
342
|
- "./lib/rubypitaya/core/handler_base.rb"
|
343
343
|
- "./lib/rubypitaya/core/handler_router.rb"
|
344
344
|
- "./lib/rubypitaya/core/helpers/setup_helper.rb"
|
345
|
+
- "./lib/rubypitaya/core/http_base.rb"
|
345
346
|
- "./lib/rubypitaya/core/http_routes.rb"
|
346
347
|
- "./lib/rubypitaya/core/initializer_base.rb"
|
347
348
|
- "./lib/rubypitaya/core/initializer_broadcast.rb"
|
@@ -353,6 +354,8 @@ files:
|
|
353
354
|
- "./lib/rubypitaya/core/parameters.rb"
|
354
355
|
- "./lib/rubypitaya/core/path.rb"
|
355
356
|
- "./lib/rubypitaya/core/postman.rb"
|
357
|
+
- "./lib/rubypitaya/core/protos/nats_connector.proto"
|
358
|
+
- "./lib/rubypitaya/core/protos/nats_connector_pb.rb"
|
356
359
|
- "./lib/rubypitaya/core/redis_connector.rb"
|
357
360
|
- "./lib/rubypitaya/core/routes_base.rb"
|
358
361
|
- "./lib/rubypitaya/core/session.rb"
|