Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
buildgrid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
Show more breadcrumbs
BuildGrid
buildgrid
Commits
63231721
Commit
63231721
authored
6 years ago
by
Martin Blanchard
Browse files
Options
Downloads
Patches
Plain Diff
Handle the server's main event loop internally
This turns Server.start() into a blocking call!
#135
parent
a770c779
No related branches found
No related tags found
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
buildgrid/_app/commands/cmd_server.py
+0
-5
0 additions, 5 deletions
buildgrid/_app/commands/cmd_server.py
buildgrid/server/instance.py
+28
-24
28 additions, 24 deletions
buildgrid/server/instance.py
with
28 additions
and
29 deletions
buildgrid/_app/commands/cmd_server.py
+
0
−
5
View file @
63231721
...
@@ -20,7 +20,6 @@ Server command
...
@@ -20,7 +20,6 @@ Server command
Create a BuildGrid server.
Create a BuildGrid server.
"""
"""
import
asyncio
import
sys
import
sys
import
click
import
click
...
@@ -51,18 +50,14 @@ def start(context, config):
...
@@ -51,18 +50,14 @@ def start(context, config):
click
.
echo
(
"
ERROR: Could not parse config: {}.
\n
"
.
format
(
str
(
e
)),
err
=
True
)
click
.
echo
(
"
ERROR: Could not parse config: {}.
\n
"
.
format
(
str
(
e
)),
err
=
True
)
sys
.
exit
(
-
1
)
sys
.
exit
(
-
1
)
loop
=
asyncio
.
get_event_loop
()
try
:
try
:
server
.
start
()
server
.
start
()
loop
.
run_forever
()
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
pass
pass
finally
:
finally
:
click
.
echo
(
"
Stopping server
"
)
server
.
stop
()
server
.
stop
()
loop
.
close
()
def
_create_server_from_config
(
config
):
def
_create_server_from_config
(
config
):
...
...
This diff is collapsed.
Click to expand it.
buildgrid/server/instance.py
+
28
−
24
View file @
63231721
...
@@ -13,18 +13,19 @@
...
@@ -13,18 +13,19 @@
# limitations under the License.
# limitations under the License.
import
asyncio
from
concurrent
import
futures
from
concurrent
import
futures
import
logging
import
logging
import
os
import
os
import
grpc
import
grpc
from
.cas.service
import
ByteStreamService
,
ContentAddressableStorag
eService
from
buildgrid.server.actioncache.service
import
ActionCach
eService
from
.actioncache
.service
import
ActionCache
Service
from
buildgrid.server.bots
.service
import
Bots
Service
from
.execution.service
import
Execution
Service
from
buildgrid.server.cas.service
import
ByteStreamService
,
ContentAddressableStorage
Service
from
.opera
tion
s
.service
import
Opera
tion
s
Service
from
buildgrid.server.execu
tion.service
import
Execu
tionService
from
.bot
s.service
import
Bot
sService
from
buildgrid.server.operation
s.service
import
Operation
sService
from
.referencestorage.service
import
ReferenceStorageService
from
buildgrid.server
.referencestorage.service
import
ReferenceStorageService
class
BuildGridServer
:
class
BuildGridServer
:
...
@@ -46,9 +47,10 @@ class BuildGridServer:
...
@@ -46,9 +47,10 @@ class BuildGridServer:
# Use max_workers default from Python 3.5+
# Use max_workers default from Python 3.5+
max_workers
=
(
os
.
cpu_count
()
or
1
)
*
5
max_workers
=
(
os
.
cpu_count
()
or
1
)
*
5
server
=
grpc
.
server
(
futures
.
ThreadPoolExecutor
(
max_workers
))
self
.
__grpc_executor
=
futures
.
ThreadPoolExecutor
(
max_workers
)
self
.
__grpc_server
=
grpc
.
server
(
self
.
__grpc_executor
)
self
.
_
server
=
server
self
.
_
_main_loop
=
asyncio
.
get_event_loop
()
self
.
_execution_service
=
None
self
.
_execution_service
=
None
self
.
_bots_service
=
None
self
.
_bots_service
=
None
...
@@ -59,14 +61,16 @@ class BuildGridServer:
...
@@ -59,14 +61,16 @@ class BuildGridServer:
self
.
_bytestream_service
=
None
self
.
_bytestream_service
=
None
def
start
(
self
):
def
start
(
self
):
"""
Starts the server.
"""
Starts the BuildGrid server.
"""
"""
self
.
__grpc_server
.
start
()
self
.
_server
.
start
()
def
stop
(
self
,
grace
=
0
):
self
.
__main_loop
.
run_forever
()
"""
Stops the server.
"""
def
stop
(
self
):
self
.
_server
.
stop
(
grace
)
"""
Stops the BuildGrid server.
"""
self
.
__main_loop
.
close
()
self
.
__grpc_server
.
stop
(
None
)
def
add_port
(
self
,
address
,
credentials
):
def
add_port
(
self
,
address
,
credentials
):
"""
Adds a port to the server.
"""
Adds a port to the server.
...
@@ -80,11 +84,11 @@ class BuildGridServer:
...
@@ -80,11 +84,11 @@ class BuildGridServer:
"""
"""
if
credentials
is
not
None
:
if
credentials
is
not
None
:
self
.
__logger
.
info
(
"
Adding secure connection on: [%s]
"
,
address
)
self
.
__logger
.
info
(
"
Adding secure connection on: [%s]
"
,
address
)
self
.
_server
.
add_secure_port
(
address
,
credentials
)
self
.
_
_grpc_
server
.
add_secure_port
(
address
,
credentials
)
else
:
else
:
self
.
__logger
.
info
(
"
Adding insecure connection on [%s]
"
,
address
)
self
.
__logger
.
info
(
"
Adding insecure connection on [%s]
"
,
address
)
self
.
_server
.
add_insecure_port
(
address
)
self
.
_
_grpc_
server
.
add_insecure_port
(
address
)
def
add_execution_instance
(
self
,
instance
,
instance_name
):
def
add_execution_instance
(
self
,
instance
,
instance_name
):
"""
Adds an :obj:`ExecutionInstance` to the service.
"""
Adds an :obj:`ExecutionInstance` to the service.
...
@@ -96,7 +100,7 @@ class BuildGridServer:
...
@@ -96,7 +100,7 @@ class BuildGridServer:
instance_name (str): Instance name.
instance_name (str): Instance name.
"""
"""
if
self
.
_execution_service
is
None
:
if
self
.
_execution_service
is
None
:
self
.
_execution_service
=
ExecutionService
(
self
.
_server
)
self
.
_execution_service
=
ExecutionService
(
self
.
_
_grpc_
server
)
self
.
_execution_service
.
add_instance
(
instance_name
,
instance
)
self
.
_execution_service
.
add_instance
(
instance_name
,
instance
)
...
@@ -110,7 +114,7 @@ class BuildGridServer:
...
@@ -110,7 +114,7 @@ class BuildGridServer:
instance_name (str): Instance name.
instance_name (str): Instance name.
"""
"""
if
self
.
_bots_service
is
None
:
if
self
.
_bots_service
is
None
:
self
.
_bots_service
=
BotsService
(
self
.
_server
)
self
.
_bots_service
=
BotsService
(
self
.
_
_grpc_
server
)
self
.
_bots_service
.
add_instance
(
instance_name
,
instance
)
self
.
_bots_service
.
add_instance
(
instance_name
,
instance
)
...
@@ -124,7 +128,7 @@ class BuildGridServer:
...
@@ -124,7 +128,7 @@ class BuildGridServer:
instance_name (str): Instance name.
instance_name (str): Instance name.
"""
"""
if
self
.
_operations_service
is
None
:
if
self
.
_operations_service
is
None
:
self
.
_operations_service
=
OperationsService
(
self
.
_server
)
self
.
_operations_service
=
OperationsService
(
self
.
_
_grpc_
server
)
self
.
_operations_service
.
add_instance
(
instance_name
,
instance
)
self
.
_operations_service
.
add_instance
(
instance_name
,
instance
)
...
@@ -138,7 +142,7 @@ class BuildGridServer:
...
@@ -138,7 +142,7 @@ class BuildGridServer:
instance_name (str): Instance name.
instance_name (str): Instance name.
"""
"""
if
self
.
_reference_storage_service
is
None
:
if
self
.
_reference_storage_service
is
None
:
self
.
_reference_storage_service
=
ReferenceStorageService
(
self
.
_server
)
self
.
_reference_storage_service
=
ReferenceStorageService
(
self
.
_
_grpc_
server
)
self
.
_reference_storage_service
.
add_instance
(
instance_name
,
instance
)
self
.
_reference_storage_service
.
add_instance
(
instance_name
,
instance
)
...
@@ -152,7 +156,7 @@ class BuildGridServer:
...
@@ -152,7 +156,7 @@ class BuildGridServer:
instance_name (str): Instance name.
instance_name (str): Instance name.
"""
"""
if
self
.
_action_cache_service
is
None
:
if
self
.
_action_cache_service
is
None
:
self
.
_action_cache_service
=
ActionCacheService
(
self
.
_server
)
self
.
_action_cache_service
=
ActionCacheService
(
self
.
_
_grpc_
server
)
self
.
_action_cache_service
.
add_instance
(
instance_name
,
instance
)
self
.
_action_cache_service
.
add_instance
(
instance_name
,
instance
)
...
@@ -166,7 +170,7 @@ class BuildGridServer:
...
@@ -166,7 +170,7 @@ class BuildGridServer:
instance_name (str): Instance name.
instance_name (str): Instance name.
"""
"""
if
self
.
_cas_service
is
None
:
if
self
.
_cas_service
is
None
:
self
.
_cas_service
=
ContentAddressableStorageService
(
self
.
_server
)
self
.
_cas_service
=
ContentAddressableStorageService
(
self
.
_
_grpc_
server
)
self
.
_cas_service
.
add_instance
(
instance_name
,
instance
)
self
.
_cas_service
.
add_instance
(
instance_name
,
instance
)
...
@@ -180,6 +184,6 @@ class BuildGridServer:
...
@@ -180,6 +184,6 @@ class BuildGridServer:
instance_name (str): Instance name.
instance_name (str): Instance name.
"""
"""
if
self
.
_bytestream_service
is
None
:
if
self
.
_bytestream_service
is
None
:
self
.
_bytestream_service
=
ByteStreamService
(
self
.
_server
)
self
.
_bytestream_service
=
ByteStreamService
(
self
.
_
_grpc_
server
)
self
.
_bytestream_service
.
add_instance
(
instance_name
,
instance
)
self
.
_bytestream_service
.
add_instance
(
instance_name
,
instance
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment