Skip to content

isCallbackRunning always returns false outside the callback #1004

@extaravindabr-byte

Description

@extaravindabr-byte

Description

`async function waitForJobCompletion(waitTime = CRON_JOB_WAIT_TIME, maxRetries = CRON_JOB_CHECK_MAX_RETRIES) {
const isJobRunning = job.isCallbackRunning;
const isRetriesExhausted = maxRetries == 0;
if (!isJobRunning || isRetriesExhausted) return;

  INFO('Waiting for the running callback');
  await wait(waitTime);
  await waitForJobCompletion(waitTime, maxRetries - 1);
}

`

If we check whether the job is running outside the cron job onTick callback it always returns false even if the callback is running currently

Expected Behavior

isCallbackRunning property should return true if the callback is running for the given cron

Actual Behavior

isCallbackRunning property always returns false

Possible Fix

Internally set the isCallbackrunning to correct value so that when we check the property outside it shows correct value.

Steps to Reproduce

  1. Set a cron that runs every minute
  2. When the callback for the cron is running, externally check the isCallbackrunning property, view a different callback (Inside setInterval etc)

Context

I was trying to gracefully close the cron job

Your Environment

  • cron version:
  • NodeJS version:
  • Operating System and version:
  • TypeScript version (if applicable):
  • Link to your project (if applicable):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions