Skip to content

Switch Trigger Service main loop data structure #1206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Trigger(Service):
def __init__(self, configs, args):
super().__init__(configs, args, 'trigger')
self._build_configs = configs['build_configs']
self._trees = configs['trees']
self._current_user = self._api.user.whoami()

def _log_revision(self, message, build_config, head_commit):
Expand Down Expand Up @@ -134,27 +135,25 @@ def _run_trigger(self, build_config, force, timeout, trees):
except Exception as ex:
self.traceback(ex)

def _iterate_build_configs(self, force, build_configs_list,
timeout, trees):
for name, config in self._build_configs.items():
if not build_configs_list or name in build_configs_list:
def _iterate_trees(self, force, timeout, trees):
for tree in self._trees.keys():
build_configs = {name: config for name, config in self._build_configs.items() if config.tree.name == tree}
for name, config in build_configs.items():
self._run_trigger(config, force, timeout, trees)

def _setup(self, args):
return {
'poll_period': int(args.poll_period),
'force': args.force,
'build_configs_list': (args.build_configs or '').split(),
'startup_delay': int(args.startup_delay or 0),
'timeout': args.timeout,
'trees': args.trees,
}

def _run(self, ctx):
poll_period, force, build_configs_list, startup_delay, timeout, trees = (
poll_period, force, startup_delay, timeout, trees = (
ctx[key] for key in (
'poll_period', 'force', 'build_configs_list', 'startup_delay',
'timeout', 'trees'
'poll_period', 'force', 'startup_delay', 'timeout', 'trees'
)
)

Expand All @@ -163,8 +162,7 @@ def _run(self, ctx):
time.sleep(startup_delay)

while True:
self._iterate_build_configs(force, build_configs_list,
timeout, trees)
self._iterate_trees(force, timeout, trees)
if poll_period:
self.log.info(f"Sleeping for {poll_period}s")
time.sleep(poll_period)
Expand All @@ -191,10 +189,6 @@ class cmd_run(Command):
'action': 'store_true',
'help': "Always create a new checkout node",
},
{
'name': '--build-configs',
'help': "List of build configurations to monitor",
},
{
'name': '--name',
'help': "Name of pipeline instance",
Expand Down