Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ansys/rep/client/jms/resource/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Task(Object):
List of IDs of owned files of task.
license_context_id : str, optional
ID of license context in use
custom_data : dict, optional
Dictionary type field to store custom data.

"""

Expand Down Expand Up @@ -77,7 +79,8 @@ def __init__(self,
monitored_file_ids=missing,
inherited_file_ids=missing,
owned_file_ids=missing,
license_context_id=missing
license_context_id=missing,
custom_data=missing
):
self.id = id
self.modification_time = modification_time
Expand All @@ -100,6 +103,7 @@ def __init__(self,
self.inherited_file_ids = inherited_file_ids
self.owned_file_ids = owned_file_ids
self.license_context_id = license_context_id
self.custom_data = custom_data

self.obj_type = self.__class__.__name__

Expand Down
5 changes: 5 additions & 0 deletions ansys/rep/client/jms/schema/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,8 @@ class Meta(ObjectSchema.Meta):
allow_none=True,
metadata={"description": "ID of license context in use"},
)

custom_data = fields.Dict(
allow_none=True,
description="Dictionary type field to store custom data.",
)
50 changes: 50 additions & 0 deletions tests/jms/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def test_task_deserialization(self):
"02q3zEBtZ0oVfoCAEBDiP5",
"02q3zEBtXfh5XvEnWc9c0w",
],
"custom_data": {"key": "value"},
}

task = TaskSchema().load(task_dict)
Expand Down Expand Up @@ -92,6 +93,7 @@ def test_task_deserialization(self):
"02q3zEBtXfh5XvEnWc9c0w",
],
)
self.assertEqual(task.custom_data, {"key": "value"})

def test_task_integration(self):

Expand Down Expand Up @@ -281,6 +283,54 @@ def test_sync_task_definition_snapshot(self):

JmsApi(client).delete_project(project)

def test_register_external_job(self):
client = self.client()

jms_api = JmsApi(client)
proj_name = f"test_register_external_job"
proj = Project(name=proj_name, priority=1, active=True)
proj = jms_api.create_project(proj)
project_api = ProjectApi(client, proj.id)
log.info(f"Created project '{proj.name}', ID='{proj.id}'")

task_def = TaskDefinition(
name="Fluent Session",
software_requirements=[
Software(name="Ansys Fluent Server", version="2023 R2"),
],
execution_level=0,
store_output=False,
)

task_def = project_api.create_task_definitions([task_def])[0]

job_def = JobDefinition(name="JobDefinition", active=True)
job_def.task_definition_ids = [task_def.id]
job_def = project_api.create_job_definitions([job_def])[0]

job = Job(
name=f"Fluent Session",
eval_status="running",
job_definition_id=job_def.id,
)
job = project_api.create_jobs([job])[0]

# add custom data to the task
tasks = project_api.get_tasks(job_id=job.id)
self.assertEqual(len(tasks), 1)
task = tasks[0]
self.assertEqual(task.eval_status, "running")

task.custom_data = {"url": "http://localhost:5000", "some_other_data": "value"}
project_api.update_tasks([task])

tasks = project_api.get_tasks(job_id=job.id)
self.assertEqual(len(tasks), 1)
self.assertEqual(tasks[0].custom_data["url"], "http://localhost:5000")
self.assertEqual(tasks[0].eval_status, "running")

JmsApi(client).delete_project(proj)


if __name__ == "__main__":
unittest.main()