You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
easy-rules/site/user-guide/scheduling-rules-engine.md

1.5 KiB

layout title header prev_section next_section doc
docs Scheduling rules engine Scheduling rules engine user-guide/managing-rules user-guide/embedding-rules-engine true

Easy Rules provides APIs to schedule a rules engine using the popular Java scheduler Quartz.

To schedule a rules engine instance, first you need to add the following dependency to your pom.xml:

<dependency>
    <groupId>org.easyrules</groupId>
    <artifactId>easyrules-quartz</artifactId>
    <version>{{site.version}}</version>
</dependency>

Then, you can create a RulesEngineScheduler as follows:

RulesEngine rulesEngine = aNewRulesEngine().build();

Date now = new Date();
int everySecond = 1;

RulesEngineScheduler scheduler = RulesEngineScheduler.getInstance();
scheduler.scheduleAtWithInterval(rulesEngine, now, everySecond);

This will schedule the rules engine to start now and repeat every second.

The RulesEngineScheduler API provides methods to schedule a rules engine:

  • At a fixed point of time using scheduleAt(RulesEngine engine, Date when)
  • Repeatedly with a predefined interval using scheduleAtWithInterval(RulesEngine engine, Date when, int interval)
  • Using unix cron-like expression with scheduleCron(RulesEngine engine, String cronExpression)

To unregister a rules engine, use the following snippet:

scheduler.unschedule(rulesEngine);

You can find a tutorial about scheduling rules engine in the time tutorial.