mirror of
https://github.com/versia-pub/versia-go.git
synced 2026-03-13 12:39:15 +01:00
refactor: workers
This commit is contained in:
parent
02ad720439
commit
8fa44e5f72
20 changed files with 764 additions and 465 deletions
19
internal/utils/tasks.go
Normal file
19
internal/utils/tasks.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/versia-pub/versia-go/pkg/taskqueue"
|
||||
)
|
||||
|
||||
func ParseTask[T any](handler func(context.Context, T) error) func(context.Context, taskqueue.Task) error {
|
||||
return func(ctx context.Context, task taskqueue.Task) error {
|
||||
var data T
|
||||
if err := json.Unmarshal(task.Payload, &data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return handler(ctx, data)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue