Detecting and troubleshooting custom job failures
Key Takeaway
A task-oriented job step script that returns an ERROR Status ends with exit status ERROR, and one that returns an OK Status ends with exit status OK. Catch failures with notifications and failure rules set up in advance, then trace them in job history and the logs.
A custom job in B2C Commerce runs your script code on a schedule or on demand from Business Manager, so it can fail when nobody is watching. Detecting failures means having your step script report its result, setting up notifications and failure rules ahead of time, and then checking job history and log files. Troubleshooting means finding the right log, releasing stuck locks, and rerunning the job or recovering the data.
How a job step reports success or failure
In a task-oriented script module or pipeline for a custom job step, you control the exit status by returning a dw.system.Status object. You create the Status with either Status.ERROR or Status.OK. You can also pass a more detailed status code and a default human-readable message.
var Status = dw.system.Status;
exports.execute = function () {
var feedFound = false; // sample value: the feed file is missing
if (!feedFound) {
return new Status(Status.ERROR, 'ERROR', 'Inventory feed not found');
}
return new Status(Status.OK, 'OK');
};
// feedFound is false => step exit status ERROR, job stops
// feedFound is true => step exit status OK, job continuesWhen the feed is missing, the function returns a Status created with Status.ERROR, so the step ends with exit status ERROR. The job then stops, unless a transition handles the step's result. When the feed is found, the function returns a Status created with Status.OK, so the step ends with exit status OK and the job continues.
You can't define the exit status for a chunk-oriented script module. A chunk-oriented module always finishes with either OK or ERROR.
Some job problems are written to the log but don't stop the job, so a job can look finished while errors pile up. If these errors are significant, add processing to the job to detect them and stop it, for example by returning an ERROR Status. Check the logs regularly as well.