Create a scheduler as a first-class core module feature, following the same pattern used for the Asynq queue system. The new core/scheduler/ subpackage contains QueueItem and ProcessedItem GORM models (tables queue_items and processed_items), a Store for database operations (enqueue, claim batch with SELECT FOR UPDATE SKIP LOCKED, result recording, stuck recovery), a Semaphore kill switch, and the polling Scheduler loop with configurable interval and rate limit. The core/scheduler.go wrapper exposes a Schedulermux struct (analogous to Queuemux) with SchedulerInit(), AddWork(), SetStore(), and RunScheduler() methods, plus global accessors ResolveSchedulerStore() and SchedulerSemaphoreSetGreen/Red/IsGreen() so controllers can enqueue work and control the semaphore without importing the subpackage directly.
This commit is contained in:
parent
b757aef6b1
commit
3710fbe343
3 changed files with 547 additions and 0 deletions
|
|
@ -1,10 +1,13 @@
|
|||
// Copyright 2021 Harran Ali <harran.m@gmail.com>. All rights reserved.
|
||||
// Copyright (c) 2024 Zeni Kim <zenik@smarteching.com>
|
||||
// Copyright (c) 2026 Jose Cely <me@jacs.guru>
|
||||
// Use of this source code is governed by MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package core
|
||||
|
||||
import "time"
|
||||
|
||||
type EnvFileConfig struct {
|
||||
UseDotEnvFile bool
|
||||
}
|
||||
|
|
@ -28,6 +31,12 @@ type QueueConfig struct {
|
|||
Queues map[string]int
|
||||
}
|
||||
|
||||
type SchedulerConfig struct {
|
||||
EnableScheduler bool
|
||||
SchedulerInterval time.Duration
|
||||
SchedulerRateLimit int
|
||||
}
|
||||
|
||||
type CacheConfig struct {
|
||||
EnableCache bool
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue