Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into crashLoopBackOff
Browse files Browse the repository at this point in the history
  • Loading branch information
jkmw committed Aug 9, 2023
2 parents 3aa8913 + 6c3b516 commit aa70ae4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
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 @@ -92,8 +92,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
}

0 comments on commit aa70ae4

Please sign in to comment.