mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-10 11:49:03 +00:00
fix(m2-pr-d): thread ctx through Job/Notification/Audit services
Collapse CancelJobWithContext into CancelJob; eliminate 10 context.Background()
hits across the Job+Notification+Audit service cluster by threading ctx
through their handler-facing service interfaces.
Services (ctx-first):
- service/job.go: ListJobs, GetJob, CancelJob, ApproveJob, RejectJob now
accept ctx; the CancelJobWithContext wrapper is removed (handler callers
continue to invoke CancelJob, now ctx-aware).
- service/notification.go: ListNotifications, GetNotification, MarkAsRead
accept ctx.
- service/audit.go: ListAuditEvents, GetAuditEvent accept ctx.
Handlers (interface + callsites):
- handler/jobs.go, handler/notifications.go, handler/audit.go: local
service interfaces updated, r.Context() threaded at every callsite.
Tests:
- Mock services updated to match the new interfaces (ctx accepted and
ignored via '_ context.Context' first parameter; Fn closure fields
unchanged).
- job_test.go / notification_test.go callsites thread context.Background()
to match production shape.
Verification:
go build ./... ok
go vet ./... ok
go test -short ./... ok
go test -race -short ./... ok
golangci-lint run ./... 0 issues
Locked decisions from the M-2 plan:
D-1 ctx-only signatures (no dual forms)
D-4 preserve handler method names facing the router
D-5 domain types stay ctx-free
Audit complete. Commit: 1f6cf0eafa. Sections: 12. Findings: 2/7/10/4/6.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -21,35 +22,35 @@ type MockJobService struct {
|
||||
RejectJobFn func(id string, reason string) error
|
||||
}
|
||||
|
||||
func (m *MockJobService) ListJobs(status, jobType string, page, perPage int) ([]domain.Job, int64, error) {
|
||||
func (m *MockJobService) ListJobs(_ context.Context, status, jobType string, page, perPage int) ([]domain.Job, int64, error) {
|
||||
if m.ListJobsFn != nil {
|
||||
return m.ListJobsFn(status, jobType, page, perPage)
|
||||
}
|
||||
return nil, 0, nil
|
||||
}
|
||||
|
||||
func (m *MockJobService) GetJob(id string) (*domain.Job, error) {
|
||||
func (m *MockJobService) GetJob(_ context.Context, id string) (*domain.Job, error) {
|
||||
if m.GetJobFn != nil {
|
||||
return m.GetJobFn(id)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *MockJobService) CancelJob(id string) error {
|
||||
func (m *MockJobService) CancelJob(_ context.Context, id string) error {
|
||||
if m.CancelJobFn != nil {
|
||||
return m.CancelJobFn(id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockJobService) ApproveJob(id string) error {
|
||||
func (m *MockJobService) ApproveJob(_ context.Context, id string) error {
|
||||
if m.ApproveJobFn != nil {
|
||||
return m.ApproveJobFn(id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockJobService) RejectJob(id string, reason string) error {
|
||||
func (m *MockJobService) RejectJob(_ context.Context, id string, reason string) error {
|
||||
if m.RejectJobFn != nil {
|
||||
return m.RejectJobFn(id, reason)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user