Notifications can be sent whenever a job enters a specific state. By default, the Scheduler sends out notifications when a job enters the Success or Failed state. It is however relatively easy to add notification hooks to the other states as well.
Adding notifications via the web front end can be done by entering email addresses and web urls in the Notify field:
To add notifications via the API with the codem executable, use the following:
$ codem -i /files/movie.flv -o /files/movie.mp4 -p h264 -n notifications@host.com,http://host.com/notifications
If an email notification is sent, the specified email address received a plain text email describing the changes that happened. The email includes a direct link to the job in the Scheduler API. If an url notification is sent, the corresponding url receives a JSON representation of the job. The JSON below is an example when a job entered the Success state.
{
"job": {
"callback_url":"http://localhost:3000/api/jobs/26",
"completed_at":"2011-05-10T08:45:03Z",
"created_at":"2011-05-10T08:25:00Z",
"destination_file":"/tmp/movie.mp4",
"duration":10577,
"filesize":4873221,
"host_id":1,
"id":26,
"message":null,
"preset_id":1,
"progress":1,
"remote_job_id":"fa832776a64b6844fb9f1a244757734a9d83c00f",
"source_file":"/tmp/movie.flv",
"state":"success",
"transcoding_started_at":"2011-05-10T08:25:03Z",
"updated_at":"2011-05-10T08:25:03Z"
}
}
Adding notifications to other states is very easy. Open app/models/jobs/states.rb in a text editor, and add notify to the state you want to be notified of.
In the screenshot below, sending notifications have been added to the OnHold state.
To add a custom notification to the scheduler, subclass Notification and implement the do_notify! method.
This method will receive a hash of options, namely: { :job => Job object, :state => 'state name' }.
For instance, to create a notifier that sends information to Twitter using the twitter gem:
To actually expose the custom notifier into the Scheduler, add it to the from_api method of Notifier.
This implementation is left as an exercise to the reader.