PageRenderTime 120ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/_unsorted/job.py

https://bitbucket.org/ericsnowcurrently/commonlib
Python | 85 lines | 33 code | 30 blank | 22 comment | 1 complexity | 305601624041c6c6eb6937adcf8aa551 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from collections import namedtuple
  2. # jobs
  3. class JobDefinition(namedtuple('Base', 'id')):
  4. """Something that can get done."""
  5. class JobRequest(namedtuple('Base', 'id master definition args jobs')):
  6. """The application of a JobDefinition."""
  7. class Job(namedtuple('Base', 'id record slave')):
  8. """The application of a JobRequest."""
  9. class JobRecord(namedtuple('Base', 'id job')):
  10. """The state of a job that persists after the job is gone.
  11. The id will be the same id that the job has.
  12. """
  13. # job slaves
  14. class Slave(namedtuple('Slave', 'name master')):
  15. """The one that does the job."""
  16. def __init__(self, name, master):
  17. super(type(self), self).__init__(name, master)
  18. self.subordinates = self._get_subordinate_slaves()
  19. @property
  20. def host(self):
  21. """The host on which this slave lives."""
  22. return self.master._get_slave_host(self)
  23. class SlaveProxy(Slave):
  24. # like a taskmaster in Nucleon
  25. # useful to wrap unstable slaves (like leptons)
  26. # XXX what is proxied?
  27. # job masters
  28. class Master(object):
  29. """The one that manages getting the job done."""
  30. def __init__(self, name, host):
  31. self.name = name
  32. self.host = host
  33. self.slaves = self._get_slaves()
  34. self.jobs = self._get_jobs()
  35. self.job_definitions = self._get_job_definitions()
  36. self.job_requests = self._get_job_requests()
  37. self.job_records = self._get_job_records()
  38. self.jobs = jobs or master._get_jobs_from_request(jobrequest)
  39. def _get_slaves(self):
  40. # Return the mapping of slaves, by name
  41. raise NotImplementedError
  42. def _get_jobs(self):
  43. # Return the mapping of existing jobs, by id
  44. raise NotImplementedError
  45. def _get_job_definitions(self):
  46. # return the mapping of job definitions, by id
  47. raise NotImplementedError
  48. def _get_job_requests(self):
  49. # Return the mapping of job requests, by id
  50. raise NotImplementedError
  51. def _get_job_records(self):
  52. # Return the mapping of job records, by id
  53. raise NotImplementedError