Skip to content

[Draft] Added Scheduling DB module#668

Draft
GoodforGod wants to merge 5 commits into
masterfrom
feature/scheduling-db-module
Draft

[Draft] Added Scheduling DB module#668
GoodforGod wants to merge 5 commits into
masterfrom
feature/scheduling-db-module

Conversation

@GoodforGod

@GoodforGod GoodforGod commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Added Scheduling DB module

Merge after #667

@GoodforGod GoodforGod added this to the v2.0.0 milestone Jun 13, 2026
@GoodforGod GoodforGod added new module Feature where new module is added module: scheduling Related to Scheduling module labels Jun 13, 2026
@github-actions

github-actions Bot commented Jun 13, 2026

Copy link
Copy Markdown

Test Results

138 tests   138 ✅  8m 4s ⏱️
  5 suites    0 💤
  5 files      0 ❌

Results for commit 34da7ae.

♻️ This comment has been updated with latest results.

var threads = Math.max(1, resolvedJobs.size());

var scheduler = Scheduler.create(this.dataSource, tasks)
.threads(threads)

@strelchm strelchm Jun 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сейчас не конфигурируется параметр режима работы планировщика, используется по умолчанию FETCH (основанный на оптимистических блокировках).

  • В случае PostgreSql пропускная способность в дефолтном режиме значительно ниже (и больше количество выборок обновлений => bloat). Лучше использовать LOCK_AND_FETCH (основанный на SKIP LOCKED, правда не во всех СУБД он поддерживается). Можно добавить конфигурирование параметра через Scheduler.pollUsingLockAndFetch).

startupTasks.add(startupTask);
}
}
var threads = Math.max(1, resolvedJobs.size());

@strelchm strelchm Jun 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Возможно, конфигурация пользователем количества потоков позволит оптимально утилизировать пул планировщика. Сейчас количество потоков зависит, в том числе, от RunOnceJob, что при большом количестве таких джобов может создать большое количество потоков в fixed thread pool (которые будут простаивать).


@Override
@Nullable
public RecurringTask<?> startupTask() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: возможно:

    @Override
    public boolean isStartupTask() {
          return SHOULD_BE_STARTED.test(task());
     }

по аналогии с тем, как фильтруются джобы в самой либе

.pollingInterval(this.config.pollingInterval())
.shutdownMaxWait(this.config.shutdownWait())
.tableName(this.config.tableName())
.startTasks(startupTasks)

@strelchm strelchm Jun 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Есть предположение, что не стартанет шедуллер, если задавать одну и ту же задачу как дважды (в конструкторе и .startTasks). Когда я делаю тест:

  @Test
  public void onstartup_should_always_commit() {
    final TestTasks.CountingHandler<Void> counter = new TestTasks.CountingHandler<>();
    final RecurringTask<Void> recurring1 =
        Tasks.recurring("recurring1", new FutureSchedule()).execute(counter);

    // Setup non auto-committing datasource
    Scheduler scheduler =
        Scheduler.create(noAutocommitingDatasource, recurring1)
            .startTasks(recurring1)
            .schedulerName(new SchedulerName.Fixed("test"))
            .commitWhenAutocommitDisabled(false)
            .build();
    stopScheduler.register(scheduler);

    scheduler.start();

    final Optional<ScheduledExecution<Object>> scheduledExecution =
        scheduler.getScheduledExecution(recurring1.getDefaultTaskInstance());
    assertThat(scheduledExecution, not(empty()));
  }

возникает ошибка:

java.lang.IllegalStateException: Duplicate key recurring1 (attempted merging values RecurringTask name=recurring1, onComplete=OnCompleteReschedule with com.github.kagkarlsson.scheduler.compatibility.NoAutocommitTest$FutureSchedule@4defd42 and RecurringTask name=recurring1, onComplete=OnCompleteReschedule with com.github.kagkarlsson.scheduler.compatibility.NoAutocommitTest$FutureSchedule@4defd42)

	at java.base/java.util.stream.Collectors.duplicateKeyException(Collectors.java:135)
	at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$1(Collectors.java:182)
	at java.base/java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at com.github.kagkarlsson.scheduler.TaskResolver.<init>(TaskResolver.java:45)
	at com.github.kagkarlsson.scheduler.SchedulerBuilder.build(SchedulerBuilder.java:250)
	at com.github.kagkarlsson.scheduler.compatibility.NoAutocommitTest.onstartup_should_always_commit(NoAutocommitTest.java:81)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

Именно по этому в либе разделяют startup и не-startup джобы (здесь и здесь).

@GoodforGod GoodforGod marked this pull request as draft June 30, 2026 19:27
@GoodforGod GoodforGod changed the title Added Scheduling DB module [Draft] Added Scheduling DB module Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: scheduling Related to Scheduling module new module Feature where new module is added

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants