Skip to content
Snippets Groups Projects
Commit b0a1c9c9 authored by Finn's avatar Finn
Browse files

Moved work function and context argument order.

Also moved the initialisation of these variables to
the `__init__` of `session.py`.
parent d1cef783
No related branches found
No related tags found
1 merge request!112Cancellation of leases.
......@@ -25,7 +25,7 @@ from buildgrid.settings import HASH_LENGTH
from buildgrid.utils import read_file, write_file
def work_buildbox(context, lease):
def work_buildbox(lease, context, event):
"""Executes a lease for a build action, using buildbox.
"""
local_cas_directory = context.local_cas
......
......@@ -20,7 +20,7 @@ from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_p
from buildgrid.utils import get_hostname
def work_dummy(context, lease):
def work_dummy(lease, context, event):
""" Just returns lease after some random time
"""
action_result = remote_execution_pb2.ActionResult()
......
......@@ -23,7 +23,7 @@ from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_p
from buildgrid.utils import get_hostname, output_file_maker, output_directory_maker
def work_host_tools(context, lease):
def work_host_tools(lease, context, event):
"""Executes a lease for a build action, using host tools.
"""
instance_name = context.parent
......
......@@ -27,8 +27,11 @@ from urllib.parse import urlparse
import click
import grpc
from buildgrid.bot import bot, bot_interface
from buildgrid.bot.bot_session import BotSession, Device, Worker
from buildgrid.bot import bot, interface, session
from buildgrid.bot.hardware.interface import HardwareInterface
from buildgrid.bot.hardware.device import Device
from buildgrid.bot.hardware.worker import Worker
from ..bots import buildbox, dummy, host
from ..cli import pass_context
......@@ -121,15 +124,13 @@ def cli(context, parent, update_period, remote, client_key, client_cert, server_
click.echo("Starting for remote=[{}]".format(context.remote))
interface = bot_interface.BotInterface(context.channel)
bot_interface = interface.BotInterface(context.channel)
worker = Worker()
worker.add_device(Device())
hardware_interface = HardwareInterface(worker)
bot_session = BotSession(parent, interface)
bot_session.add_worker(worker)
context.bot_session = bot_session
context.bot_interface = bot_interface
context.hardware_interface = hardware_interface
@cli.command('dummy', short_help="Run a dummy session simply returning leases.")
......@@ -139,9 +140,10 @@ def run_dummy(context):
Creates a session, accepts leases, does fake work and updates the server.
"""
try:
b = bot.Bot(context.bot_session, context.update_period)
b.session(dummy.work_dummy,
context)
bot_session = session.BotSession(context.parent, context.bot_interface, context.hardware_interface,
dummy.work_dummy, context)
b = bot.Bot(bot_session, context.update_period)
b.session()
except KeyboardInterrupt:
pass
......@@ -154,9 +156,10 @@ def run_host_tools(context):
result back to CAS.
"""
try:
b = bot.Bot(context.bot_session, context.update_period)
b.session(host.work_host_tools,
context)
bot_session = session.BotSession(context.parent, context.bot_interface, context.hardware_interface,
host.work_host_tools, context)
b = bot.Bot(bot_session, context.update_period)
b.session()
except KeyboardInterrupt:
pass
......@@ -175,8 +178,9 @@ def run_buildbox(context, local_cas, fuse_dir):
context.fuse_dir = fuse_dir
try:
b = bot.Bot(context.bot_session, context.update_period)
b.session(buildbox.work_buildbox,
context)
bot_session = session.BotSession(context.parent, context.bot_interface, context.hardware_interface,
buildbox.work_buildbox, context)
b = bot.Bot(bot_session, context.update_period)
b.session()
except KeyboardInterrupt:
pass
......@@ -13,16 +13,9 @@
# limitations under the License.
"""
Bot
====
Creates a bot session and sends updates to the server.
"""
import asyncio
import logging
import sys
class Bot:
"""Creates a local BotSession."""
......@@ -35,10 +28,13 @@ class Bot:
self.__bot_session = bot_session
self.__update_period = update_period
def session(self, work, context):
self.__loop = None
def session(self):
"""Will create a session and periodically call the server."""
self.__loop = asyncio.get_event_loop()
self.__bot_session.create_bot_session(work, context)
self.__bot_session.create_bot_session()
try:
task = asyncio.ensure_future(self.__update_bot_session())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment