example01

package
v0.26.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// TypeSendEmail is wired to [asynq.Task.Type], [asynq.ServeMux.Handle] and [asynq.ServeMux.HandleFunc].
	TypeSendEmail = "example01:send_email"
	// TypeSendSMS is wired to [asynq.Task.Type], [asynq.ServeMux.Handle] and [asynq.ServeMux.HandleFunc].
	TypeSendSMS = "example01:send_sms_message"
)

Auto-generated constants for use with asynq.NewTask, asynq.ServeMux.Handle, and asynq.ServeMux.HandleFunc.

Variables

This section is empty.

Functions

func EnqueueSendEmail added in v0.26.10

func EnqueueSendEmail(client asynqClient, message *SendEmail, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendEmail pushes a SendEmail task to the queue.

Additional asynq.Option can be passed to override the options set by NewSendEmailTask.

This function is auto-generated.

func EnqueueSendEmailContext

func EnqueueSendEmailContext(ctx context.Context, client asynqClient, message *SendEmail, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendEmailContext pushes a SendEmail task to the queue.

Additional asynq.Option can be passed to override the options set by NewSendEmailTask.

This function is auto-generated.

Example
package main

import (
	"context"

	"github.com/hibiken/asynq"
	"github.com/luca-arch/asynq-codegen/examples/example01"
)

func main() {
	asynqRedisClientOpt := asynq.RedisClientOpt{Addr: "127.0.0.1:6379", DialTimeout: 1}

	client := asynq.NewClient(asynqRedisClientOpt)
	defer client.Close()

	example01.EnqueueSendEmailContext(context.Background(), client, &example01.SendEmail{
		Body: "Hello world",
		From: "sender@example.com",
		To:   "recipient@example.com",
	})

}

func EnqueueSendEmailContextWithHeaders added in v0.26.10

func EnqueueSendEmailContextWithHeaders(ctx context.Context, client asynqClient, message *SendEmail, headers map[string]string, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendEmailContextWithHeaders pushes a SendEmail task to the queue.

It supports task headers introduced with asynq 0.26.0.

Additional asynq.Option can be passed to override the options set by NewSendEmailTask.

This function is auto-generated.

func EnqueueSendEmailWithHeaders added in v0.26.10

func EnqueueSendEmailWithHeaders(client asynqClient, message *SendEmail, headers map[string]string, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendEmailWithHeaders pushes a SendEmail task to the queue.

It supports task headers introduced with asynq 0.26.0.

Additional asynq.Option can be passed to override the options set by NewSendEmailTask.

This function is auto-generated.

func EnqueueSendSMS added in v0.26.10

func EnqueueSendSMS(client asynqClient, message *SendSMS, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendSMS pushes a SendSMS task to the queue.

Additional asynq.Option can be passed to override the options set by NewSendSMSTask.

This function is auto-generated.

func EnqueueSendSMSContext

func EnqueueSendSMSContext(ctx context.Context, client asynqClient, message *SendSMS, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendSMSContext pushes a SendSMS task to the queue.

Additional asynq.Option can be passed to override the options set by NewSendSMSTask.

This function is auto-generated.

func EnqueueSendSMSContextWithHeaders added in v0.26.10

func EnqueueSendSMSContextWithHeaders(ctx context.Context, client asynqClient, message *SendSMS, headers map[string]string, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendSMSContextWithHeaders pushes a SendSMS task to the queue.

It supports task headers introduced with asynq 0.26.0.

Additional asynq.Option can be passed to override the options set by NewSendSMSTask.

This function is auto-generated.

func EnqueueSendSMSWithHeaders added in v0.26.10

func EnqueueSendSMSWithHeaders(client asynqClient, message *SendSMS, headers map[string]string, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendSMSWithHeaders pushes a SendSMS task to the queue.

It supports task headers introduced with asynq 0.26.0.

Additional asynq.Option can be passed to override the options set by NewSendSMSTask.

This function is auto-generated.

func NewSendEmailProcessor

func NewSendEmailProcessor(fn SendEmailProcessor) func(context.Context, *asynq.Task) error

NewSendEmailProcessor wraps a SendEmailProcessor function so that it can be passed to asynq.ServeMux.Handle and asynq.ServeMux.HandleFunc.

Notes about the returned function:

  • it will reject nil tasks and tasks of which the typename does not match TypeSendEmail.
  • it will return an error if a task's payload cannot be unmarshalled.
  • it will return any received error as-is, including asynq.SkipRetry and asynq.RevokeTask.

This function is auto-generated.

func NewSendEmailTask

func NewSendEmailTask(t *SendEmail) (*asynq.Task, error)

NewSendEmailTask calls NewSendEmailTaskWithHeaders with nil headers.

This function is auto-generated.

func NewSendEmailTaskWithHeaders added in v0.26.10

func NewSendEmailTaskWithHeaders(t *SendEmail, headers map[string]string) (*asynq.Task, error)

NewSendEmailTaskWithHeaders takes a SendEmail pointer and returns a new asynq.Task with its typename set to TypeSendEmail.

It calls asynq.NewTaskWithHeaders introduced with asynq 0.26.0.

It returns an error if the pointer is nil, or if it cannot be marshalled.

Task's options:

  • Max retries: 5
  • Retention: 24h0m0s
  • Timeout: 1m0s

This function is auto-generated.

func NewSendSMSProcessor

func NewSendSMSProcessor(fn SendSMSProcessor) func(context.Context, *asynq.Task) error

NewSendSMSProcessor wraps a SendSMSProcessor function so that it can be passed to asynq.ServeMux.Handle and asynq.ServeMux.HandleFunc.

Notes about the returned function:

  • it will reject nil tasks and tasks of which the typename does not match TypeSendSMS.
  • it will return an error if a task's payload cannot be unmarshalled.
  • it will return any received error as-is, including asynq.SkipRetry and asynq.RevokeTask.

This function is auto-generated.

func NewSendSMSTask

func NewSendSMSTask(t *SendSMS) (*asynq.Task, error)

NewSendSMSTask calls NewSendSMSTaskWithHeaders with nil headers.

This function is auto-generated.

func NewSendSMSTaskWithHeaders added in v0.26.10

func NewSendSMSTaskWithHeaders(t *SendSMS, headers map[string]string) (*asynq.Task, error)

NewSendSMSTaskWithHeaders takes a SendSMS pointer and returns a new asynq.Task with its typename set to TypeSendSMS.

It calls asynq.NewTaskWithHeaders introduced with asynq 0.26.0.

It returns an error if the pointer is nil, or if it cannot be marshalled.

Task's options:

  • Max retries: 5
  • Retention: 24h0m0s
  • Timeout: 1m0s

This function is auto-generated.

Types

type Dispatcher added in v0.26.10

type Dispatcher struct {
	Client asynqClient
}

Dispatcher defines methods to enqueue messages, using the already exported Enqueue* methods.

This type is auto-generated.

func (*Dispatcher) EnqueueSendEmail added in v0.26.10

func (d *Dispatcher) EnqueueSendEmail(message *SendEmail, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendEmail invokes EnqueueSendEmail.

This method is auto-generated.

func (*Dispatcher) EnqueueSendEmailContext added in v0.26.10

func (d *Dispatcher) EnqueueSendEmailContext(ctx context.Context, message *SendEmail, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendEmailContext invokes EnqueueSendEmailContext.

This method is auto-generated.

func (*Dispatcher) EnqueueSendEmailContextWithHeaders added in v0.26.10

func (d *Dispatcher) EnqueueSendEmailContextWithHeaders(ctx context.Context, message *SendEmail, headers map[string]string, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendEmailContextWithHeaders invokes EnqueueSendEmailContextWithHeaders.

This method is auto-generated.

func (*Dispatcher) EnqueueSendEmailWithHeaders added in v0.26.10

func (d *Dispatcher) EnqueueSendEmailWithHeaders(message *SendEmail, headers map[string]string, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendEmailWithHeaders invokes a EnqueueSendEmailWithHeaders.

This method is auto-generated.

func (*Dispatcher) EnqueueSendSMS added in v0.26.10

func (d *Dispatcher) EnqueueSendSMS(message *SendSMS, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendSMS invokes EnqueueSendSMS.

This method is auto-generated.

func (*Dispatcher) EnqueueSendSMSContext added in v0.26.10

func (d *Dispatcher) EnqueueSendSMSContext(ctx context.Context, message *SendSMS, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendSMSContext invokes EnqueueSendSMSContext.

This method is auto-generated.

func (*Dispatcher) EnqueueSendSMSContextWithHeaders added in v0.26.10

func (d *Dispatcher) EnqueueSendSMSContextWithHeaders(ctx context.Context, message *SendSMS, headers map[string]string, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendSMSContextWithHeaders invokes EnqueueSendSMSContextWithHeaders.

This method is auto-generated.

func (*Dispatcher) EnqueueSendSMSWithHeaders added in v0.26.10

func (d *Dispatcher) EnqueueSendSMSWithHeaders(message *SendSMS, headers map[string]string, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)

EnqueueSendSMSWithHeaders invokes a EnqueueSendSMSWithHeaders.

This method is auto-generated.

type Processors

type Processors struct {
	SendEmail SendEmailProcessor
	SendSMS   SendSMSProcessor
}

Processors defines methods to process messages by their type.

This type is auto-generated.

func (*Processors) Handle

func (p *Processors) Handle(mux asynqMux)

Handle register all non-nil handlers with asynq.ServeMux.HandleFunc.

This function is auto-generated.

func (*Processors) HandleAll

func (p *Processors) HandleAll(mux asynqMux) error

HandleAll register all handlers with asynq.ServeMux.HandleFunc. It returns an error if any handler is nil.

This function is auto-generated.

Example
package main

import (
	"context"

	"github.com/hibiken/asynq"
	"github.com/luca-arch/asynq-codegen/examples/example01"
)

func main() {
	serveMux := asynq.NewServeMux()

	if err := (&example01.Processors{
		SendEmail: func(context.Context, *example01.SendEmail, map[string]string) error {
			return nil
		},
		SendSMS: func(context.Context, *example01.SendSMS, map[string]string) error {
			return nil
		},
	}).HandleAll(serveMux); err != nil {
		panic(err)
	}

}

func (*Processors) NewServeMux added in v0.26.10

func (p *Processors) NewServeMux(middlewares ...asynq.MiddlewareFunc) (*asynq.ServeMux, error)

NewServeMux wires up a new asynq.ServeMux with the provided middlewares and the Processors handlers.

This function is auto-generated.

func (*Processors) Run added in v0.26.10

func (p *Processors) Run(ctx context.Context, redisConnOpt asynq.RedisConnOpt, cfg asynq.Config, middlewares ...asynq.MiddlewareFunc) error

Run invokes Processors.NewServeMux, asynq.Server.Start, and returns any error encountered by either method. It then waits for the context to be done before stopping and shutting down the server.

Note the context passed to this method must be cancelled explicitly (e.g.: signal.NotifyContext, errgroup.WithContext, or testing.T.Context) for the method to return.

This function is auto-generated.

func (*Processors) RunWithRedisClient added in v0.26.12

func (p *Processors) RunWithRedisClient(ctx context.Context, client redis.UniversalClient, cfg asynq.Config, middlewares ...asynq.MiddlewareFunc) error

RunWithRedisClient invokes Processors.NewServeMux, asynq.Server.Start, and returns any error encountered by either method. It then waits for the context to be done before stopping and shutting down the server.

Note the context passed to this method must be cancelled explicitly (e.g.: signal.NotifyContext, errgroup.WithContext, or testing.T.Context) for the method to return.

Also, the redis.UniversalClient connection pool must be closed upstream, explicitly.

This function is auto-generated.

type SendEmail

type SendEmail struct {
	Body string `json:"body"`
	From string `json:"from"`
	To   string `json:"to"`
}

asynq:task

func NewSendEmailFromJSON

func NewSendEmailFromJSON(r io.Reader) (*SendEmail, error)

NewSendEmailFromJSON consumes a JSON input and returns a SendEmail. Any error returned by json.Unmarshal will be returned as-is.

This function is auto-generated.

func NewSendEmailFromJSONBytes

func NewSendEmailFromJSONBytes(b []byte) (*SendEmail, error)

NewSendEmailFromJSONBytes reads a JSON bytestream and returns a SendEmail.

Any error returned by json.Unmarshal will be returned as-is.

This function is auto-generated.

Example
package main

import (
	"fmt"

	"github.com/luca-arch/asynq-codegen/examples/example01"
)

func main() {
	task, err := example01.NewSendEmailFromJSONBytes([]byte(`
		{
			"body": "Hello world",
			"from": "sender@example.com",
			"to":   "recipient@example.com"
		}
	`))
	if err != nil {
		panic(err)
	}

	fmt.Printf("Message from %s: %s", task.From, task.Body)

}
Output:
Message from sender@example.com: Hello world

type SendEmailProcessor

type SendEmailProcessor = func(context.Context, *SendEmail, map[string]string) error

SendEmailProcessor describes a function that processes SendEmail.

This type is auto-generated.

type SendSMS

type SendSMS struct {
	Message   string `json:"message"`
	Recipient string `json:"recipient"`
}

asynq:task send_sms_message

func NewSendSMSFromJSON

func NewSendSMSFromJSON(r io.Reader) (*SendSMS, error)

NewSendSMSFromJSON consumes a JSON input and returns a SendSMS. Any error returned by json.Unmarshal will be returned as-is.

This function is auto-generated.

func NewSendSMSFromJSONBytes

func NewSendSMSFromJSONBytes(b []byte) (*SendSMS, error)

NewSendSMSFromJSONBytes reads a JSON bytestream and returns a SendSMS.

Any error returned by json.Unmarshal will be returned as-is.

This function is auto-generated.

type SendSMSProcessor

type SendSMSProcessor = func(context.Context, *SendSMS, map[string]string) error

SendSMSProcessor describes a function that processes SendSMS.

This type is auto-generated.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL