kagkarlsson / db-scheduler

Persistent cluster-friendly scheduler for Java
Apache License 2.0
1.23k stars 188 forks source link

db-scheduler executing when parameter meets #521

Closed Mukund2900 closed 1 month ago

Mukund2900 commented 1 month ago

is there a way to schedule task when a parameter meets ? db-scheduler.enabled=true db-scheduler.heartbeat-interval=5m db-scheduler.polling-interval=10s db-scheduler.polling-limit= db-scheduler.table-name=scheduled_tasks db-scheduler.immediate-execution-enabled=false db-scheduler.scheduler-name= db-scheduler.threads=10

These are the parameters.

    Task<Void> genTripSheetOneTimeTask() {
        return Tasks.oneTime("generate-trip-sheet-task")
                .onFailure(new FailureHandler.MaxRetriesFailureHandler<>(maxRetryCount, (executionComplete, executionOperations) -> {
                    log.info(LOG_INFO, executionComplete.getExecution().consecutiveFailures, retryIntervalSecs);
                    executionOperations.reschedule(executionComplete, Instant.now().plusSeconds(retryIntervalSecs));
                    String[] split = executionComplete.getExecution().taskInstance.getId().split("/");
                    recordTripSheetGenerationFailure(split[0]);
                }))
                .execute((instance, ctx) -> {
                    String taskName = instance.getId();
                    log.info(LOG_M, taskName, new Date(System.currentTimeMillis()));
                    autoGenerateTripSheetTask.generate(taskName);
                });
    }
I want this to execute when this row in db has a specific column value. 

Is there a way to do it ? I dont want that condition to be verified in code . Because that will cause delay. As it is possible that some other instance might meet the criteria. For eg, i have 3 env and column name is env and value is blue. Now I want this task to be picked only by the blue env.