markFailed method

  1. @override
Future<void> markFailed(
  1. String runId,
  2. Object error,
  3. StackTrace stack, {
  4. bool terminal = false,
})

Marks the run as failed and records error and stack.

Implementation

@override
Future<void> markFailed(
  String runId,
  Object error,
  StackTrace stack, {
  bool terminal = false,
}) async {
  final now = _clock.now().toUtc();

  await _connections.runInTransaction((ctx) async {
    if (terminal) {
      await _deleteWatcher(ctx, runId);
    }

    final run = await ctx
        .query<StemWorkflowRun>()
        .whereEquals('id', runId)
        .whereEquals('namespace', namespace)
        .first();

    if (run != null) {
      final updates = StemWorkflowRunUpdateDto(
        status: terminal ? WorkflowStatus.failed.name : null,
        lastError: jsonEncode({
          'error': error.toString(),
          'stack': stack.toString(),
        }),
        updatedAt: now,
      ).toMap();
      await ctx.repository<StemWorkflowRun>().update(
        updates,
        where: StemWorkflowRunPartial(id: runId, namespace: namespace),
      );
    }
  });
}