You can execute an Engine from within the model calculation logic. The binding variable model
provides access to the ModelFormulaCalculationContext API which allows you to call the engine – i.e. start a Job Trigger Calculation.
Enabling a Job Trigger Calculation Image
In order to run a given engine/image on your partition, you must make a request to Pricefx Support to enable the specific image you want to use, along with the number of CPUs and available RAM you require ( decent starting values are described in engines reference pages).
Running a Job Trigger Calculation
Each image/engine accepts dedicated parameters which you supply in the method call startJobTriggerCalculation.
A model Step executing the calculation, that starts a new Job Trigger Calculation, will be considered as finished only when calculations, formula and Job Trigger are all finished. In terms of execution order, this follows the same rules as sequence calculations.
Example
Model class definition:
{ "uniqueName": "Job_Trigger_Calc_Sample", "definition": { "calculations": [ { "name": "run-jtc", "type": "formula", "formulaName": "Job_Trigger_Calc" } ], "steps": [ { "name": "step1", "label": "Step 1", "calculation": "run-jtc" } ] } }
Model calculation logic Job_Trigger_Calc (of Nature model_calculation
):
model.startJobTriggerCalculation( "cregistry.pricefx.eu/engineering/pricefx-optimization-engine", // name of the engine image "latest", // tag of the engine image api.jsonEncode([ // parameters required by the engine image ]), "oe" // a name for the job, unique for this calculation and step )
Calculation Process Sequence
In a Model Object, when the user calculates the first step, this is what happens:
A new calculation and its corresponding Job Status Tracker is created with the calculation context
step1 / run-jtc
.The step is considered as started from the Model Object’s point of view.
The model calculation logic runs in the Pricefx cluster as usual.
At the end, a new calculation and its corresponding Job Status Tracker is created with the calculation context
step1 / run-jtc:oe
.Note, that if multiple Job Trigger Calculations are started in the same model calculation logic, they will be executed concurrently.
The calculation description is sent to the Job Trigger Service, that:
Verifies the Pricefx partition has the authorization to run this image.
Knows how much resources must be allocated for the execution.
Executes the Docker image with the provided parameters.
The image can communicate with the Pricefx cluster with the same level of security clearance as the user who started the calculation.
Monitors the job and report its progress to the Job Status Tracker.
At the end sends back the terminal status logs to the Pricefx cluster logs.
The step is considered as finished from the Model Object’s point of view.