CROSSLINK-288 Add batch action endpoints#607
Open
JanisSaldabols wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds “batch action” scheduling support to the broker by introducing a new batch_action persistence model and exposing CRUD-style HTTP endpoints (OpenAPI + handler wiring) to create/list/get/delete scheduled batch actions per tenant/owner.
Changes:
- Add
batch_actiontable + SQLC queries/repo methods to persist batch actions alongsidescheduled_task. - Introduce scheduler API endpoints (
/batch_actions,/batch_actions/{id}) with handler implementation and unit tests. - Extend OpenAPI generation and server wiring to expose the new scheduler API under both direct and Okapi-prefixed routing.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| broker/sqlc/skd_schema.sql | Adds a duplicate scheduled_task schema (appears unused vs sqlc.yaml). |
| broker/sqlc/skd_query.sql | Adds a duplicate scheduled_task query set (appears unused vs sqlc.yaml). |
| broker/sqlc/sched_schema.sql | Extends SQLC scheduler schema with new batch_action table. |
| broker/sqlc/sched_query.sql | Adds SQLC queries for batch actions plus GetScheduledTaskById. |
| broker/scheduler/service/scheduler.go | Exports cron helper as NextCronTime and updates internal call sites. |
| broker/scheduler/service/scheduler_test.go | Updates tests and mock to accommodate repo/interface changes and exported cron helper. |
| broker/scheduler/db/repo.go | Extends scheduler repo interface + Pg implementation with batch action methods. |
| broker/scheduler/api/api_handler.go | New HTTP handler implementing batch action endpoints. |
| broker/scheduler/api/api_handler_test.go | Unit tests for the new scheduler batch action handler behavior. |
| broker/oapi/sched-cfg.yaml | New oapi-codegen config to generate only scheduler-api tagged endpoints/models. |
| broker/oapi/open-api.yaml | Adds batch action schemas + /batch_actions paths. |
| broker/oapi/cfg.yaml | Excludes scheduler-api tag from the main oapi package generation. |
| broker/migrations/039_add_batch_action.up.sql | Migration creating batch_action table, index, and send-email event_config entry. |
| broker/migrations/039_add_batch_action.down.sql | Down migration dropping batch_action and removing send-email event_config entry. |
| broker/Makefile | Adds scheduler OpenAPI codegen target and includes it in generate/build/clean. |
| broker/go.mod | Adds cron dependency entry (currently marked indirect). |
| broker/events/eventmodels.go | Adds send-email event name and new BatchActionData payload structure. |
| broker/descriptors/ModuleDescriptor-template.json | Adds module permissions + routing entries for batch action endpoints. |
| broker/app/app.go | Wires the new scheduler API handler into mux routing (including Okapi base path). |
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.
Comments suppressed due to low confidence (3)
broker/scheduler/api/api_handler_test.go:246
- This test is intended to validate invalid cron handling, but the request body omits required
batchQuery, so the handler will fail earlier with "batchQuery must not be empty" instead of reaching cron parsing. Include a non-emptybatchQueryso the test asserts the intended behavior.
func TestPostBatchActions_InvalidCronExpression(t *testing.T) {
h := newHandler(new(MockSchedRepo))
req := newReq(http.MethodPost, `{"actionName":"email","schedule":"not-a-cron"}`)
rr := httptest.NewRecorder()
h.PostBatchActions(rr, req, schedoapi.PostBatchActionsParams{Symbol: symPtr(testSymbol)})
assert.Equal(t, http.StatusBadRequest, rr.Code)
}
broker/scheduler/api/api_handler_test.go:259
- This test aims to cover the SaveScheduledTask error path, but the request body omits required
batchQuery, so the handler returns 400 before calling the repo. Add a non-emptybatchQueryto the JSON body so the repository error path is actually exercised.
func TestPostBatchActions_SaveScheduledTaskError(t *testing.T) {
repo := new(MockSchedRepo)
repo.On("SaveScheduledTask", mock.Anything).Return(sched_db.ScheduledTask{}, errors.New("db error"))
h := newHandler(repo)
body := `{"actionName":"email","schedule":"` + validCron + `"}`
req := newReq(http.MethodPost, body)
rr := httptest.NewRecorder()
h.PostBatchActions(rr, req, schedoapi.PostBatchActionsParams{Symbol: symPtr(testSymbol)})
assert.Equal(t, http.StatusInternalServerError, rr.Code)
repo.AssertExpectations(t)
broker/scheduler/api/api_handler_test.go:275
- This test aims to cover the SaveBatchAction error path, but the request body omits required
batchQuery, so the handler returns 400 before calling the repo. Add a non-emptybatchQueryto the JSON body so the SaveBatchAction error path is reached.
func TestPostBatchActions_SaveBatchActionError(t *testing.T) {
repo := new(MockSchedRepo)
repo.On("SaveScheduledTask", mock.Anything).Return(scheduledTaskFixture("task-1"), nil)
repo.On("SaveBatchAction", mock.Anything).Return(sched_db.BatchAction{}, errors.New("db error"))
h := newHandler(repo)
body := `{"actionName":"email","schedule":"` + validCron + `"}`
req := newReq(http.MethodPost, body)
rr := httptest.NewRecorder()
h.PostBatchActions(rr, req, schedoapi.PostBatchActionsParams{Symbol: symPtr(testSymbol)})
assert.Equal(t, http.StatusInternalServerError, rr.Code)
repo.AssertExpectations(t)
}
adamdickmeiss
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.