Go - NewSchedule()

Creates a new Schedule to run a function on a defined frequency.

import (
  "fmt"

  "github.com/nitrictech/go-sdk/handler"
  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  nitric.NewSchedule("aggregate-data").Every("3 days", func(ctx *handler.IntervalContext, _ handler.IntervalHandler) (*handler.IntervalContext, error) {
    fmt.Println("aggregating data")

    return ctx, nil
  })

  if err := nitric.Run(); err != nil {
    fmt.Println(err)
  }
}

Parameters

  • Name
    description
    Required
    Required
    Type
    string
    Description

    The unique name of this Schedule within the app. Subsequent calls to schedule with the same name will return the same object.

Notes

  • Schedules do not require access permissions to be specified.

  • During local development schedules can be triggered manually from the local development dashboard

Examples

Create a Schedule

import (
  "fmt"

  "github.com/nitrictech/go-sdk/handler"
  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  nitric.NewSchedule("send-reminder").Every("1 day", func(ctx *handler.IntervalContext, _ handler.IntervalHandler) (*handler.IntervalContext, error) {
    fmt.Println("sending data")

    return ctx, nil
  })

  nitric.NewSchedule("archive-data").Cron("0 1 1 * *", func (ctx *handler.IntervalContext, _ handler.IntervalHandler) (*handler.IntervalContext, error) {
    fmt.Println("archiving data")

    return ctx, nil
  })

  if err := nitric.Run(); err != nil {
    fmt.Println(err)
  }
}