postRun method

  1. @override
Future<void> postRun(
  1. TaskResult result
)
override

Action to run after a task associated with this RunCondition has run, whether successfully or not.

This method will not be called if the Dartle cache has been disabled.

Implementation

@override
Future<void> postRun(TaskResult result) async {
  var success = result.isSuccess;
  DartleException? error;

  if (success) {
    if (outputs.isNotEmpty && verifyOutputsExist) {
      logger.fine('Verifying task produced expected outputs');
      try {
        await _verifyOutputs();
      } on DartleException catch (e) {
        success = false;
        error = e;
      }
    }
  }

  final taskName = result.invocation.name;
  logger.fine(() => "Updating cached artifacts for task '$taskName'");
  if (success) {
    await cache.clean(key: taskName);
    await cache(inputs, key: taskName);
    await cache(outputs, key: taskName);
    await cache.cacheInvocation(result.invocation);
  } else {
    if (outputs.isEmpty) {
      // the task failed without any outputs, so for it to run again next
      // time we need to remove its inputs
      await cache.remove(inputs, key: taskName);
    } else {
      // just forget the outputs of the failed task as they
      // may not be correct anymore
      await cache.remove(outputs, key: taskName);
    }
    await cache.removeTaskInvocation(taskName);
    if (error != null) throw error;
  }
}