| 286 | } |
| 287 | |
| 288 | async appendNextEvent( |
| 289 | runId: string, |
| 290 | event: WorkflowRunEventDraft, |
| 291 | options: AppendWorkflowRunEventOptions = {} |
| 292 | ): Promise<WorkflowRunRecord> { |
| 293 | assert(runId.length > 0, "WorkflowRunStore.appendNextEvent: runId is required"); |
| 294 | const eventWithMaybeSequence = event as WorkflowRunEventDraft & { sequence?: unknown }; |
| 295 | assert( |
| 296 | eventWithMaybeSequence.sequence == null, |
| 297 | "WorkflowRunStore.appendNextEvent: event sequence is assigned by the store" |
| 298 | ); |
| 299 | return await this.withWorkflowMutationLock( |
| 300 | runId, |
| 301 | async () => |
| 302 | await this.withExpectedLeaseOwner( |
| 303 | runId, |
| 304 | options.expectedLeaseOwnerId, |
| 305 | async () => await this.appendNextEventUnlocked(runId, event, options) |
| 306 | ) |
| 307 | ); |
| 308 | } |
| 309 | |
| 310 | async appendEvent( |
| 311 | runId: string, |