feat: request up to capacity jobs from Forgejo in one API call #1245

Merged
mfenniak merged 2 commits from mfenniak/forgejo-runner:fetchtask-mutliple into main 2025-12-28 20:49:09 +00:00
Owner

Permits the Runner to fetch multiple tasks from Forgejo in one API call, up to the configured capacity (minus any running jobs).

In the event that Forgejo doesn't support the TaskCapacity parameter (eg. current Forgejo), this implementation continues to perform FetchTask operations retrieving one task every configured FetchInterval, which is the same as the current behaviour. The implementation is changed so that this is done in a single goroutine rather than one goroutine per capacity, but the behaviour is the same -- the interval was implemented through a shared rate limiter before, and now only has a single goroutine waiting on the same rate limiter.

testing/synctest is used to create neat unit tests for the new behaviour. They look very fragile with millisecond precision waits, but are not due to synctest.

Related Forgejo PR: https://codeberg.org/forgejo/forgejo/pulls/10602

  • features
    • PR: feat: request up to capacity jobs from Forgejo in one API call
Permits the Runner to fetch multiple tasks from Forgejo in one API call, up to the configured capacity (minus any running jobs). In the event that Forgejo doesn't support the `TaskCapacity` parameter (eg. current Forgejo), this implementation continues to perform `FetchTask` operations retrieving one task every configured `FetchInterval`, which is the same as the current behaviour. The implementation is changed so that this is done in a single goroutine rather than one goroutine per capacity, but the behaviour is the same -- the interval was implemented through a shared rate limiter before, and now only has a single goroutine waiting on the same rate limiter. [`testing/synctest`](https://pkg.go.dev/testing/synctest) is used to create neat unit tests for the new behaviour. They look very fragile with millisecond precision waits, but are not due to synctest. Related Forgejo PR: https://codeberg.org/forgejo/forgejo/pulls/10602 <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - features - [PR](https://code.forgejo.org/forgejo/runner/pulls/1245): <!--number 1245 --><!--line 0 --><!--description ZmVhdDogcmVxdWVzdCB1cCB0byBgY2FwYWNpdHlgIGpvYnMgZnJvbSBGb3JnZWpvIGluIG9uZSBBUEkgY2FsbA==-->feat: request up to `capacity` jobs from Forgejo in one API call<!--description--> <!--end release-notes-assistant-->
@ -77,0 +93,4 @@
log.Tracef("[poller] successfully fetched %d tasks", len(tasks))
for _, task := range tasks {
inProgressTasks.Add(1)
wg.Add(1)
Owner

Suppose you could make use of wg.Do

Suppose you could make use of [`wg.Do`](https://pkg.go.dev/sync#WaitGroup.Go)
mfenniak marked this conversation as resolved
@ -77,0 +95,4 @@
inProgressTasks.Add(1)
wg.Add(1)
go func() {
p.runTaskWithRecover(p.jobsCtx, task)
Owner
https://go.dev/blog/loopvar-preview, you're lucky :)
Author
Owner

I am aware of this gotcha, but my awareness ends roughly around "it's fine to ignore this problem now". 🤣

I am aware of this gotcha, but my awareness ends roughly around "it's fine to ignore this problem now". 🤣
mfenniak marked this conversation as resolved
@ -77,1 +102,4 @@
}
}
}
Owner

Trace message that indicates shutdown initiated/handling, waiting until all tasks are complete? Given you added the other trace message.

Trace message that indicates shutdown initiated/handling, waiting until all tasks are complete? Given you added the other trace message.
Author
Owner

There's an info-level msg before the loop break indicating that shutdown began.

There's an info-level msg before the loop `break` indicating that shutdown began.
Gusted marked this conversation as resolved
mfenniak force-pushed fetchtask-mutliple from 80e135d23a
All checks were successful
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / validate pre-commit-hooks file (pull_request) Successful in 44s
checks / validate mocks (pull_request) Successful in 48s
checks / build and test (pull_request) Successful in 2m54s
checks / runner exec tests (pull_request) Successful in 25s
Integration tests for the release process / release-simulation (pull_request) Successful in 4m53s
checks / runner integration tests (pull_request) Successful in 6m32s
checks / integration tests (docker-latest) (pull_request) Successful in 10m11s
checks / integration tests (docker-stable) (pull_request) Successful in 12m17s
to 82bf866505
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 4s
checks / build and test (pull_request) Failing after 16s
checks / runner exec tests (pull_request) Has been skipped
checks / runner integration tests (pull_request) Has been skipped
checks / validate mocks (pull_request) Successful in 38s
checks / validate pre-commit-hooks file (pull_request) Successful in 38s
Integration tests for the release process / release-simulation (pull_request) Has been cancelled
checks / integration tests (docker-latest) (pull_request) Successful in 13m1s
checks / integration tests (docker-stable) (pull_request) Successful in 15m30s
2025-12-28 03:27:08 +00:00
Compare
mfenniak force-pushed fetchtask-mutliple from 82bf866505
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 4s
checks / build and test (pull_request) Failing after 16s
checks / runner exec tests (pull_request) Has been skipped
checks / runner integration tests (pull_request) Has been skipped
checks / validate mocks (pull_request) Successful in 38s
checks / validate pre-commit-hooks file (pull_request) Successful in 38s
Integration tests for the release process / release-simulation (pull_request) Has been cancelled
checks / integration tests (docker-latest) (pull_request) Successful in 13m1s
checks / integration tests (docker-stable) (pull_request) Successful in 15m30s
to 61134cdf09
All checks were successful
checks / validate mocks (pull_request) Successful in 36s
checks / validate pre-commit-hooks file (pull_request) Successful in 45s
checks / build and test (pull_request) Successful in 2m54s
checks / runner exec tests (pull_request) Successful in 47s
Integration tests for the release process / release-simulation (pull_request) Successful in 5m57s
checks / runner integration tests (pull_request) Successful in 8m33s
checks / integration tests (docker-latest) (pull_request) Successful in 13m44s
checks / integration tests (docker-stable) (pull_request) Successful in 15m47s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 4s
2025-12-28 03:29:21 +00:00
Compare
mfenniak force-pushed fetchtask-mutliple from 61134cdf09
All checks were successful
checks / validate mocks (pull_request) Successful in 36s
checks / validate pre-commit-hooks file (pull_request) Successful in 45s
checks / build and test (pull_request) Successful in 2m54s
checks / runner exec tests (pull_request) Successful in 47s
Integration tests for the release process / release-simulation (pull_request) Successful in 5m57s
checks / runner integration tests (pull_request) Successful in 8m33s
checks / integration tests (docker-latest) (pull_request) Successful in 13m44s
checks / integration tests (docker-stable) (pull_request) Successful in 15m47s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 4s
to ebfdf283a4
All checks were successful
checks / validate pre-commit-hooks file (pull_request) Successful in 1m19s
checks / validate mocks (pull_request) Successful in 1m33s
checks / build and test (pull_request) Successful in 3m41s
checks / runner exec tests (pull_request) Successful in 25s
Integration tests for the release process / release-simulation (pull_request) Successful in 5m21s
checks / runner integration tests (pull_request) Successful in 7m19s
checks / integration tests (docker-latest) (pull_request) Successful in 12m27s
checks / integration tests (docker-stable) (pull_request) Successful in 12m24s
issue-labels / release-notes (pull_request_target) Successful in 7s
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Successful in 12s
cascade / forgejo (pull_request_target) Successful in 46s
2025-12-28 15:50:20 +00:00
Compare
mfenniak changed title from WIP: feat: request up to capacity jobs from Forgejo in one API call to feat: request up to capacity jobs from Forgejo in one API call 2025-12-28 15:50:25 +00:00
Gusted approved these changes 2025-12-28 20:44:15 +00:00
mfenniak deleted branch fetchtask-mutliple 2025-12-28 20:49:09 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
forgejo/runner!1245
No description provided.