github.com/mattermost/mattermost-plugin-api@v0.1.4/cluster/job_example_test.go (about)

     1  package cluster
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/mattermost/mattermost-server/v6/plugin"
     7  )
     8  
     9  func ExampleSchedule() {
    10  	// Use p.API from your plugin instead.
    11  	pluginAPI := plugin.API(nil)
    12  
    13  	callback := func() {
    14  		// periodic work to do
    15  	}
    16  
    17  	job, err := Schedule(pluginAPI, "key", MakeWaitForInterval(5*time.Minute), callback)
    18  	if err != nil {
    19  		panic("failed to schedule job")
    20  	}
    21  
    22  	// main thread
    23  
    24  	defer job.Close()
    25  }