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
e487a7b7
Commit
e487a7b7
authored
6 years ago
by
Martin Blanchard
Browse files
Options
Downloads
Patches
Plain Diff
Handle the server's main event loop internally
parent
47fa6438
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
+33
-21
33 additions, 21 deletions
buildgrid/server/instance.py
with
33 additions
and
26 deletions
buildgrid/_app/commands/cmd_server.py
+
0
−
5
View file @
e487a7b7
...
...
@@ -20,7 +20,6 @@ Server command
Create a BuildGrid server.
"""
import
asyncio
import
logging
import
sys
...
...
@@ -52,18 +51,14 @@ def start(context, config):
click
.
echo
(
"
ERROR: Could not parse config: {}.
\n
"
.
format
(
str
(
e
)),
err
=
True
)
sys
.
exit
(
-
1
)
loop
=
asyncio
.
get_event_loop
()
try
:
server
.
start
()
loop
.
run_forever
()
except
KeyboardInterrupt
:
pass
finally
:
context
.
logger
.
info
(
"
Stopping server
"
)
server
.
stop
()
loop
.
close
()
def
_create_server_from_config
(
config
):
...
...
This diff is collapsed.
Click to expand it.
buildgrid/server/instance.py
+
33
−
21
View file @
e487a7b7
...
...
@@ -13,18 +13,20 @@
# limitations under the License.
import
asyncio
from
concurrent
import
futures
import
logging
import
os
import
time
import
grpc
from
.cas.service
import
ByteStreamService
,
ContentAddressableStorageService
from
.actioncache.service
import
ActionCacheService
from
.execution.service
import
ExecutionService
from
.operations.service
import
OperationsService
from
.bots.service
import
BotsService
from
.referencestorage.service
import
ReferenceStorageService
from
buildgrid.server
.cas.service
import
ByteStreamService
,
ContentAddressableStorageService
from
buildgrid.server
.actioncache.service
import
ActionCacheService
from
buildgrid.server
.execution.service
import
ExecutionService
from
buildgrid.server
.operations.service
import
OperationsService
from
buildgrid.server
.bots.service
import
BotsService
from
buildgrid.server
.referencestorage.service
import
ReferenceStorageService
class
BuildGridServer
:
...
...
@@ -46,9 +48,10 @@ class BuildGridServer:
# Use max_workers default from Python 3.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
.
_bots_service
=
None
...
...
@@ -59,14 +62,23 @@ class BuildGridServer:
self
.
_bytestream_service
=
None
def
start
(
self
):
"""
Starts the server.
"""
Starts the
BuildGrid
server.
"""
self
.
_server
.
start
()
self
.
__grpc_server
.
start
()
self
.
__main_loop
.
run_forever
()
def
stop
(
self
,
grace
=
0
):
"""
Stops the server.
"""
Stops the BuildGrid server.
Args:
grace (int, optional): A duration of time in seconds. Defaults to 0.
"""
self
.
_server
.
stop
(
grace
)
self
.
__main_loop
.
close
()
self
.
__grpc_server
.
stop
(
grace
)
if
grace
>
0
:
time
.
sleep
(
grace
)
def
add_port
(
self
,
address
,
credentials
):
"""
Adds a port to the server.
...
...
@@ -80,11 +92,11 @@ class BuildGridServer:
"""
if
credentials
is
not
None
:
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
:
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
):
"""
Adds an :obj:`ExecutionInstance` to the service.
...
...
@@ -96,7 +108,7 @@ class BuildGridServer:
instance_name (str): Instance name.
"""
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
)
...
...
@@ -110,7 +122,7 @@ class BuildGridServer:
instance_name (str): Instance name.
"""
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
)
...
...
@@ -124,7 +136,7 @@ class BuildGridServer:
instance_name (str): Instance name.
"""
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
)
...
...
@@ -138,7 +150,7 @@ class BuildGridServer:
instance_name (str): Instance name.
"""
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
)
...
...
@@ -152,7 +164,7 @@ class BuildGridServer:
instance_name (str): Instance name.
"""
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
)
...
...
@@ -166,7 +178,7 @@ class BuildGridServer:
instance_name (str): Instance name.
"""
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
)
...
...
@@ -180,6 +192,6 @@ class BuildGridServer:
instance_name (str): Instance name.
"""
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
)
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