Add cloning to jobs
@@ -4,6 +4,7 @@ from django.db import models
from django.utils.functional import cached_property
from db.models.abstract_jobs import AbstractJob, AbstractJobStatus, JobMixin
+from db.models.cloning_strategies import CloningStrategy
from db.models.utils import DescribableModel
from libs.spec_validation import validate_job_spec_config
from polyaxon_schemas.polyaxonfile.specification import JobSpecification
@@ -34,6 +35,19 @@ class Job(AbstractJob, DescribableModel, JobMixin):
blank=True,
null=True,
related_name='+')
+ original_job = models.ForeignKey(
+ 'self',
+ on_delete=models.SET_NULL,
+ null=True,
+ blank=True,
+ related_name='clones',
+ help_text='The original job that was cloned from.')
+ cloning_strategy = models.CharField(
+ max_length=16,
+ blank=True,
+ null=True,
+ default=CloningStrategy.RESTART,
+ choices=CloningStrategy.CHOICES)
status = models.OneToOneField(
'db.JobStatus',
related_name='+',
@@ -65,6 +79,26 @@ class Job(AbstractJob, DescribableModel, JobMixin):
def specification(self):
return JobSpecification(values=self.config)
+ @property
+ def is_clone(self):
+ return self.original_job is not None
+
+ @property
+ def original_unique_name(self):
+ return self.original_job.unique_name if self.original_job else None
+
+ @property
+ def is_restart(self):
+ return self.is_clone and self.cloning_strategy == CloningStrategy.RESTART
+
+ @property
+ def is_resume(self):
+ return self.is_clone and self.cloning_strategy == CloningStrategy.RESUME
+
+ @property
+ def is_copy(self):
+ return self.is_clone and self.cloning_strategy == CloningStrategy.COPY
+
def set_status(self, status, message=None, details=None): # pylint:disable=arguments-differ
return self._set_status(status_model=JobStatus,
status=status,
