You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(scheduler): add cost-based admission and Job struct
Add a cost field to scheduler jobs so strategies declare resource weight
at submit time. The scheduler tracks total active cost against a
configurable budget (max-cost), providing a general mechanism to limit
total resource pressure from heavy background work.
Additionally, replace positional Submit parameters with a Job struct
that includes an explicit Clone bool, removing the isCloneJob string
matching. MaxCloneConcurrency is preserved as a direct, independent
admission check alongside cost.
Cost constants defined in the git strategy:
clone=4, snapshot=3, repack=2, fetch=1
Two independent admission checks in takeNextJob:
1. Cost budget: activeCost + job.Cost <= maxCost
2. Clone limit: Clone jobs capped at MaxCloneConcurrency
Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d4a57-1477-707c-bb89-5543fddff0e7
Copy file name to clipboardExpand all lines: internal/jobscheduler/jobs.go
+61-40Lines changed: 61 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -18,19 +18,23 @@ import (
18
18
typeConfigstruct {
19
19
Concurrencyint`hcl:"concurrency" help:"The maximum number of concurrent jobs to run (0 means number of cores)." default:"4"`
20
20
MaxCloneConcurrencyint`hcl:"max-clone-concurrency" help:"Maximum number of concurrent clone jobs. Remaining worker slots are reserved for fetch/repack/snapshot jobs. 0 means no limit." default:"0"`
21
+
MaxCostint`hcl:"max-cost" help:"Maximum total cost of concurrently running jobs. Each job declares its own cost at submission. 0 means Concurrency * 4." default:"0"`
21
22
SchedulerDBstring`hcl:"scheduler-db" help:"Path to the scheduler state database." default:"${CACHEW_STATE}/scheduler.db"`
22
23
}
23
24
24
-
typequeueJobstruct {
25
-
idstring
26
-
queuestring
27
-
runfunc(ctx context.Context) error
25
+
// Job describes a unit of work to submit to the scheduler.
26
+
typeJobstruct {
27
+
Queuestring
28
+
IDstring
29
+
Costint
30
+
Clonebool// Subject to MaxCloneConcurrency limits.
0 commit comments