Skip to content
Snippets Groups Projects
Commit 6701589b authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[backend] Make process launch an DB atomic transaction

parent ae9c3cef
No related branches found
No related tags found
1 merge request!194Scheduler
Pipeline #
...@@ -424,29 +424,31 @@ class Worker(models.Model): ...@@ -424,29 +424,31 @@ class Worker(models.Model):
if settings.DEBUG: cmdline += ['-vv'] if settings.DEBUG: cmdline += ['-vv']
# start newly assigned job splits # start newly assigned job splits
for split in JobSplit.objects.select_for_update().filter(worker=self, with transaction.atomic():
status=Job.QUEUED, start_date__isnull=True, splits = JobSplit.objects.select_for_update().filter(worker=self,
process_id__isnull=True): status=Job.QUEUED, start_date__isnull=True,
execute = pick_execute(split, environments) process_id__isnull=True)
if execute is None: for split in splits:
message = "Environment `%s' is not available for split " \ execute = pick_execute(split, environments)
"%d/%d running at worker `%s', for block `%s' of " \ if execute is None:
"experiment `%s': %s" % \ message = "Environment `%s' is not available for split " \
(split.job.block.environment, "%d/%d running at worker `%s', for block `%s' of " \
split.split_index+1, "experiment `%s': %s" % \
split.job.block.required_slots, (split.job.block.environment,
self, split.split_index+1,
split.job.block.name, split.job.block.required_slots,
split.job.block.experiment.fullname(), self,
"Available environments are `%s'" % \ split.job.block.name,
'|'.join(environments.keys()), split.job.block.experiment.fullname(),
) "Available environments are `%s'" % \
split.end(Result(status=1, usrerr=settings.DEFAULT_USER_ERROR, '|'.join(environments.keys()),
syserr=message)) )
continue split.end(Result(status=1,
usrerr=settings.DEFAULT_USER_ERROR, syserr=message))
# if we get to this point, then we launch the user process continue
subprocess.Popen(cmdline + [execute, str(split.pk)])
# if we get to this point, then we launch the user process
subprocess.Popen(cmdline + [execute, str(split.pk)])
# cleans-up zombie processes that may linger # cleans-up zombie processes that may linger
_cleanup_zombies() _cleanup_zombies()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment