Search code examples
javaspringspring-bootschedulerjobrunr

JobRunr Recurring Job is not Triggering every day


I have created a Recurring Job using the JobRunr to trigger at daily morning 5 AM. it triggers some days at 5 AM. some days it doesn't not triggers. is this a bug in jobrunr or my code ?

so in last week it triggered on Monday Tuesday and Friday at 5 AM. and doesn't triggered on Wednesday, Thursday Saturday and Sunday. i want it to be triggered daily at 5AM.

in jobrunr dashboard i can see there is a recurring job that will triggers at 5 Am daily.

here is my code.

pom.xml

 <dependency>
            <groupId>org.jobrunr</groupId>
            <artifactId>jobrunr-spring-boot-3-starter</artifactId>
            <version>7.2.0</version>
        </dependency>

jobrunrConfig


import javax.sql.DataSource;
import org.jobrunr.configuration.JobRunr;
import org.jobrunr.configuration.JobRunrConfiguration.JobRunrConfigurationResult;
import org.jobrunr.jobs.mappers.JobMapper;
import org.jobrunr.scheduling.JobScheduler;
import org.jobrunr.storage.StorageProvider;
import org.jobrunr.storage.sql.common.SqlStorageProviderFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Profile(value = {"scheduler"})
public class JobRunrConfig {



  @Bean
  public StorageProvider storageProvider(DataSource dataSource, JobMapper jobMapper) {
    StorageProvider storageProvider = SqlStorageProviderFactory.using(dataSource);
    storageProvider.setJobMapper(jobMapper);
    return storageProvider;
  }

  @Bean
  public JobScheduler jobScheduler(StorageProvider storageProvider) {
    return new JobScheduler(storageProvider);
  }

  @Bean
  public JobRunrConfigurationResult jobRunr(StorageProvider storageProvider) {
    return JobRunr.configure()
        .useStorageProvider(storageProvider)
        .useDashboardIf(true)
        .useBackgroundJobServer()
        .initialize();
  }
}

here is code to trigger

import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jobrunr.jobs.annotations.Job;
import org.jobrunr.jobs.annotations.Recurring;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RequiredArgsConstructor
@Profile(value = {"scheduler"})
public class AutoDepositJobSchedule {




  @Recurring(id = "auto-recurdeposit-job", cron = "${application.autodepositCron}")
  @Job(name = "Auto job")
  public void executeAutoPresentations() {
    log.info("job runr  Triggered AT" + LocalDateTime.now());

      try {
        // logic to execute
      } catch (Exception e) {
        log.error("Error while job execution", e);
      }

  }
}



also part from normal application.properties i have also added the another application-scheduler.properties specific for this

org.jobrunr.background-job-server.enabled: true

Solution

  • If the connection drops, JobRunr will stop processing as it can flood your disk. Make sure your connection does not drop, then it will run stable.