-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.go
More file actions
25 lines (18 loc) · 1002 Bytes
/
handler.go
File metadata and controls
25 lines (18 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package pgqueue
import "context"
// JobHandler processes one-shot jobs. Implement RunTask with your business logic;
// the framework handles decoding, status updates, and retries.
type JobHandler[P any] interface {
RunTask(ctx context.Context, job *Job[P]) Result
}
// TickerHandler processes recurring ticker jobs. Implement RunTick with your
// business logic; the framework handles decoding, rescheduling, and state persistence.
type TickerHandler[P any] interface {
RunTick(ctx context.Context, job *Job[P]) Result
}
// JobHandlerFunc is a functional adapter for JobHandler.
type JobHandlerFunc[P any] func(ctx context.Context, job *Job[P]) Result
func (f JobHandlerFunc[P]) RunTask(ctx context.Context, job *Job[P]) Result { return f(ctx, job) }
// TickerHandlerFunc is a functional adapter for TickerHandler.
type TickerHandlerFunc[P any] func(ctx context.Context, job *Job[P]) Result
func (f TickerHandlerFunc[P]) RunTick(ctx context.Context, job *Job[P]) Result { return f(ctx, job) }