Skip to content

Commit

Permalink
api: create and read snapshots with log
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelPull committed Dec 11, 2023
1 parent 2a4b983 commit 2ce8167
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions api/src/service/cache_snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export async function getLatestSnapshot(
items = items.slice(snapshotIndex + 1);
const parsedEvents = parseBusinessEvents(items, streamName);
const businessEvents = parsedEvents.filter(Result.isOk);
const sourcedData = sourceFromSnapshot(ctx, businessEvents, false, data);
const sourcedData = sourceFromSnapshot(ctx, businessEvents, true, data);

// if there are reordering events, apply it
if (lastOrderingEventItem && eventType === SUBPROJECT_SNAPSHOT_EVENT_KEY) {
Expand Down Expand Up @@ -240,7 +240,7 @@ export async function publishSnapshot(
const parsedEvents = parseBusinessEvents(items, streamName);
const businessEvents = parsedEvents.filter(Result.isOk);

const sourcedData = sourceFromSnapshot(ctx, businessEvents, false, data);
const sourcedData = sourceFromSnapshot(ctx, businessEvents, true, data);
if (ordering && eventType === SUBPROJECT_SNAPSHOT_EVENT_KEY) {
if (Result.isOk(sourcedData)) {
sourcedData.workflowitemOrdering = ordering;
Expand Down
7 changes: 6 additions & 1 deletion api/src/service/domain/workflow/workflowitem_ordering.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AssertionError } from "assert";
import * as Workflowitem from "./workflowitem";
import logger from "../../../lib/logger";

export type WorkflowitemOrdering = Workflowitem.Id[];

Expand Down Expand Up @@ -73,7 +74,11 @@ function closedAt(item: Workflowitem.ScrubbedWorkflowitem): string | AssertionEr
const traceEvent = item.log.find((e) => e.businessEvent.type === "workflowitem_closed");

if (traceEvent === undefined || traceEvent.businessEvent.type !== "workflowitem_closed") {
return new AssertionError({ message: `Expected close event for workflowitem ${item.id}` });
const error = new AssertionError({
message: `Expected close event for workflowitem ${item.id}`,
});
logger.error(error, error.message);
return error;
}
const closeEvent = traceEvent.businessEvent;

Expand Down

0 comments on commit 2ce8167

Please sign in to comment.