1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-18 20:11:20 +00:00

framework: Have Job hold its own JobState

JobState, previously handled by RunState, is now held in the
Job.

Changes and accesses to a Job's status access the Job's
JobState directly, so that there is only one place now that each Job's
state data is tracked.

This also means there is no use for update_job in RunState.
This commit is contained in:
Jonathan Paynter 2020-07-01 10:36:52 +00:00 committed by Marc Bonnici
parent 8640f4f69a
commit 7c6ebfb49c
2 changed files with 14 additions and 12 deletions

View File

@ -23,6 +23,7 @@ from datetime import datetime
from wa.framework import pluginloader, signal, instrument from wa.framework import pluginloader, signal, instrument
from wa.framework.configuration.core import Status from wa.framework.configuration.core import Status
from wa.utils.log import indentcontext from wa.utils.log import indentcontext
from wa.framework.run import JobState
class Job(object): class Job(object):
@ -39,18 +40,27 @@ class Job(object):
@property @property
def status(self): def status(self):
return self._status return self.state.status
@property @property
def has_been_initialized(self): def has_been_initialized(self):
return self._has_been_initialized return self._has_been_initialized
@property
def retries(self):
return self.state.retries
@status.setter @status.setter
def status(self, value): def status(self, value):
self._status = value self.state.status = value
self.state.timestamp = datetime.utcnow()
if self.output: if self.output:
self.output.status = value self.output.status = value
@retries.setter
def retries(self, value):
self.state.retries = value
def __init__(self, spec, iteration, context): def __init__(self, spec, iteration, context):
self.logger = logging.getLogger('job') self.logger = logging.getLogger('job')
self.spec = spec self.spec = spec
@ -59,10 +69,9 @@ class Job(object):
self.workload = None self.workload = None
self.output = None self.output = None
self.run_time = None self.run_time = None
self.retries = 0
self.classifiers = copy(self.spec.classifiers) self.classifiers = copy(self.spec.classifiers)
self._has_been_initialized = False self._has_been_initialized = False
self._status = Status.NEW self.state = JobState(self.id, self.label, self.iteration, Status.NEW)
def load(self, target, loader=pluginloader): def load(self, target, loader=pluginloader):
self.logger.info('Loading job {}'.format(self)) self.logger.info('Loading job {}'.format(self))
@ -88,7 +97,6 @@ class Job(object):
self.workload.initialize(context) self.workload.initialize(context)
self.set_status(Status.PENDING) self.set_status(Status.PENDING)
self._has_been_initialized = True self._has_been_initialized = True
context.update_job_state(self)
def configure_augmentations(self, context, pm): def configure_augmentations(self, context, pm):
self.logger.info('Configuring augmentations') self.logger.info('Configuring augmentations')

View File

@ -102,13 +102,7 @@ class RunState(Podable):
self.timestamp = datetime.utcnow() self.timestamp = datetime.utcnow()
def add_job(self, job): def add_job(self, job):
job_state = JobState(job.id, job.label, job.iteration, job.status) self.jobs[(job.state.id, job.state.iteration)] = job.state
self.jobs[(job_state.id, job_state.iteration)] = job_state
def update_job(self, job):
state = self.jobs[(job.id, job.iteration)]
state.status = job.status
state.timestamp = datetime.utcnow()
def get_status_counts(self): def get_status_counts(self):
counter = Counter() counter = Counter()