Sometimes you want to create a Job but define multiple different schedules that will Trigger it at runtime.

Constructor

DynamicSchedule()

Creates a new DynamicSchedule.

Instance methods

register()

Use this method to register a new schedule with the DynamicSchedule.

unregister()

Use this method to unregister a schedule from the DynamicSchedule, using the id you used when registering it.

Example use cases:

You want your users to be able to define their own schedule

  1. Create a DynamicSchedule.
  2. Create a Job that will be triggered by the DynamicSchedule.
  3. Anywhere in your codebase you can now call yourDynamicSchedule.register to add a new schedule. You should use your user’s userId when registering.
  4. When the Job runs you can check the context.source.id to see which user triggered it.