Deployment with Zend Server (Part 5 of 8)

This is the fifth in a series of eight posts detailing tips on deploying to Zend Server. The previous post in the series detailed how to secure your Job Queue job scripts.

Today, I'm sharing some best practices around writing job scripts, particularly around how to indicate execution status.

Tip 5: Set your job status

You should always set your job script status, and exit with an appropriate return status. This ensures that Job Queue knows for sure if the job completed successfully, which can help you better identify failed jobs in the UI. I use the following:

// for failure:
ZendJobQueue::setCurrentJobStatus(ZendJobQueue::FAILED);
exit(1);

// for success:
ZendJobQueue::setCurrentJobStatus(ZendJobQueue::OK);
exit(0);

I also have started returning relevant messages. Since Job Queue aggregates these in the UI panel, that allows you to examine the output, which often helps in debugging.

exec($command, $output, $return);
header('Content-Type: text/plain');
if ($return != 0) {
    ZendJobQueue::setCurrentJobStatus(ZendJobQueue::FAILED);
    echo implode("
", $output);
    exit(1);
}

ZendJobQueue::setCurrentJobStatus(ZendJobQueue::OK);
echo implode("
", $output);
exit(0);

Here's sample output:

(The [0;34m]-style codes are colorization codes; terminals capable of color would display the output in color, but Zend Server, of course, is seeing plain text.)

In sum: return appropriate job status via the ZendJobQueue::setCurrentJobStatus() static method and the exit() code, and send output to help diagnose issues later.

Next timeā€¦

The next tip in the series discusses setting up page caching in Zend Server, as well as creating jobs to clear page caches.

Other articles in the series