Background Jobs
Talia uses the Backgroundjob (bj) library with some additional perks. For JRuby you must use our own version of the library, available from Github. In general, it's best to use the background classes provided by Talia instead of interacting directly with bj.
Creating Jobs
Creating a job that will report it's progress during runtime:
# Example job
TaliaCore::BackgroundJobs::Job.submit_with_progress('hyper_import_xml_old', :tag => 'import')
The first parameter identifies the script that should be queued. The background script is expected to reside in jobs/<scriptname> and will be called using script/runer. The current environment will be passed. To see how the options work, see the bj documentation.
In case a :tag is given to a Talia background job, it will not allow another job with the same tag to be created until the first is finished. This can be used to avoid queuing multiple "colliding" operations, such as import.
Creating a Job script
The script itself will look something like this:
# Initialize your script. (The Talia system will already be initialized at this point). script_init_things # Run your things, giving a progress TaliaCore::BackgroundJobs::Job.run_with_progress('Importing', size_of_things) do |progress| things.each do |thing| handle thing progress.inc end end # Finished progress.finished
This will run all the operations in the script, and report the progress in each script loop. Note that you need to give the overall count of operations at the beginning. You may have several run_with_progress blocks; in this case each will start from 0 again.
Also see the bj documentation on how to pass information to the scripts.
Monitoring Background Jobs
Background jobs can be monitored through the backend admin interface. Running jobs should produce a self-updating progress bar, and you should be able to see the job information, standard output, environment and such things for each job.
