Skip to content

Commit

Permalink
Log execution start (#158)
Browse files Browse the repository at this point in the history
* Log execution start

* Fix softTimeout not being applied

* Fix docs

* Update docs
  • Loading branch information
Siegrift authored Nov 18, 2024
1 parent 42d5507 commit 8d20f1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/processing/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Processing

> Implementation of [OIS processing](https://docs.api3.org/reference/ois/latest/processing.html).
> Implementation of [OIS processing](https://airnode-docs.api3.org/reference/ois/latest/processing.html).
The pre/post processing is only supported for Node.js environments and uses internal Node.js modules.

Expand Down
10 changes: 6 additions & 4 deletions src/run-in-loop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ export interface RunInLoopOptions {
/** Part of every message logged by the logger. */
logLabel?: Lowercase<string>;
/**
* Minimum time to wait between executions. E.g. value 500 means that the next execution will be started only after
* 500ms from the start of the previous one (even if the previous one ended after 150ms). Default is 0.
* The ideal frequency of callback executions. E.g. value 500 means that the next callback execution will be started
* only after 500ms from the start of the previous one (even if the previous one ended after 150ms). Default is 0. The
* delay between callback executions can be modified by min/max wait time.
*/
frequencyMs?: number;
/**
Expand Down Expand Up @@ -55,13 +56,13 @@ export const runInLoop = async (
frequencyMs = 0,
minWaitTimeMs = 0,
maxWaitTimeMs,
softTimeoutMs,
softTimeoutMs = frequencyMs,
hardTimeoutMs,
enabled = true,
initialDelayMs,
} = options;

if (softTimeoutMs && hardTimeoutMs && hardTimeoutMs < softTimeoutMs) {
if (hardTimeoutMs && hardTimeoutMs < softTimeoutMs) {
throw new Error('hardTimeoutMs must not be smaller than softTimeoutMs');
}
if (minWaitTimeMs && maxWaitTimeMs && maxWaitTimeMs < minWaitTimeMs) {
Expand All @@ -77,6 +78,7 @@ export const runInLoop = async (
if (enabled) {
const context = logLabel ? { executionId, label: logLabel } : { executionId };
const shouldContinueRunning = await logger.runWithContext(context, async () => {
logger.info('Starting execution');
const goRes = await go(fn, hardTimeoutMs ? { totalTimeoutMs: hardTimeoutMs } : {}); // NOTE: This is a safety net to prevent the loop from hanging
if (!goRes.success) {
logger.error(`Unexpected runInLoop error`, goRes.error);
Expand Down

0 comments on commit 8d20f1c

Please sign in to comment.