onStart method

  1. @override
Future<bool> onStart()
override

Callback when this executor is started. Returns true if successfully started, false otherwise.

Implementation

@override
Future<bool> onStart() async {
  if (deployment?.deployed == null) {
    warning(
        '$runtimeType - This deployment does not have a start time. Cannot execute this trigger.');
    return false;
  }

  if (configuration?.elapsedTime == null) {
    warning(
        '$runtimeType - This ElapsedTimeTrigger does not have a elapsedTime specified. Cannot execute this trigger.');
    return false;
  }

  int delay = configuration!.elapsedTime!.inMilliseconds -
      (DateTime.now().millisecondsSinceEpoch -
          deployment!.deployed!.millisecondsSinceEpoch);

  if (delay > 0) {
    timer = Timer(Duration(milliseconds: delay), () => onTrigger());
  } else {
    warning(
        '$runtimeType - the trigger time is in the past and should have happened already.');
    return false;
  }

  return true;
}