markFailed method
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 {
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();
if (terminal) {
updates['owner_id'] = null;
updates['lease_expires_at'] = null;
updates['wait_topic'] = null;
updates['resume_at'] = null;
updates['suspension_data'] = null;
}
final changed = await ctx
.query<StemWorkflowRun>()
.whereEquals('id', runId)
.whereEquals('namespace', namespace)
.whereIn('status', [
WorkflowStatus.running.name,
WorkflowStatus.suspended.name,
])
.update(updates);
if (terminal && changed > 0) await _deleteWatcher(ctx, runId);
}
});
}