Regular scheduled jobs

Any component used by your application can have jobs that need to be run at regular intervals. Executing the following runs all jobs that are scheduled to run:

reahl runjobs etc

The tutorial.jobsbootstrap example needs its Address.clear_added_flags() to run automatically, once a day.

class Address(Base):
    __tablename__ = 'jobsbootstrap_address'

    id            = Column(Integer, primary_key=True)
    email_address = Column(UnicodeText)
    name          = Column(UnicodeText)
    added_today   = Column(Boolean, nullable=False, default=True)

    def clear_added_flags(cls):
        for address in Session.query(cls).filter_by(added_today=True):
            address.added_today = False

    def fields(self, fields): = Field(label='Name', required=True)
        fields.email_address = EmailField(label='Email', required=True)

    def events(self, events): = Event(label='Save', action=Action(

    def save(self):

To register this job with the component, add a <schedule> tag in the .reahlproject file:

  <schedule locator="reahl.doc.examples.tutorial.jobsbootstrap.jobsbootstrap:Address.clear_added_flags"/>

A job, such as Address.clear_added_flags() should include code that makes sure it only does its work when necessary. You can then use your operating system tools (such as cron) to run reahl runjobs etc very regularly – say once every 10 minutes. Each scheduled job will now be invoked regularly, and can check at each invocation whether it is time for it to do its work, or whether it should ignore the current run until a future time. This way, all jobs can get a chance to be run, and be in control of when they should run.