Schedule Grid Workload with Cron using GridGain

One of the “unsung” APIs in GridGain 3.0 is a cron-based scheduling for task, closures, runnables, callable – and pretty much everything else that you may want to run on the grid. It wasn’t too hard to do it before in GridGain 2 – but in GridGain we’ve added a comprehensive API support for distributed cron-based scheduling.

Here’s an example of scheduling a closure that broadcasts a message to all nodes every minute with initial delay in two seconds five times:

Grid g = G.grid();

UUID lid = g.localNode().id();

g.scheduleLocal(
    new CAX() {
        @Override public void applyx() {
            g.run(BROADCAST, F.println("Hello from: " + lid));
        }   
    }, "{2, 5} * * * * *" // 2 seconds delay with 5 executions only.
);

First of all, notice how nicely you can reuse variable lid that is defined in local context but is reused in the closure that gets executed remotely thanks to our Zero Deployment technology.

Secondly, method scheduleLocal() returns comprehensive future object of type GridScheduleFuture that gives you rich API for managing cron-based execution.

All in all – very nice and powerful addition to GridGain’s arsenal of distributed functionality.

One response

  1. Hi Nikita,

    this seems like an interesting feature. Although I have one issue with the pattern.

    Currently I have a homogenous grid. Every node is identical. Each node had Jetty embedded and we are behind a loadbalancer. A Homogenous grid makes our deploymnet, etc, much simpler.

    So, in a Homogenous grid, is there any way to schedule a task. That is, is there any way when starting a node, for it to try to add a cron task, but if another node has already started that task, it turns the cron request into a noop. Then if the initiating node fails, have failover of the cron task to other nodes?

    Or in other words a two-way gridification of the cron task.

    Thanks,

    Paul.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: