Skip to content

Commit

Permalink
add: example send_welcome_sms_task.go
Browse files Browse the repository at this point in the history
  • Loading branch information
abbasfisal committed Dec 20, 2024
1 parent 071a4f4 commit 0242ea8
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions internal/modules/public/jobs/send_welcome_sms_task.go
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
}

0 comments on commit 0242ea8

Please sign in to comment.