cron method

Future<void> cron(
  1. String cronExpression,
  2. IntervalHandler handler, {
  3. List<IntervalHandler> middlewares = const [],
})

Run the handler at a certain interval defined by the cronExpression.

Implementation

Future<void> cron(String cronExpression, IntervalHandler handler,
    {List<IntervalHandler> middlewares = const []}) async {
  var registrationRequest = $sp.RegistrationRequest(
    scheduleName: name,
    cron: $sp.ScheduleCron(expression: cronExpression),
  );

  final composedHandler =
      composeMiddleware([...middlewares, handler], IntervalContext.fromCtx);

  var worker = IntervalWorker(registrationRequest, composedHandler);

  await worker.start();
}