Commit 060f71d4 authored by André Anjos's avatar André Anjos 💬

[backend] Fix result to job/split relationship

parent c71f3a2c
......@@ -143,7 +143,7 @@ class Migration(migrations.Migration):
('split_errors', models.PositiveIntegerField(default=0)),
('block', models.OneToOneField(related_name='job', on_delete=models.deletion.CASCADE, to='experiments.Block', null=True)),
('parent', models.OneToOneField(related_name='child', to='backend.Job', null=True, on_delete=models.deletion.SET_NULL)),
('result', models.ForeignKey(to='backend.Result', null=True)),
('result', models.OneToOneField(to='backend.Result', null=True, on_delete=models.deletion.CASCADE, related_name='job')),
],
),
migrations.CreateModel(
......@@ -159,7 +159,7 @@ class Migration(migrations.Migration):
('process_id', models.PositiveIntegerField(null=True)),
('job', models.ForeignKey(related_name='splits', to='backend.Job', null=True)),
('worker', models.ForeignKey(related_name='splits', on_delete=models.deletion.SET_NULL, to='backend.Worker', null=True)),
('result', models.ForeignKey(to='backend.Result', related_name='splits', null=True)),
('result', models.OneToOneField(to='backend.Result', related_name='split', null=True, on_delete=models.deletion.CASCADE)),
],
),
migrations.AlterUniqueTogether(
......
......@@ -476,7 +476,8 @@ class Job(models.Model):
status = models.CharField(max_length=1, choices=STATUS, default=QUEUED)
result = models.ForeignKey(Result, null=True, on_delete=models.CASCADE)
result = models.OneToOneField(Result, null=True, on_delete=models.CASCADE,
related_name='job')
runnable_date = models.DateTimeField(null=True, blank=True)
......@@ -658,17 +659,12 @@ class Job(models.Model):
self.child.parent = parent
else: #child is the new parent
self.child.parent = None
else:
self.child.copy(job)
self.child._cascade_updates()
self.child.copy(self)
if self.parent and self.status == Job.CANCELLED:
self.parent = None
# update state of parent block/experiment
self.block._update_state()
@transaction.atomic
def _update_state(self):
......@@ -710,8 +706,9 @@ class Job(models.Model):
self.status = Job.QUEUED
# if required, erase dangling files, update own results
timings = None
if self.done():
timings = None
# compute final timings and update parent block
if self.status != Job.SKIPPED:
diff_timings = self._merge_results()
self.end_date = self.splits.order_by('-end_date').\
......@@ -728,11 +725,9 @@ class Job(models.Model):
self.runnable_date = None
self.erase_dangling_files()
# compute final timings and update parent block
self.save()
# updates the dependents and child state
self.save()
self.block._update_state(timings)
self._cascade_updates()
......@@ -827,8 +822,8 @@ class JobSplit(models.Model):
status = models.CharField(max_length=1, choices=Job.STATUS,
default=Job.QUEUED)
result = models.ForeignKey(Result, null=True, on_delete=models.CASCADE,
related_name='splits')
result = models.OneToOneField(Result, null=True, on_delete=models.CASCADE,
related_name='split')
start_date = models.DateTimeField(null=True)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment