Skip to content
Snippets Groups Projects
Commit f286948d authored by Daniel Lyons's avatar Daniel Lyons
Browse files

Add a function to the template rendering for creating a Condor job name from an arbitrary string

parent 512f1c4c
No related branches found
Tags end-of-sprint/5
1 merge request!1081Add a function to the template rendering for creating a Condor job name from an arbitrary string
Pipeline #6845 passed
......@@ -37,7 +37,12 @@ from messaging.messenger import SenderIF
from mock_alchemy.mocking import UnifiedAlchemyMagicMock
from workspaces.capability.services.capability_service import Router
from workspaces.workflow.schema import Workflow, WorkflowRequest, WorkflowRequestFile
from workspaces.workflow.schema import (
Workflow,
WorkflowRequest,
WorkflowRequestFile,
WorkflowTemplate,
)
from workspaces.workflow.services.interfaces import WorkflowInfoIF
from workspaces.workflow.services.workflow_info import WorkflowInfo
from workspaces.workflow.services.workflow_service import WorkflowService
......@@ -414,3 +419,11 @@ class TestWorkflowService:
def test_get_dagfile_log(self, mock_workflow_service: WorkflowService):
log_path = mock_workflow_service._get_dag_logfile_name(pathlib.Path("fake.dag"))
assert log_path.name == "fake.dag.dagman.log"
def test_condor_name_utility():
t = WorkflowTemplate()
t.filename = "foo.dag"
t.content = b"{{#make_condor_jobname}}T10t10/J2030+2093.23{{/make_condor_jobname}}"
file = t.render({})
assert file.content == b"T10t10/J2030-2093-23"
......@@ -17,7 +17,7 @@
# along with Workspaces. If not, see <https://www.gnu.org/licenses/>.
import datetime
import logging
from typing import Dict, List
from typing import Callable, Dict, List
import chevron
import pendulum
......@@ -118,6 +118,11 @@ class WorkflowTemplate(JSONSerializable):
:param argument: argument(s) needed for template render
:return: an AbstractFile rendered from mustache template
"""
# add some rendering helpers to the argument
render_helpers = {"make_condor_jobname": self.make_condor_jobname}
argument = {**render_helpers, **argument}
# render
contents = chevron.render(self.content.decode("ascii"), argument)
logger.debug(
"rendering %s with argument %s to %s",
......@@ -147,6 +152,12 @@ class WorkflowTemplate(JSONSerializable):
def from_json(cls, json: dict) -> any:
return WorkflowTemplate(json["filename"], json["content"])
@staticmethod
def make_condor_jobname(content: str, renderer: Callable[[str], str]):
# get the rendered content
rendered = renderer(content)
return rendered.replace(".", "-").replace("+", "-")
def __repr__(self):
return f"<WorkflowTemplate filename={self.filename} for workflow={self.workflow_name}>"
......
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