crontab

package
v2.27.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MIT Imports: 4 Imported by: 0

README

Crontab

Example

package main

import (
	"context"

	"github.com/flc1125/go-cron/v4"
	"github.com/go-kratos-ecosystem/components/v2/crontab"
	"github.com/go-kratos/kratos/v2"
)

func main() {
	c := cron.New(
		cron.WithSeconds(),
		cron.WithMiddleware( /*...*/ ),
	)

	_, _ = c.AddFunc("* * * * * *", func(context.Context) error {
		// do something
		return nil
	})

	// kratos app start
	app := kratos.New(
		kratos.Server(
			crontab.NewServer(c),
		),
	)

	err := app.Run()
	if err != nil {
		panic(err)
	}
}

Documentation

Overview

Example
c := cron.New(
	cron.WithSeconds(),
	cron.WithMiddleware( /*...*/ ),
)

_, _ = c.AddFunc("* * * * * *", func(context.Context) error {
	// do something
	return nil
})

// kratos app start
app := kratos.New(
	kratos.Server(
		crontab.NewServer(c),
	),
)

err := app.Run()
if err != nil {
	panic(err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger added in v2.10.0

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

func NewLogger added in v2.10.0

func NewLogger(logger log.Logger) *Logger

func (*Logger) Printf added in v2.10.0

func (l *Logger) Printf(format string, v ...any)

type Server

type Server struct {
	*cron.Cron
}

func NewServer

func NewServer(c *cron.Cron) *Server

func (*Server) Start

func (s *Server) Start(context.Context) error

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Jump to

Keyboard shortcuts

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