-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50070e7
commit 071a4f4
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package jobs | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/hibiken/asynq" | ||
"log" | ||
) | ||
|
||
const TypeExample = "example:task" | ||
|
||
func TaskExample(data any) (*asynq.Task, error) { | ||
payload, err := json.Marshal(&data) | ||
if err != nil { | ||
fmt.Println(TypeExample, " | json marshal err:", err) | ||
return nil, err | ||
} | ||
|
||
// e.g. return asynq.NewTask(TypeExample, payload,asynq.Queue("low")) =>pass some opts | ||
return asynq.NewTask(TypeExample, payload), nil | ||
} | ||
|
||
func HandleExampleTask(ctx context.Context, t *asynq.Task) error { | ||
var data any | ||
err := json.Unmarshal(t.Payload(), &data) | ||
if err != nil { | ||
log.Println("unmarshal json got err:", err) | ||
return err | ||
} | ||
|
||
// implement business logic | ||
|
||
fmt.Println(TypeExample, " implement business logic ;)") | ||
|
||
//------------------------- | ||
|
||
return nil | ||
} |