Skip to content

Commit

Permalink
plan_queue_reentrancy_fix_for_imported_templates (#100)
Browse files Browse the repository at this point in the history
* tests pass

* fix actions upload to v4
  • Loading branch information
geoffhendrey authored Jan 31, 2025
1 parent 58f2c5e commit 34dde19
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

- name: Upload npm debug log on failure
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: npm-debug-log
path: /home/runner/.npm/_logs/*-debug.log
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_bun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: Upload Bun test logs on failure
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: bun-test-logs
path: ./bun-test-logs/*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stated-js",
"version": "0.1.51",
"version": "0.1.52",
"license": "Apache-2.0",
"description": "JSONata embedded in JSON",
"main": "./dist/src/index.js",
Expand Down
4 changes: 4 additions & 0 deletions src/ConsoleLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export default class ConsoleLogger implements StatedLogger{
this.level = initialLevel;
}

setLevel(level:Levels):void {
this.level = level;
}

debug(...args: any[]) {
if (LOG_LEVELS[this.level] >= LOG_LEVELS.debug) {
console.debug(...args);
Expand Down
18 changes: 14 additions & 4 deletions src/ParallelPlanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ export class ParallelPlanner implements Planner{


async execute(plan: ExecutionPlan): Promise<void>{

const isDebug = this.tp.isEnabled("debug");

if((plan as ParallelExecutionPlan).completed){
const msg = `Attempt to re-execute a completed plan: ${(plan as ParallelExecutionPlanDefault).toJSON()}`;
this.tp.logger.error(msg);
throw new Error(msg);
}

//console.log(`executing ${stringifyTemplateJSON(plan)}`);
//we create a map of Promises. This is very important as two or more ParallelPlanSteps can have dependency
//on the same node (by jsonPtr). These must await on the same Promise. For any jsonPtr, there must be only
Expand All @@ -283,13 +292,13 @@ export class ParallelPlanner implements Planner{

if(circular){ //if step is marked as circular, evaluate it's expression and bail without following its reference
step.didUpdate = await this.tp.evaluateNode(step);
this.tp.logger.debug(`execute: circular, abort ${step.jsonPtr}`);
isDebug && this.tp.logger.debug(`execute: circular, abort ${step.jsonPtr}`);
return step;
}

// Check if a Promise already exists for this jsonPtr (mutation is put in the map first since it is the root of the plan, so will be found by the leaves that depend on it)
if (promises.has(jsonPtr)) {
this.tp.logger.debug(`execute: waiting ${step.jsonPtr}`);
isDebug && this.tp.logger.debug(`execute: waiting ${step.jsonPtr}`);
const promise = promises.get(jsonPtr)!; //don't freak out ... '!' is TS non-null assertion
//return a 'pointer' to the cached plan, or else we create loops with lead nodes in a mutation plan pointing back to the root of the
//plan that holds the mutation
Expand All @@ -306,6 +315,7 @@ export class ParallelPlanner implements Planner{

const executor = async () => {
try {
isDebug && this.tp.logger.debug(`execute: ${step.jsonPtr}`)
step.output = plan.output;
step.forkId = plan.forkId;
step.forkStack = plan.forkStack;
Expand All @@ -322,7 +332,7 @@ export class ParallelPlanner implements Planner{
//need to run the step
if( plan.op === "initialize" || step.parallel.some((step) => step.didUpdate || step.completed)){
if(!step.completed){ //fast forward past completed steps
this.tp.logger.debug(`execute: evaluate ${step.jsonPtr}`);
isDebug && this.tp.logger.debug(`execute: evaluate ${step.jsonPtr}`);
step.didUpdate = await this.tp.evaluateNode(step);
}
}else { //if we are here then we are not initializing a node, but reacting to some mutation.
Expand All @@ -337,7 +347,7 @@ export class ParallelPlanner implements Planner{
}
const mutationCausedAChange= (await theMutation).didUpdate;
if(mutationCausedAChange){
this.tp.logger.debug(`execute: evaluate ${step.jsonPtr}`);
isDebug && this.tp.logger.debug(`execute: evaluate ${step.jsonPtr}`);
const _didUpdate= await this.tp.evaluateNode(step);
step.didUpdate = _didUpdate;
}
Expand Down
Loading

0 comments on commit 34dde19

Please sign in to comment.