-
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.
add: example send_welcome_sms_task.go
- Loading branch information
1 parent
071a4f4
commit 0242ea8
Showing
1 changed file
with
41 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,41 @@ | ||
package jobs | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/hibiken/asynq" | ||
"log" | ||
) | ||
|
||
//this is just and example | ||
|
||
const TypeSendWelcomeSMS = "user:welcome:sms" | ||
|
||
func TaskSendWelcomeSMS(data any) (*asynq.Task, error) { | ||
payload, err := json.Marshal(&data) | ||
if err != nil { | ||
fmt.Println(TypeSendWelcomeSMS, " | json marshal err:", err) | ||
return nil, err | ||
} | ||
|
||
// e.g. return asynq.NewTask(TypeSendWelcomeSMS, payload,asynq.Queue("low")) =>pass some opts | ||
return asynq.NewTask(TypeSendWelcomeSMS, payload), nil | ||
} | ||
|
||
func HandleTaskSendWelcomeSMS(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(TypeSendWelcomeSMS, " implement business logic ;)") | ||
|
||
//------------------------- | ||
|
||
return nil | ||
} |