2022-02-08 05:58:22 -08:00
|
|
|
package tasks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2024-06-22 07:34:26 -07:00
|
|
|
"github.com/mikestefanello/pagoda/pkg/log"
|
|
|
|
"github.com/mikestefanello/pagoda/pkg/services"
|
2022-02-08 05:58:22 -08:00
|
|
|
)
|
|
|
|
|
2024-06-22 07:34:26 -07:00
|
|
|
// ExampleTask is an example implementation of services.Task
|
|
|
|
// This represents the task that can be queued for execution via the task client and should contain everything
|
|
|
|
// that your queue subscriber needs to process the task.
|
|
|
|
type ExampleTask struct {
|
|
|
|
Message string
|
|
|
|
}
|
2022-02-08 05:58:22 -08:00
|
|
|
|
2024-06-22 07:34:26 -07:00
|
|
|
// Name satisfies the services.Task interface by proviing a unique name for this Task type
|
|
|
|
func (t ExampleTask) Name() string {
|
|
|
|
return "example_task"
|
2022-02-08 05:58:22 -08:00
|
|
|
}
|
|
|
|
|
2024-06-22 07:34:26 -07:00
|
|
|
// NewExampleTaskQueue provides a Queue that can process ExampleTask tasks
|
|
|
|
// The service container is provided so the subscriber can have access to the app dependencies.
|
|
|
|
// All queues must be registered in the Register() function.
|
|
|
|
// Whenever an ExampleTask is added to the task client, it will be queued and eventually sent here for execution.
|
|
|
|
func NewExampleTaskQueue(c *services.Container) services.Queue {
|
|
|
|
return services.NewQueue[ExampleTask](func(ctx context.Context, task ExampleTask) error {
|
|
|
|
log.Default().Info("Example task received",
|
|
|
|
"message", task.Message,
|
|
|
|
)
|
|
|
|
log.Default().Info("This can access the container for dependencies",
|
|
|
|
"echo", c.Web.Reverse("home"),
|
|
|
|
)
|
|
|
|
return nil
|
|
|
|
})
|
2022-02-08 05:58:22 -08:00
|
|
|
}
|