diff --git a/SAS/TMSS/src/tmss/tmssapp/migrations/0001_initial.py b/SAS/TMSS/src/tmss/tmssapp/migrations/0001_initial.py index 7d9bb828cc5803b2e078176143297a7f5bbb7ade..4513ec30e2675dd3473534b824eb7cd2d12aea6f 100644 --- a/SAS/TMSS/src/tmss/tmssapp/migrations/0001_initial.py +++ b/SAS/TMSS/src/tmss/tmssapp/migrations/0001_initial.py @@ -639,7 +639,7 @@ class Migration(migrations.Migration): ('tags', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=128), blank=True, default=list, help_text='User-defined search keywords for object.', size=8)), ('created_at', models.DateTimeField(auto_now_add=True, help_text='Moment of object creation.')), ('updated_at', models.DateTimeField(auto_now=True, help_text='Moment of last object update.')), - ('time_offset', models.FloatField(help_text='Time Offset between first and second Task Blueprint')), + ('time_offset', models.IntegerField(default=60, help_text='Time offset of start of second task with respect to start of first task.')), ], options={ 'abstract': False, @@ -652,7 +652,7 @@ class Migration(migrations.Migration): ('tags', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=128), blank=True, default=list, help_text='User-defined search keywords for object.', size=8)), ('created_at', models.DateTimeField(auto_now_add=True, help_text='Moment of object creation.')), ('updated_at', models.DateTimeField(auto_now=True, help_text='Moment of last object update.')), - ('time_offset', models.FloatField(help_text='Time Offset between first and second Task Draft')), + ('time_offset', models.IntegerField(default=60, help_text='Time offset of start of second task with respect to start of first task.')), ], options={ 'abstract': False, diff --git a/SAS/TMSS/src/tmss/tmssapp/tasks.py b/SAS/TMSS/src/tmss/tmssapp/tasks.py index 432a1e1d7ec4168500f4632065fd117edbe9e1b5..2531e4dc3d623cdcc008ee1c5e6c2568b7e2b79b 100644 --- a/SAS/TMSS/src/tmss/tmssapp/tasks.py +++ b/SAS/TMSS/src/tmss/tmssapp/tasks.py @@ -150,6 +150,28 @@ def create_task_blueprint_from_task_draft(task_draft: models.TaskDraft) -> model dataformat=task_relation_draft.dataformat) logger.info("Task Blueprint (id=%s) connected to Task Blueprint (id=%s) via Task Relation Blueprint (id=%s)", task_blueprint.pk, producing_task_blueprint.pk, task_relation_blueprint.pk) + + # Do the sam 'trick' for Task Scheduling Relation Draft to Blueprint + task_draft_scheduling_relations = list(task_draft.first_to_connect.all()) + list(task_draft.second_to_connect.all()) + for task_scheduling_relation_draft in task_draft_scheduling_relations: + for first_task_blueprint in task_scheduling_relation_draft.first.task_blueprints.all(): + for second_task_blueprint in task_scheduling_relation_draft.second.task_blueprints.all(): + try: + # do nothing if task_scheduling_relation_blueprint already exists... + models.TaskSchedulingRelationBlueprint.objects.get(first_id=first_task_blueprint.id, + second_id=second_task_blueprint.id) + except models.TaskSchedulingRelationBlueprint.DoesNotExist: + # ...'else' create it. + task_scheduling_relation_blueprint = models.TaskSchedulingRelationBlueprint.objects.create( + first=first_task_blueprint, + second=second_task_blueprint, + time_offset=task_scheduling_relation_draft.time_offset, + placement=task_scheduling_relation_draft.placement) + logger.info("Task Blueprint (id=%s) connected via scheduling relation with id=%s", + task_blueprint.pk, task_scheduling_relation_blueprint.pk) + logger.info("The scheduling relation is: '%s' (id=%s) '%s' '%s' (id=%s)", + first_task_blueprint.name, first_task_blueprint.pk, task_scheduling_relation_blueprint.placement, + second_task_blueprint.name, second_task_blueprint.pk) return task_blueprint @@ -180,6 +202,7 @@ def create_task_blueprint_and_subtasks_and_schedule_subtasks_from_task_draft(tas task_blueprint.refresh_from_db() return task_blueprint + def create_task_blueprints_from_scheduling_unit_blueprint(scheduling_unit_blueprint: models.SchedulingUnitBlueprint) -> models.SchedulingUnitBlueprint: '''Convenience method: Create the scheduling_unit_blueprint's task_blueprint(s)''' task_drafts = list(scheduling_unit_blueprint.draft.task_drafts.all()) @@ -196,6 +219,7 @@ def create_task_blueprints_from_scheduling_unit_blueprint(scheduling_unit_bluepr scheduling_unit_blueprint.refresh_from_db() return scheduling_unit_blueprint + def create_task_blueprints_and_subtasks_from_scheduling_unit_blueprint(scheduling_unit_blueprint: models.SchedulingUnitBlueprint) -> models.SchedulingUnitBlueprint: '''Convenience method: Create the scheduling_unit_blueprint's task_blueprint(s), then create each task_blueprint's subtasks''' scheduling_unit_blueprint = create_task_blueprints_from_scheduling_unit_blueprint(scheduling_unit_blueprint) @@ -213,6 +237,7 @@ def create_task_blueprints_and_subtasks_from_scheduling_unit_blueprint(schedulin scheduling_unit_blueprint.refresh_from_db() return scheduling_unit_blueprint + def create_task_blueprints_and_subtasks_and_schedule_subtasks_from_scheduling_unit_blueprint(scheduling_unit_blueprint: models.SchedulingUnitBlueprint) -> models.SchedulingUnitBlueprint: '''Convenience method: Create the scheduling_unit_blueprint's task_blueprint(s), then create the task_blueprint's subtasks, and schedule the ones that are not dependend on predecessors''' scheduling_unit_blueprint = create_task_blueprints_and_subtasks_from_scheduling_unit_blueprint(scheduling_unit_blueprint) diff --git a/SAS/TMSS/test/tmss_test_data_rest.py b/SAS/TMSS/test/tmss_test_data_rest.py index 865e74c738db8703dc70ea105a9ff1ea1dc448b3..c795670843671cd59cddf00f4a18ead0b7ee419e 100644 --- a/SAS/TMSS/test/tmss_test_data_rest.py +++ b/SAS/TMSS/test/tmss_test_data_rest.py @@ -226,8 +226,8 @@ class TMSSRESTTestDataCreator(): 'task_blueprints': [], 'produced_by': [], 'consumed_by': [], - 'scheduling_relation_first': [], - 'scheduling_relation_second': []} + 'first_to_connect': [], + 'second_to_connect': []} def TaskRelationDraft(self, producer_url=None, consumer_url=None, template_url=None, input_role_url=None, output_role_url=None): @@ -294,8 +294,8 @@ class TMSSRESTTestDataCreator(): "subtasks": [], "produced_by": [], "consumed_by": [], - 'scheduling_relation_first': [], - 'scheduling_relation_second': []} + 'first_to_connect': [], + 'second_to_connect': []} def TaskRelationBlueprint(self, draft_url=None, template_url=None, input_role_url=None, output_role_url=None, consumer_url=None, producer_url=None): if draft_url is None: