Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyk93 committed Nov 9, 2020
1 parent 5efc92f commit cc6473f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
6 changes: 3 additions & 3 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func LoadArgsMain() (unit Unit, ok bool, err error) {
unit = Unit{
Name: "arg-main",
Group: DefaultGroup,
Kind: "daemon",
Kind: KindDaemon,
ExecuteOptions: ExecuteOptions{
Command: args,
},
Expand All @@ -106,9 +106,9 @@ func LoadEnvMain() (unit Unit, ok bool, err error) {
if group == "" {
group = DefaultGroup
}
kind := "daemon"
kind := KindDaemon
if once, _ := strconv.ParseBool(strings.TrimSpace(os.Getenv("MINIT_MAIN_ONCE"))); once {
kind = "once"
kind = KindOnce
return
}
var command []string
Expand Down
10 changes: 5 additions & 5 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ type RunnerFactory struct {

var (
RunnerFactories = map[string]*RunnerFactory{
"render": {
KindRender: {
Level: RunnerL1,
Create: func(unit Unit, logger *mlog.Logger) (Runner, error) {
return NewRenderRunner(unit, logger)
},
},
"once": {
KindOnce: {
Level: RunnerL2,
Create: func(unit Unit, logger *mlog.Logger) (Runner, error) {
return NewOnceRunner(unit, logger)
},
},
"daemon": {
KindDaemon: {
Level: RunnerL3,
Create: func(unit Unit, logger *mlog.Logger) (Runner, error) {
return NewDaemonRunner(unit, logger)
},
},
"cron": {
KindCron: {
Level: RunnerL3,
Create: func(unit Unit, logger *mlog.Logger) (Runner, error) {
return NewCronRunner(unit, logger)
},
},
"logrotate": {
KindLogrotate: {
Level: RunnerL3,
Create: func(unit Unit, logger *mlog.Logger) (Runner, error) {
return NewLogrotateRunner(unit, logger)
Expand Down
2 changes: 2 additions & 0 deletions runner_cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/robfig/cron/v3"
)

const KindCron = "cron"

type CronRunner struct {
Unit
logger *mlog.Logger
Expand Down
2 changes: 2 additions & 0 deletions runner_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"time"
)

const KindDaemon = "daemon"

type DaemonRunner struct {
Unit
logger *mlog.Logger
Expand Down
2 changes: 2 additions & 0 deletions runner_logrotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"time"
)

const KindLogrotate = "logrotate"

// filename mark
// daily: FILENAME.ROT2020-06-02.EXT
// filesize: FILENAME.ROT000000000001.EXT (%012d)
Expand Down
2 changes: 2 additions & 0 deletions runner_once.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/acicn/minit/pkg/mlog"
)

const KindOnce = "once"

type OnceRunner struct {
Unit
logger *mlog.Logger
Expand Down
2 changes: 2 additions & 0 deletions runner_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"text/template"
)

const KindRender = "render"

type RenderRunner struct {
Unit
logger *mlog.Logger
Expand Down

0 comments on commit cc6473f

Please sign in to comment.