push

package
v1.7.6 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Module(
	"push",
	fx.Decorate(func(log *zap.Logger) *zap.Logger {
		return log.Named("push")
	}),
	fx.Provide(
		func(cfg Config, lc fx.Lifecycle) (c client, err error) {
			if cfg.Mode == ModeFCM {
				c, err = fcm.New(cfg.ClientOptions)
			} else if cfg.Mode == ModeUpstream {
				c, err = upstream.New(cfg.ClientOptions)
			} else {
				return nil, errors.New("invalid push mode")
			}

			if err != nil {
				return nil, err
			}

			lc.Append(fx.Hook{
				OnStart: func(ctx context.Context) error {
					return c.Open(ctx)
				},
				OnStop: func(ctx context.Context) error {
					return c.Close(ctx)
				},
			})

			return c, nil
		},
	),
	fx.Provide(
		New,
	),
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Mode Mode

	ClientOptions map[string]string

	Debounce time.Duration
	Timeout  time.Duration
}

type Mode

type Mode string
const (
	ModeFCM      Mode = "fcm"
	ModeUpstream Mode = "upstream"
)

type Params

type Params struct {
	fx.In

	Config Config

	Client client

	Logger *zap.Logger
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(params Params) *Service

func (*Service) Enqueue

func (s *Service) Enqueue(ctx context.Context, token string, data map[string]string) error

Enqueue adds the data to the cache and immediately sends all messages if the debounce is 0.

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run runs the service with the provided context if a debounce is set.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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