Merge "Add an init phase to scheduler/web startup"

This commit is contained in:
Zuul 2021-11-17 07:09:41 +00:00 committed by Gerrit Code Review
commit 08e81187c3
8 changed files with 33 additions and 1 deletions

View File

@ -30,6 +30,7 @@ import {
RunningIcon,
QuestionIcon,
StopCircleIcon,
HistoryIcon,
} from '@patternfly/react-icons'
import { IconProperty } from '../build/Misc'
@ -39,6 +40,10 @@ const STATE_ICON_CONFIGS = {
icon: RunningIcon,
color: 'var(--pf-global--success-color--100)',
},
INITIALIZING: {
icon: HistoryIcon,
color: 'var(--pf-global--warning-color--100)',
},
PAUSED: {
icon: PauseCircleIcon,
color: 'var(--pf-global--warning-color--100)',

View File

@ -181,6 +181,11 @@ class GerritEventConnector(threading.Thread):
return not self._stopped
def run(self):
# Wait for the scheduler to prime its config so that we have
# the full tenant list before we start moving events.
self.connection.sched.primed_event.wait()
if self._stopped:
return
self.event_queue.registerEventWatch(self._onNewEvent)
while not self._stopped:
try:

View File

@ -693,6 +693,11 @@ class GithubEventConnector:
return not self._stopped
def run_event_dispatcher(self):
# Wait for the scheduler to prime its config so that we have
# the full tenant list before we start moving events.
self.connection.sched.primed_event.wait()
if self._stopped:
return
self.event_queue.registerEventWatch(self._onNewEvent)
# Set the wake event so we get an initial run
self._dispatcher_wake_event.set()

View File

@ -91,6 +91,11 @@ class GitlabEventConnector(threading.Thread):
return not self._stopped
def run(self):
# Wait for the scheduler to prime its config so that we have
# the full tenant list before we start moving events.
self.connection.sched.primed_event.wait()
if self._stopped:
return
self.event_queue.registerEventWatch(self._onNewEvent)
while not self._stopped:
try:

View File

@ -156,6 +156,11 @@ class PagureEventConnector(threading.Thread):
return not self._stopped
def run(self):
# Wait for the scheduler to prime its config so that we have
# the full tenant list before we start moving events.
self.connection.sched.primed_event.wait()
if self._stopped:
return
self.event_queue.registerEventWatch(self._onNewEvent)
while not self._stopped:
try:

View File

@ -150,6 +150,7 @@ class Scheduler(threading.Thread):
threading.Thread.__init__(self)
self.daemon = True
self.hostname = socket.getfqdn()
self.primed_event = threading.Event()
self.wake_event = threading.Event()
self.layout_lock = threading.Lock()
self.run_handler_lock = threading.Lock()
@ -282,7 +283,7 @@ class Scheduler(threading.Thread):
target=self.startCleanup, name='cleanup start')
self.start_cleanup_thread.daemon = True
self.start_cleanup_thread.start()
self.component_info.state = self.component_info.RUNNING
self.component_info.state = self.component_info.INITIALIZING
def stop(self):
self.log.debug("Stopping scheduler")
@ -301,6 +302,8 @@ class Scheduler(threading.Thread):
self.log.debug("Stopping nodepool")
self.nodepool.stop()
self.log.debug("Stopping connections")
# Connections may be waiting on the primed event
self.primed_event.set()
self.stopConnections()
self.log.debug("Stopping stats thread")
self.stats_election.cancel()
@ -844,7 +847,9 @@ class Scheduler(threading.Thread):
duration = round(time.monotonic() - start, 3)
self.log.info("Config priming complete (duration: %s seconds)",
duration)
self.primed_event.set()
self.wake_event.set()
self.component_info.state = self.component_info.RUNNING
def reconfigure(self, config, smart=False):
self.log.debug("Submitting reconfiguration event")

View File

@ -1792,6 +1792,7 @@ class ZuulWeb(object):
def start(self):
self.log.debug("ZuulWeb starting")
self.component_info.state = self.component_info.INITIALIZING
# Wait for system config and layouts to be loaded
while not self.system_config_cache.is_valid:
self.system_config_cache_wake_event.wait()

View File

@ -44,6 +44,7 @@ class BaseComponent(ZooKeeperBase):
"""
# Component states
INITIALIZING = "initializing"
RUNNING = "running"
PAUSED = "paused"
STOPPED = "stopped"