Skip to content

Commit

Permalink
Merge pull request #38 from redpencilio/bugfix/prevent-concurrent-tas…
Browse files Browse the repository at this point in the history
…k-runs

When cronjob is scheduled at a faster rate than the job duration itself, a new task run was run
  • Loading branch information
gauquiebart authored Jul 27, 2023
2 parents 0ee12d6 + 843608f commit 8262622
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.vscode
.vscode
.idea
5 changes: 4 additions & 1 deletion app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,20 @@ const consumerJob = new CronJob(CRON_PATTERN, async () => {
console.log("Another task is still running");
return;
}

taskIsRunning = true;
const stream = namedNode(LDES_STREAM);
const initialState = await fetchState(stream);
const endpoint = LDES_ENDPOINT_VIEW;

console.log("RUN CONSUMER");

const ldesOptions = {
dereferenceMembers: LDES_DEREFERENCE_MEMBERS,
disablePolling: RUNONCE,
pollingInterval: LDES_POLLING_INTERVAL
};

if (LDES_REQUESTS_PER_MINUTE) {
ldesOptions.requestsPerMinute = LDES_REQUESTS_PER_MINUTE;
}
Expand Down Expand Up @@ -131,7 +135,6 @@ const consumerJob = new CronJob(CRON_PATTERN, async () => {
}
} catch (e) {
console.error(e);
} finally {
taskIsRunning = false;
}
});
Expand Down

0 comments on commit 8262622

Please sign in to comment.