Skip to content

CROSSLINK-288 Add batch action endpoints#607

Open
JanisSaldabols wants to merge 5 commits into
CROSSLINK-287from
CROSSLINK-288
Open

CROSSLINK-288 Add batch action endpoints#607
JanisSaldabols wants to merge 5 commits into
CROSSLINK-287from
CROSSLINK-288

Conversation

@JanisSaldabols
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_action table + SQLC queries/repo methods to persist batch actions alongside scheduled_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).

Comment thread broker/migrations/039_add_batch_action.up.sql
Comment thread broker/sqlc/sched_schema.sql Outdated
Comment thread broker/scheduler/api/api_handler.go
Comment thread broker/scheduler/service/scheduler.go Outdated
Comment thread broker/sqlc/skd_schema.sql Outdated
Comment thread broker/sqlc/skd_query.sql Outdated
Comment thread broker/go.mod Outdated
Comment thread broker/Makefile Outdated
Comment thread broker/oapi/open-api.yaml
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 8 comments.

Comment thread broker/scheduler/db/repo.go Outdated
Comment thread broker/scheduler/service/scheduler.go Outdated
Comment thread broker/scheduler/api/api_handler.go
Comment thread broker/go.mod
Comment thread broker/Makefile Outdated
Comment thread broker/events/eventmodels.go
Comment thread broker/sqlc/skd_schema.sql Outdated
Comment thread broker/sqlc/skd_query.sql Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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-empty batchQuery so 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-empty batchQuery to 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-empty batchQuery to 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)
}

Comment thread broker/scheduler/api/api_handler_test.go Outdated
Comment thread broker/scheduler/api/api_handler.go
Comment thread broker/migrations/039_add_batch_action.down.sql
Comment thread broker/sqlc/sched_schema.sql
Comment thread broker/scheduler/db/repo.go Outdated
Comment thread broker/app/app.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants