Dart - schedule.cron()

Sets the cron expressions that determines when the schedule triggers and a callback to be triggered.

import 'package:nitric_sdk/nitric.dart';
Nitric.schedule("send-reminder").cron("0 1 1 * *", (ctx) async {
// do some processing
return ctx;
});

Parameters

  • Name
    expression
    Required
    Required
    Type
    String
    Description

    The expression that sets when the schedule will be triggered. This value should be a standard 5 value Unix cron expression, e.g., '0 1 1 * *'.

  • Name
    handler
    Required
    Required
    Type
    IntervalHandler
    Description

    Callback services to use as the handler which will run on the defined frequency.

Examples

Create a Schedule to run on a cron

import 'package:nitric_sdk/nitric.dart';
// every 15 minutes
Nitric.schedule("check for updates").cron("0/15 * * * *", (ctx) async {
print("checking for updates");
return ctx;
});
// at 1:00am on the 1st of every month
Nitric.schedule("delete stale data").cron("0 1 1 * *", (ctx) async {
print("clearing data");
return ctx;
});
Last updated on Dec 19, 2024