go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/cron/job.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package cron
     9  
    10  import (
    11  	"context"
    12  )
    13  
    14  // Job is an interface types can satisfy to be loaded into the JobManager.
    15  type Job interface {
    16  	Name() string
    17  	Execute(context.Context) error
    18  }
    19  
    20  // ScheduleProvider is a type that provides a schedule for the job.
    21  // If a job does not implement this method, it is treated as
    22  // "OnDemand" or a job that must be triggered explicitly.
    23  type ScheduleProvider interface {
    24  	Schedule() Schedule
    25  }
    26  
    27  // ConfigProvider is a type that returns a job config.
    28  type ConfigProvider interface {
    29  	Config() JobConfig
    30  }
    31  
    32  // LifecycleProvider is a job that provides lifecycle hooks.
    33  type LifecycleProvider interface {
    34  	Lifecycle() JobLifecycle
    35  }
    36  
    37  // BackgroundProvider is a type that returns a base context based on a parent context.
    38  type BackgroundProvider interface {
    39  	Background(context.Context) context.Context
    40  }