claimRunExecution method

  1. @override
Future<WorkflowExecutionClaim?> claimRunExecution(
  1. String runId, {
  2. required String ownerId,
  3. Duration leaseDuration = const Duration(seconds: 30),
})
override

Atomically claims runId, returning its unique execution identity.

Implementation

@override
Future<WorkflowExecutionClaim?> claimRunExecution(
  String runId, {
  required String ownerId,
  Duration leaseDuration = const Duration(seconds: 30),
}) async {
  final state = _runs[runId];
  if (state == null || state.status != WorkflowStatus.running) return null;
  if (state.waitTopic != null) return null;
  final now = _clock.now();
  if (!_leaseExpired(state, now)) return null;
  final executionId = 'exec-${_executionCounter++}';
  final expiresAt = now.add(leaseDuration);
  _runs[runId] = state.copyWith(
    ownerId: ownerId,
    executionId: executionId,
    leaseExpiresAt: expiresAt,
    updatedAt: now,
  );
  return WorkflowExecutionClaim(
    runId: runId,
    executionId: executionId,
    ownerId: ownerId,
    leaseExpiresAt: expiresAt,
  );
}