/_unsorted/job.py
Python | 85 lines | 33 code | 30 blank | 22 comment | 1 complexity | 305601624041c6c6eb6937adcf8aa551 MD5 | raw file
Possible License(s): BSD-3-Clause
- from collections import namedtuple
- # jobs
- class JobDefinition(namedtuple('Base', 'id')):
- """Something that can get done."""
- class JobRequest(namedtuple('Base', 'id master definition args jobs')):
- """The application of a JobDefinition."""
- class Job(namedtuple('Base', 'id record slave')):
- """The application of a JobRequest."""
- class JobRecord(namedtuple('Base', 'id job')):
- """The state of a job that persists after the job is gone.
- The id will be the same id that the job has.
- """
- # job slaves
- class Slave(namedtuple('Slave', 'name master')):
- """The one that does the job."""
- def __init__(self, name, master):
- super(type(self), self).__init__(name, master)
- self.subordinates = self._get_subordinate_slaves()
- @property
- def host(self):
- """The host on which this slave lives."""
- return self.master._get_slave_host(self)
- class SlaveProxy(Slave):
- # like a taskmaster in Nucleon
- # useful to wrap unstable slaves (like leptons)
- # XXX what is proxied?
- # job masters
- class Master(object):
- """The one that manages getting the job done."""
- def __init__(self, name, host):
- self.name = name
- self.host = host
- self.slaves = self._get_slaves()
- self.jobs = self._get_jobs()
- self.job_definitions = self._get_job_definitions()
- self.job_requests = self._get_job_requests()
- self.job_records = self._get_job_records()
- self.jobs = jobs or master._get_jobs_from_request(jobrequest)
- def _get_slaves(self):
- # Return the mapping of slaves, by name
- raise NotImplementedError
- def _get_jobs(self):
- # Return the mapping of existing jobs, by id
- raise NotImplementedError
- def _get_job_definitions(self):
- # return the mapping of job definitions, by id
- raise NotImplementedError
- def _get_job_requests(self):
- # Return the mapping of job requests, by id
- raise NotImplementedError
- def _get_job_records(self):
- # Return the mapping of job records, by id
- raise NotImplementedError