JBoss.orgCommunity Documentation

Chapter 9. Scheduled Jobs

9.1. What Are Scheduled Jobs?
9.2. Ruby Job Classes
9.3. Scheduling Jobs
9.3.1. YAML Configuration Format
9.4. Resource Injection with Jobs

Scheduled jobs are simply components that execute on a possibly-recurring schedule instead of in response to user interaction. Scheduled jobs fire asynchronously, outside of the normal web-browser thread-of-control. Scheduled jobs have full access to the entire Ruby environment. This allows them to interact with database models and other application functionality.

Each scheduled job maps to exactly one Ruby class. The path and filename should match the class name of the job contained in the file.

File nameClass name
mail_notifier.rbMailNotifier
mail/notifier.rbMail::Notifier


Each job class should implement a no-argument run() method to perform the work when fired.


From within the class's run() method, the full application environment is available.

The job schedule defines the time(s) that a job should execute. This may be defined to be single point in time, or more often, as recurring event. The job schedule is defined with a jobs section of your torquebox.yml.

If a job requires access to other resources, such as messaging topics and queues, or Java CDI components these should be injected using the resource injection facilities provided by TorqueBox (see Chapter 11, Resource Injection).

In order for resource injection to function with scheduled jobs, they must reside either at the root of your application directory (typical for simple Rack applications), or underneath an app/jobs/ directory. If you place the job anywhere else, it may still funciton, but resources injection will not be available.