Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not restart stopped/failed jobs if maxAttempts is reached #65

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/proc/basejob.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
)

var (
_ Job = &CommonJob{}

ProcessWillBeRestartedError = errors.New("process will be restarted")
ProcessWillBeStoppedError = errors.New("process will be stopped")
)
Expand Down Expand Up @@ -67,6 +69,10 @@ func (job *baseJob) IsControllable() bool {
return job.Config.Controllable
}

func (job *baseJob) GetPhase() *JobPhase {
return &job.phase
}

func (job *baseJob) GetName() string {
return job.Config.Name
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/proc/job_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ func (job *CommonJob) Run(ctx context.Context, _ chan<- error) error {
l.Info("stop process")
job.phase.Set(JobPhaseReasonStopped)
return nil
default:
l.WithError(err).Error("job exited with error")
}

attempts++
Expand Down
5 changes: 5 additions & 0 deletions pkg/proc/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ func (r *Runner) addJobIfNotExists(job Job) {
}

func (r *Runner) startJob(job Job) {
phase := job.GetPhase()
if phase.Is(JobPhaseReasonStopped) || phase.Is(JobPhaseReasonFailed) {
return
}

job.Init()

r.waitGroup.Add(1)
Expand Down
8 changes: 3 additions & 5 deletions pkg/proc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type baseJob struct {
stdout *os.File
stderr *os.File
lastError error
phase JobPhase
}

type BootJob struct {
Expand All @@ -70,7 +71,6 @@ type CommonJob struct {
Config *config.JobConfig

watchingFiles map[string]time.Time
phase JobPhase
}

type CommonJobStatus struct {
Expand Down Expand Up @@ -98,6 +98,7 @@ type Job interface {
Run(context.Context, chan<- error) error
Watch()

GetPhase() *JobPhase
GetName() string
}

Expand All @@ -110,6 +111,7 @@ func newBaseJob(c *config.BaseJobConfig) (*baseJob, error) {
stdout: os.Stdout,
stderr: os.Stderr,
}
job.phase.Set(JobPhaseReasonAwaitingReadiness)
if len(c.Stdout) == 0 {
return job, nil
}
Expand Down Expand Up @@ -144,13 +146,9 @@ func NewCommonJob(c *config.JobConfig) (*CommonJob, error) {
return nil, err
}

phase := JobPhase{}
phase.Set(JobPhaseReasonAwaitingReadiness)

j := CommonJob{
baseJob: *job,
Config: c,
phase: phase,
}

return &j, nil
Expand Down
10 changes: 10 additions & 0 deletions pkg/proc/types_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@ type JobPhase struct {
}

func (p *JobPhase) Set(reason JobPhaseReason) {
if p == nil {
p = &JobPhase{}
}
if p.Reason == reason {
return
}

p.LastChange = time.Now()
p.Reason = reason
}

func (p *JobPhase) Is(reason JobPhaseReason) bool {
if p == nil {
return false
}
return p.Reason == reason
}
Loading