kagkarlsson / db-scheduler

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

Adding new OneTimeTask dynamically at runtime and it to current Scheduler #501

Closed rahul1257 closed 1 month ago

rahul1257 commented 2 months ago

Prerequisites

Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

Expected Behavior

Hi! i saw we cannot create recurring task at runtime but just wanted to be sure about onetimetask. i am using db-scheduler to schedule multiple tasks when an external 3 requests is coming at the same time to run in multiple pods lets say, 3. when i create 3 beans with different name for scheduling it works fine but is there any functionality to create a Task at runtime dynamically i.e, applicationName-1, applicationName-2, applicationName-3. this would be helpful if i increase the number of pods in near future.

@Value("${spring.application.name}") private String springAppName;

public void triggerOneTime(MyTaskData myClassData) { OneTimeTask myAdhocTask = Tasks.oneTime(springAppName+myClassData.getShard(), MyTaskData.class) // +myClassData.getShard() value can be 1, 2, 3 etc.. .execute((inst, ctx) -> { System.out.println("Executed! Custom data, Id: " + inst.getData().id); });

    final Scheduler scheduler = Scheduler
            .create(dataSource, myAdhocTask)
            .registerShutdownHook()
            .build();

    scheduler.start();
} 

Current Behavior

For this case i think multiple scheduler is getting created which is running the same name task in 2 different pods at the same time which is repeating the process.


For bug reports

YOU MAY DELETE THE For bug reports SECTION IF A NEW FEATURE REQUEST.

Steps to Reproduce the bug

1. 1. 1.

Context

Logs