@versori/run 0.5.3 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -166,7 +166,7 @@ export class VanillaInterpreter {
166
166
  }
167
167
  }
168
168
  static async newInstance(options = {}) {
169
- const log = options.logger || new ConsoleLogger();
169
+ const log = options.logger || new ConsoleLogger("info");
170
170
  const compiler = options.compiler || new ObservableCompiler();
171
171
  const serviceName = Deno.env.get(envVarProjectId) || 'example-service';
172
172
  const environmentID = Deno.env.get(envVarEnvId) || 'development';
@@ -1 +1 @@
1
- {"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/vanilla/compilers/durableworkflow.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EACH,mBAAmB,EACnB,sBAAsB,EACzB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAqB,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,wBAAgB,sBAAsB,CAClC,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,WAAW,GACpB,UAAU,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CA0FjD;AAED,eAAO,MAAM,uBAAuB,EAAE,eAAe,CAAC,mBAAmB,EAAE,sBAAsB,CAI5F,CAAC"}
1
+ {"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/vanilla/compilers/durableworkflow.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EACH,mBAAmB,EACnB,sBAAsB,EACzB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAqB,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,wBAAgB,sBAAsB,CAClC,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,WAAW,GACpB,UAAU,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CA6EjD;AAED,eAAO,MAAM,uBAAuB,EAAE,eAAe,CAAC,mBAAmB,EAAE,sBAAsB,CAIhG,CAAC"}
@@ -10,31 +10,24 @@
10
10
  * As of the Change Date, in accordance with the Business Source License,
11
11
  * use of this software will be governed by the Apache License, Version 2.0.
12
12
  */
13
+ import { ulid } from '../../../../deps/jsr.io/@std/ulid/1.0.0/mod.js';
13
14
  import { Observable } from 'rxjs';
14
15
  import { DurableWorkflowTrigger, } from '../../../dsl/triggers/DurableTrigger.js';
15
16
  import { VanillaActivation } from '../ObservableCompiler.js';
16
17
  export function compileDurableWorkflow(ctx, trigger, signal) {
17
18
  return new Observable((subscriber) => {
18
19
  function cleanup() {
19
- ctx.log.debug('webhook trigger stopped');
20
+ ctx.log.debug('durable workflow trigger stopped');
20
21
  subscriber.complete();
21
22
  }
22
23
  signal.addEventListener('abort', cleanup, { once: true });
23
24
  let consecutiveErrors = 0;
24
- const maxConsecutiveErrors = 5;
25
25
  (async () => {
26
26
  while (true) {
27
27
  if (signal.aborted) {
28
28
  cleanup();
29
29
  break;
30
30
  }
31
- if (consecutiveErrors >= maxConsecutiveErrors) {
32
- ctx.log.error('reached too many consecutive errors stopping trigger', {
33
- 'triggerId': trigger.id,
34
- });
35
- cleanup();
36
- break;
37
- }
38
31
  try {
39
32
  // Right now the API itself will hang for a period of time if no workflows are available.
40
33
  // so we don't need to add a delay here.
@@ -47,26 +40,21 @@ export function compileDurableWorkflow(ctx, trigger, signal) {
47
40
  continue;
48
41
  }
49
42
  for (const wf of wfs.workflows) {
50
- if (wf.id &&
51
- wf.attempt !== undefined &&
52
- trigger.options.maxAttempts &&
53
- wf.attempt > trigger.options.maxAttempts) {
54
- ctx.log.error('Workflow exceeded max attempts failing', {
55
- workflowId: wf.id,
56
- attempts: wf.attempt,
57
- });
58
- await ctx.queueProvider.complete({
59
- id: wf.id,
60
- output: wf.output,
61
- status: 'failed',
62
- });
63
- continue;
64
- }
65
43
  const payload = wf.payload ? atob(wf.payload) : '{}';
66
44
  const data = JSON.parse(payload);
67
- const activation = VanillaActivation;
68
- const newContext = ctx.contextProvider.create(activation, data, {
45
+ const newContext = ctx.contextProvider.createWithExecutionId(VanillaActivation, data, wf.metadata?.executionId ?? ulid().toString(), {
69
46
  workflow: wf,
47
+ onSuccess: (completedContext) => {
48
+ // locked status means we own the workflow and it's not completed yet
49
+ if (wf.status !== 'locked') {
50
+ return;
51
+ }
52
+ ctx.queueProvider.complete({
53
+ id: wf.id,
54
+ output: btoa(JSON.stringify(completedContext.data)),
55
+ status: 'completed',
56
+ });
57
+ },
70
58
  });
71
59
  consecutiveErrors = 0;
72
60
  subscriber.next(newContext);
@@ -75,6 +63,8 @@ export function compileDurableWorkflow(ctx, trigger, signal) {
75
63
  catch (error) {
76
64
  ctx.log.error('Error fetching workflows', { error });
77
65
  consecutiveErrors++;
66
+ // no workflows available, back-off a bit before retrying
67
+ await new Promise((resolve) => setTimeout(resolve, Math.min(consecutiveErrors * 1000, 30000)));
78
68
  }
79
69
  }
80
70
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versori/run",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Versori Run",
5
5
  "homepage": "https://github.com/versori/versori-run#readme",
6
6
  "repository": {
@@ -172,7 +172,7 @@ class VanillaInterpreter {
172
172
  }
173
173
  }
174
174
  static async newInstance(options = {}) {
175
- const log = options.logger || new ConsoleLogger_js_1.ConsoleLogger();
175
+ const log = options.logger || new ConsoleLogger_js_1.ConsoleLogger("info");
176
176
  const compiler = options.compiler || new ObservableCompiler_js_1.ObservableCompiler();
177
177
  const serviceName = Deno.env.get(constants_js_1.envVarProjectId) || 'example-service';
178
178
  const environmentID = Deno.env.get(constants_js_1.envVarEnvId) || 'development';
@@ -1 +1 @@
1
- {"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/vanilla/compilers/durableworkflow.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EACH,mBAAmB,EACnB,sBAAsB,EACzB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAqB,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,wBAAgB,sBAAsB,CAClC,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,WAAW,GACpB,UAAU,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CA0FjD;AAED,eAAO,MAAM,uBAAuB,EAAE,eAAe,CAAC,mBAAmB,EAAE,sBAAsB,CAI5F,CAAC"}
1
+ {"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/vanilla/compilers/durableworkflow.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EACH,mBAAmB,EACnB,sBAAsB,EACzB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAqB,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,wBAAgB,sBAAsB,CAClC,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,WAAW,GACpB,UAAU,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CA6EjD;AAED,eAAO,MAAM,uBAAuB,EAAE,eAAe,CAAC,mBAAmB,EAAE,sBAAsB,CAIhG,CAAC"}
@@ -14,31 +14,24 @@
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.durableWorkflowCompiler = void 0;
16
16
  exports.compileDurableWorkflow = compileDurableWorkflow;
17
+ const mod_js_1 = require("../../../../deps/jsr.io/@std/ulid/1.0.0/mod.js");
17
18
  const rxjs_1 = require("rxjs");
18
19
  const DurableTrigger_js_1 = require("../../../dsl/triggers/DurableTrigger.js");
19
20
  const ObservableCompiler_js_1 = require("../ObservableCompiler.js");
20
21
  function compileDurableWorkflow(ctx, trigger, signal) {
21
22
  return new rxjs_1.Observable((subscriber) => {
22
23
  function cleanup() {
23
- ctx.log.debug('webhook trigger stopped');
24
+ ctx.log.debug('durable workflow trigger stopped');
24
25
  subscriber.complete();
25
26
  }
26
27
  signal.addEventListener('abort', cleanup, { once: true });
27
28
  let consecutiveErrors = 0;
28
- const maxConsecutiveErrors = 5;
29
29
  (async () => {
30
30
  while (true) {
31
31
  if (signal.aborted) {
32
32
  cleanup();
33
33
  break;
34
34
  }
35
- if (consecutiveErrors >= maxConsecutiveErrors) {
36
- ctx.log.error('reached too many consecutive errors stopping trigger', {
37
- 'triggerId': trigger.id,
38
- });
39
- cleanup();
40
- break;
41
- }
42
35
  try {
43
36
  // Right now the API itself will hang for a period of time if no workflows are available.
44
37
  // so we don't need to add a delay here.
@@ -51,26 +44,21 @@ function compileDurableWorkflow(ctx, trigger, signal) {
51
44
  continue;
52
45
  }
53
46
  for (const wf of wfs.workflows) {
54
- if (wf.id &&
55
- wf.attempt !== undefined &&
56
- trigger.options.maxAttempts &&
57
- wf.attempt > trigger.options.maxAttempts) {
58
- ctx.log.error('Workflow exceeded max attempts failing', {
59
- workflowId: wf.id,
60
- attempts: wf.attempt,
61
- });
62
- await ctx.queueProvider.complete({
63
- id: wf.id,
64
- output: wf.output,
65
- status: 'failed',
66
- });
67
- continue;
68
- }
69
47
  const payload = wf.payload ? atob(wf.payload) : '{}';
70
48
  const data = JSON.parse(payload);
71
- const activation = ObservableCompiler_js_1.VanillaActivation;
72
- const newContext = ctx.contextProvider.create(activation, data, {
49
+ const newContext = ctx.contextProvider.createWithExecutionId(ObservableCompiler_js_1.VanillaActivation, data, wf.metadata?.executionId ?? (0, mod_js_1.ulid)().toString(), {
73
50
  workflow: wf,
51
+ onSuccess: (completedContext) => {
52
+ // locked status means we own the workflow and it's not completed yet
53
+ if (wf.status !== 'locked') {
54
+ return;
55
+ }
56
+ ctx.queueProvider.complete({
57
+ id: wf.id,
58
+ output: btoa(JSON.stringify(completedContext.data)),
59
+ status: 'completed',
60
+ });
61
+ },
74
62
  });
75
63
  consecutiveErrors = 0;
76
64
  subscriber.next(newContext);
@@ -79,6 +67,8 @@ function compileDurableWorkflow(ctx, trigger, signal) {
79
67
  catch (error) {
80
68
  ctx.log.error('Error fetching workflows', { error });
81
69
  consecutiveErrors++;
70
+ // no workflows available, back-off a bit before retrying
71
+ await new Promise((resolve) => setTimeout(resolve, Math.min(consecutiveErrors * 1000, 30000)));
82
72
  }
83
73
  }
84
74
  })();