Skip to content
Open
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
19 changes: 12 additions & 7 deletions pkg/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import (
"io"
"os"
"os/exec"
"runtime"
"sync"
"time"

"github.com/adhocore/gronx"
"github.com/rs/zerolog"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
"gopkg.in/yaml.v3"
)

Expand All @@ -37,8 +40,8 @@ type JobSpec struct {
Cron string `yaml:"cron,omitempty" json:"cron,omitempty"`
Command stringArray `yaml:"command" json:"command"`

OnSuccess OnEvent `yaml:"on_success,omitempty" json:"on_success,omitempty"`
OnError OnEvent `yaml:"on_error,omitempty" json:"on_error,omitempty"`
OnSuccess OnEvent `yaml:"on_success,omitempty" json:"on_success,omitempty"`
OnError OnEvent `yaml:"on_error,omitempty" json:"on_error,omitempty"`
OnRetriesExhausted OnEvent `yaml:"on_retries_exhausted,omitempty" json:"on_retries_exhausted,omitempty"`

Name string `json:"name"`
Expand All @@ -64,8 +67,8 @@ func (secret) MarshalText() ([]byte, error) {

// JobRun holds information about a job execution.
type JobRun struct {
LogEntryId int `json:"id,omitempty" db:"id"`
Status *int `json:"status,omitempty" db:"status,omitempty"`
LogEntryId int `json:"id,omitempty" db:"id"`
Status *int `json:"status,omitempty" db:"status,omitempty"`
logBuf bytes.Buffer
Log string `json:"log" db:"message"`
Name string `json:"name" db:"job"`
Expand Down Expand Up @@ -208,7 +211,6 @@ func (j *JobSpec) execCommandWithRetry(ctx context.Context, trigger string, pare
return jr
}


func (j *JobSpec) now() time.Time {
// defer for if schedule doesn't exist, allows for easy testing
if j.globalSchedule != nil {
Expand Down Expand Up @@ -253,7 +255,11 @@ func (j *JobSpec) execCommand(ctx context.Context, jr JobRun, trigger string) Jo
case true:
w = &jr.logBuf
default:
w = io.MultiWriter(os.Stdout, &jr.logBuf)
if runtime.GOOS == "windows" {
w = transform.NewWriter(io.MultiWriter(os.Stdout, &jr.logBuf), simplifiedchinese.GB18030.NewDecoder().Transformer)
} else {
w = io.MultiWriter(os.Stdout, &jr.logBuf)
}
}

// Merge stdout and stderr to same writer
Expand Down Expand Up @@ -319,7 +325,6 @@ func (j *JobSpec) execCommand(ctx context.Context, jr JobRun, trigger string) Jo
return jr
}


func (j *JobSpec) loadLogFromDb(id int) (JobRun, error) {
var jr JobRun
if j.cfg.DB == nil {
Expand Down