From d0907ef6db2941e8ea4329d4c9cd9c98e62e488e Mon Sep 17 00:00:00 2001 From: Peter Kraft Date: Wed, 7 Aug 2024 13:42:35 -0700 Subject: [PATCH 1/6] fix default --- src/scheduler/scheduler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scheduler/scheduler.ts b/src/scheduler/scheduler.ts index 86bb02c12..8d7746cda 100644 --- a/src/scheduler/scheduler.ts +++ b/src/scheduler/scheduler.ts @@ -15,7 +15,7 @@ export enum SchedulerMode { export class SchedulerConfig { crontab: string = '* * * * *'; // Every minute - mode ?: SchedulerMode = SchedulerMode.ExactlyOncePerInterval; + mode ?: SchedulerMode = SchedulerMode.ExactlyOncePerIntervalWhenActive; } //// From 13ffef6ada928df7fa44c2a5ec8f3ab2d23406e2 Mon Sep 17 00:00:00 2001 From: Peter Kraft Date: Wed, 7 Aug 2024 14:03:16 -0700 Subject: [PATCH 2/6] fix default --- src/communicator.ts | 4 ++-- tests/failures.test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/communicator.ts b/src/communicator.ts index d691b7780..18363a09e 100644 --- a/src/communicator.ts +++ b/src/communicator.ts @@ -8,7 +8,7 @@ export type Communicator = (ctxt: CommunicatorContext, . export type CommunicatorFunction = Communicator; export interface CommunicatorConfig { - retriesAllowed?: boolean; // Should failures be retried? (default true) + retriesAllowed?: boolean; // Should failures be retried? (default false) intervalSeconds?: number; // Seconds to wait before the first retry attempt (default 1). maxAttempts?: number; // Maximum number of retry attempts (default 3). If errors occur more times than this, throw an exception. backoffRate?: number; // The multiplier by which the retry interval increases after every retry attempt (default 2). @@ -33,7 +33,7 @@ export class CommunicatorContextImpl extends DBOSContextImpl implements Communic { super(commName, span, logger, workflowContext); this.functionID = functionID; - this.retriesAllowed = params.retriesAllowed ?? true; + this.retriesAllowed = params.retriesAllowed ?? false; this.intervalSeconds = params.intervalSeconds ?? 1; this.maxAttempts = params.maxAttempts ?? 3; this.backoffRate = params.backoffRate ?? 2; diff --git a/tests/failures.test.ts b/tests/failures.test.ts index ad1425121..e8efcd598 100644 --- a/tests/failures.test.ts +++ b/tests/failures.test.ts @@ -179,7 +179,7 @@ class FailureTestClass { return await ctxt.invoke(FailureTestClass).testSerialError(maxRetry); } - @Communicator({ intervalSeconds: 1, maxAttempts: 2 }) + @Communicator({ retriesAllowed: true, intervalSeconds: 1, maxAttempts: 2 }) static async testFailCommunicator(ctxt: CommunicatorContext) { FailureTestClass.cnt++; if (ctxt.retriesAllowed && FailureTestClass.cnt !== ctxt.maxAttempts) { From c585756d5003afcf75aa7741a3bc26a6b220d02b Mon Sep 17 00:00:00 2001 From: Peter Kraft Date: Thu, 8 Aug 2024 10:06:37 -0700 Subject: [PATCH 3/6] revert --- src/communicator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/communicator.ts b/src/communicator.ts index 18363a09e..d691b7780 100644 --- a/src/communicator.ts +++ b/src/communicator.ts @@ -8,7 +8,7 @@ export type Communicator = (ctxt: CommunicatorContext, . export type CommunicatorFunction = Communicator; export interface CommunicatorConfig { - retriesAllowed?: boolean; // Should failures be retried? (default false) + retriesAllowed?: boolean; // Should failures be retried? (default true) intervalSeconds?: number; // Seconds to wait before the first retry attempt (default 1). maxAttempts?: number; // Maximum number of retry attempts (default 3). If errors occur more times than this, throw an exception. backoffRate?: number; // The multiplier by which the retry interval increases after every retry attempt (default 2). @@ -33,7 +33,7 @@ export class CommunicatorContextImpl extends DBOSContextImpl implements Communic { super(commName, span, logger, workflowContext); this.functionID = functionID; - this.retriesAllowed = params.retriesAllowed ?? false; + this.retriesAllowed = params.retriesAllowed ?? true; this.intervalSeconds = params.intervalSeconds ?? 1; this.maxAttempts = params.maxAttempts ?? 3; this.backoffRate = params.backoffRate ?? 2; From 1d8ca9c6217c5c0ddce263395d16ea72816c802f Mon Sep 17 00:00:00 2001 From: Peter Kraft Date: Thu, 8 Aug 2024 10:12:05 -0700 Subject: [PATCH 4/6] error --- src/workflow.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/workflow.ts b/src/workflow.ts index c4e93a04b..fcf525d68 100644 --- a/src/workflow.ts +++ b/src/workflow.ts @@ -781,7 +781,8 @@ export class WorkflowContextImpl extends DBOSContextImpl implements WorkflowCont try { result = await commFn.call(clsInst, ctxt, ...args); } catch (error) { - this.logger.error(error); + const e = error as Error + this.logger.error(`Communicator error being automatically retried. Attempt ${numAttempts} of ${ctxt.maxAttempts}. Error: ${e.message}`); span.addEvent(`Communicator attempt ${numAttempts + 1} failed`, { "retryIntervalSeconds": intervalSeconds, "error": (error as Error).message }, performance.now()); if (numAttempts < ctxt.maxAttempts) { // Sleep for an interval, then increase the interval by backoffRate. From 64fb2fbea437ac01656cbda7c62c3c31f7e99bf2 Mon Sep 17 00:00:00 2001 From: Peter Kraft Date: Thu, 8 Aug 2024 10:45:52 -0700 Subject: [PATCH 5/6] better warn --- src/workflow.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/workflow.ts b/src/workflow.ts index fcf525d68..aef1228b8 100644 --- a/src/workflow.ts +++ b/src/workflow.ts @@ -782,7 +782,7 @@ export class WorkflowContextImpl extends DBOSContextImpl implements WorkflowCont result = await commFn.call(clsInst, ctxt, ...args); } catch (error) { const e = error as Error - this.logger.error(`Communicator error being automatically retried. Attempt ${numAttempts} of ${ctxt.maxAttempts}. Error: ${e.message}`); + this.logger.warn(`Communicator error being automatically retried. Attempt ${numAttempts} of ${ctxt.maxAttempts}. ${e.stack}`); span.addEvent(`Communicator attempt ${numAttempts + 1} failed`, { "retryIntervalSeconds": intervalSeconds, "error": (error as Error).message }, performance.now()); if (numAttempts < ctxt.maxAttempts) { // Sleep for an interval, then increase the interval by backoffRate. From fc872c834984bbd176874b94917bf912eb53a519 Mon Sep 17 00:00:00 2001 From: Peter Kraft Date: Thu, 8 Aug 2024 11:07:52 -0700 Subject: [PATCH 6/6] not thrown twice --- src/dbos-executor.ts | 3 ++- src/httpServer/server.ts | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/dbos-executor.ts b/src/dbos-executor.ts index 2a63238cd..5a528b21a 100644 --- a/src/dbos-executor.ts +++ b/src/dbos-executor.ts @@ -675,8 +675,9 @@ export class DBOSExecutor implements DBOSExecutorContext { wCtxt.span.setStatus({ code: SpanStatusCode.OK }); } else { // Record the error. - const e: Error = err as Error; + const e = err as Error & {dbos_already_logged?: boolean}; this.logger.error(e); + e.dbos_already_logged = true if (wCtxt.isTempWorkflow) { internalStatus.name = `${DBOSExecutor.tempWorkflowName}-${wCtxt.tempWfOperationType}-${wCtxt.tempWfOperationName}`; } diff --git a/src/httpServer/server.ts b/src/httpServer/server.ts index de858bb13..3e53587b7 100644 --- a/src/httpServer/server.ts +++ b/src/httpServer/server.ts @@ -311,7 +311,10 @@ async checkPortAvailability(port: number, host: string): Promise { oc.span.setStatus({ code: SpanStatusCode.OK }); } catch (e) { if (e instanceof Error) { - oc.logger.error(e); + const annotated_e = e as Error & {dbos_already_logged?: boolean}; + if (annotated_e.dbos_already_logged !== true) { + oc.logger.error(e); + } oc.span.setStatus({ code: SpanStatusCode.ERROR, message: e.message }); let st = (e as DBOSResponseError)?.status || 500; const dbosErrorCode = (e as DBOSError)?.dbosErrorCode;