Go - NewSchedule()

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

import (
"fmt"
"github.com/nitrictech/go-sdk/faas"
"github.com/nitrictech/go-sdk/nitric"
)
func main() {
nitric.NewSchedule("aggregate-data").Every("3 days", func(ctx *faas.EventContext, _ faas.EventHandler) (*faas.EventContext, error) {
fmt.Println("aggregating data")
return ctx, nil
})
nitric.Run()
}

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/faas"
"github.com/nitrictech/go-sdk/nitric"
)
func main() {
nitric.NewSchedule("send-reminder").Every("1 day", func(ctx *faas.EventContext, _ faas.EventHandler) (*faas.EventContext, error) {
fmt.Println("sending data")
return ctx, nil
})
nitric.NewSchedule("archive-data").Cron("0 1 1 * *", func (ctx *faas.EventContext, _ faas.EventHandler) (*faas.EventContext, error) {
fmt.Println("archiving data")
return ctx, nil
})
nitric.Run()
}
Last updated on Mar 24, 2025