go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/cron/job_lifecycle.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 "context"
    11  
    12  // JobLifecycle is a suite of lifeycle hooks
    13  // you can set for a given job.
    14  type JobLifecycle struct {
    15  	// OnRegister is called when the job is loaded into the job manager.
    16  	OnRegister func(context.Context) error
    17  	// OnRemove is called when the job is removed from the manager
    18  	// or the job manager is stopped.
    19  	OnRemove func(context.Context) error
    20  	// OnBegin fires whenever a job is started.
    21  	OnBegin func(context.Context)
    22  	// OnComplete fires whenever a job finishes, regardless of status.
    23  	OnComplete func(context.Context)
    24  	// OnCancellation is called if the job is canceled explicitly
    25  	// or it sets a timeout in the .Config() and exceeds that timeout.
    26  	OnCancellation func(context.Context)
    27  	// OnError is called if the job returns an error or panics during
    28  	// execution, but will not be called if the job is canceled.
    29  	OnError func(context.Context)
    30  	// OnSuccess is called if the job completes without an error.
    31  	OnSuccess func(context.Context)
    32  	// OnBroken is called if the job errors after having completed successfully
    33  	// the previous invocation.
    34  	OnBroken func(context.Context)
    35  	// OnFixed is called if the job completes successfully after having
    36  	// returned an error on the previous invocation.
    37  	OnFixed func(context.Context)
    38  	// OnEnabled is called if the job is explicitly enabled.
    39  	OnEnabled func(context.Context)
    40  	// OnDisabled is called if the job is explicitly disabled.
    41  	OnDisabled func(context.Context)
    42  }