JVM - schedule()

Creates a new Schedule to run a function on a defined frequency.

import io.nitric.Nitric;
import io.nitric.faas.v0.Frequency;

public class Application {
  public static void main(String[] args) {
    Nitric.INSTANCE.schedule("aggregate-data").every(3, Frequency.Hours, (ctx) -> {
      System.out.println("aggregating data");
      return ctx;
    });

    Nitric.run();
  }
}

Parameters

  • Name
    description
    Required
    Required
    Type
    String
    Description

    The unique name of this Schedule within the app. Subsequent calls to schedule with the same name will return the same object.

Notes

  • Schedules do not require access permissions to be specified.
  • During local development schedules can be triggered manually from the local development dashboard

Examples

Create a Schedule

import io.nitric.Nitric;
import io.nitric.faas.v0.Frequency;

public class Application {
  public static void main(String[] args) {
    // Can be defined as a rate using `.every()`
    Nitric.INSTANCE.schedule("send-reminders").every(3, Frequency.Minutes, (ctx) -> {
      // add code to run here
      return ctx;
    });

    // Can be defined as a cron expression using `.cron()`
    Nitric.INSTANCE.schedule("archive-orders").cron("0 1 1 * *", (ctx) -> {
      // add code to run here
      return ctx;
    });

    Nitric.run();
  }
}