-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Ability to dynamically build job/template description #137
Comments
Hey Jimmy. Sorry for the delay, I thought that I had already responded but I see now that I had not. You're spot on that this would be a very useful feature. The challenge that I imagine that you're hitting is that the model classes' constructor always runs the validation logic, and things like a JobTemplate with no Steps is not a valid job template. It's not pretty, but as a workaround for now you could leverage the fact that all of the model implementations are Pydantic models. It is possible to construct models without validation (see: https://docs.pydantic.dev/1.10/usage/models/#creating-models-without-validation). That should allow for creating instances of the model classes that don't pass validation, and then you could, say, I'd suggest still running the final model through the validation logic ( If you have the time, and inclination then we do accept pull requests. ;-) |
Ok, that makes sense. So if I would be adding functions for eg. adding Steps, is there a desired naming structure for the functions? Edit:
Would there be a way to have multiple "levels" of validations? Eg. one for constructing and another level for when exporting/sending it? (Not (yet) familar with Pydantic) |
Just follow the patterns of other methods. The main things to know are in the DEVELOPMENT.md:
Not in a way that doesn't involve duplicating the data model in its entirety that I can immediately see. Pydantic works by introspecting the model definitions and creating the validation logic from the annotations on the member declarations. It doesn't have a way to say "conditionally do this validation" that I'm aware of. The trick is that there are two use-cases for these models:
The implementation is heavily biased to (1) right now, and that makes case (2) challenging. |
This is what I was afraid of, that to eg. implement OJD in eg. OpenCue with it's more dynamic nature, one would first have to use the native outline format and then convert everything into OJD in a single step. |
Hmm.. just checked my test script and it's indeed possible to create a job without any steps.. Edit: #!/usr/bin/python3
from openjd.model import model_to_object, JobParameterDefinition, decode_job_template
from openjd.model.v2023_09 import *
import yaml
command = CommandString('echo test 12434')
action = Action(command=command)
layer1 = Step(
name="layer1",
script=StepScript(
actions=StepActions(
onRun=action
)
),
parameterSpace=StepParameterSpace(
taskParameterDefinitions={
"tags": RangeListTaskParameterDefinition(
type=TaskParameterType.STRING,
range=["blender"]
),
"services": RangeListTaskParameterDefinition(
type=TaskParameterType.STRING,
range=["blender"]
),
"frames": RangeListTaskParameterDefinition(
type=TaskParameterType.INT,
range=["1-1"]
),
"outputs": RangeListTaskParameterDefinition(
type=TaskParameterType.STRING,
range=["/tmp/blender/blender.#####.exr"]
)
},
combination="(tags, services, frames)"
)
)
job = Job(
name='testJob',
steps=[layer1],
parameters={"show": JobParameter(value="testing", type=JobParameterType.STRING),
"shot": JobParameter(value="sh0010", type=JobParameterType.STRING),
"user": JobParameter(value="jimmy", type=JobParameterType.STRING),
"email": JobParameter(value="jimmy@example.com", type=JobParameterType.STRING),
"uid": JobParameter(value="1000", type=JobParameterType.INT),
"facility": JobParameter(value="local", type=JobParameterType.STRING),
"paused": JobParameter(value="0", type=JobParameterType.INT),
"priority": JobParameter(value="1", type=JobParameterType.INT),
"maxretries": JobParameter(value="2", type=JobParameterType.INT),
"autoeat": JobParameter(value="0", type=JobParameterType.INT)
}
)
obj = model_to_object(model=job)
print(yaml.dump(obj)) |
Also, if I were to add eg. add_step(), would it require a new version of the model? |
Ah, that worked because you used the
Nope. That's an additive change that would be just fine. The model version is specific to the data model, not the functional model that we layer on top of that. If that makes sense... |
Personally I still feel that the Edit: |
Use Case
When writing the job/template description it currently requires you to know all information before creating the object. There is no way to add eg. new Steps to a job, so one have to create an internal model first and then convert it to OJD instead of natively building the job directly.
Proposed Solution
Add CRUD functions to the model.
The text was updated successfully, but these errors were encountered: