Run Modes & Scheduling
After you publish a model, the platform needs to know when to run it. pd4castr supports two run modes that control how and when model runs are triggered: automatic runs based on incoming data, and on-demand runs triggered manually.
Run Modes
Set the runMode field in .pd4castrrc.json to one of these values:
Automatic
The model runs automatically when new input data arrives. The platform monitors your storage locations and triggers a run when all required inputs have fresh data. This is the default mode for production models that need to update on a regular cadence.
{
"runMode": "AUTOMATIC"
}On-Demand
The model runs only when explicitly triggered by a user via the pd4castr UI’s “Run model” button or the API trigger endpoint. Only one run can be in progress at a time. This is a good fit for models you want fine-tuned control over.
{
"runMode": "ON_DEMAND"
}How Automatic Triggering Works
For models with AUTOMATIC run mode, the platform tracks a trigger progress
state that determines when a new run starts.
The trigger logic works as follows:
- When a new file arrives in a storage location, whether the CLI uploaded it for a static input or a data fetcher wrote it for a fetched input, the input’s latest file reference is updated.
- The platform checks the model’s trigger progress.
- All inputs with
WAIT_FOR_LATEST_FILEtrigger type must have received new data since the last run. - Inputs with
USE_MOST_RECENT_FILEtrigger type use whatever file was last available — they don’t block a run from starting. - When all conditions are met, a run is triggered. On a model with an input that has several input sources, each input source tracks its own progress and starts its own runs, as Input sources describes.
- One base run plus one run per enabled sensitivity are created.
Custom Run Datetime
By default, the run datetime is set to the moment the run is created. If your
model needs a specific run datetime to align with the context of the input data
(for example, the trading interval the forecast covers), you can define a custom
runDatetimeQuery in .pd4castrrc.json.
{
"runDatetimeQuery": "queries/run-datetime.sql"
}This SQL file is executed against the input data and must return at least one
row with a run_datetime column; the platform reads the first row and ignores
the rest. For example:
SELECT MAX(forecast_datetime) AS run_datetime
FROM input_dataWhere the data in the table named input_data in this case would correspond to
an input with the key of input_data.
Set runDatetimeQuery to null or omit it to use the default behaviour. See
SQL queries for the SQL dialect and how the query
refers to an input.
If your model declares axes, keep this query away from partitioned inputs, as Custom run datetime queries explains.
Data Fetcher Scheduling
For fetched inputs, the platform polls the data provider every checkInterval
seconds (minimum 5). pd4castr starts a check within a second of the interval
ending, so a 5-second interval runs the check query 12 times a minute against
the provider’s database.
The scheduling cycle works like this:
- The check query runs against the data provider’s data on each interval.
- If the results differ from the last check, the fetch query runs.
- The fetched data is written to the configured storage location as a new input file.
- This new file landing in the storage location can trigger automatic model
runs (if the model uses
AUTOMATICrun mode and all trigger conditions are met).
Together, these steps run a fetched-input model with no manual steps: pd4castr polls the data provider, stores each new batch, and starts the model’s runs.
Next Steps
- See Model inputs for details on trigger types and fetcher configuration.
- Review Publishing to learn how run mode is set during the publish process.