Skip to content

Commit

Permalink
Merge pull request #97 from ziqin/master
Browse files Browse the repository at this point in the history
Refine: remove outer `provider`s which shadow the embedded `provider`s provided by `emptyHook`
  • Loading branch information
z4yx committed Aug 2, 2019
2 parents 540eea8 + 30259da commit 3872c41
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 34 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ Pre-built binary for Linux x86_64 is available at [Github releases](https://gith
# Job Run Process
PreSyncing Syncing Success
+-----------+ +-----------+ +-------------+ +--------------+
| pre-job +--+->| job run +--->| post-exec +-+-->| post-success |
+-----------+ ^ +-----------+ +-------------+ | +--------------+
| |
| +-----------------+ | Failed
+------+ post-fail |<---------+
+-----------------+
PreSyncing Syncing Success
+-----------+ +----------+ +-----------+ +-------------+ +--------------+
| pre-job +--+->| pre-exec +--->| job run +--->| post-exec +-+-->| post-success |
+-----------+ ^ +----------+ +-----------+ +-------------+ | +--------------+
| |
| +-----------------+ | Failed
+----------------+ post-fail |<---------------+
+-----------------+
```


Expand Down
2 changes: 1 addition & 1 deletion manager/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestHTTPServer(t *testing.T) {
So(res[_errorKey], ShouldEqual, "invalid workerID "+invalidWorker)
})

Convey("flush disabled jobs", func(ctx C) {
Convey("flush disabled jobs", func(ctx C) {
req, err := http.NewRequest("DELETE", baseURL+"/jobs/disabled", nil)
So(err, ShouldBeNil)
clt := &http.Client{}
Expand Down
5 changes: 3 additions & 2 deletions worker/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

type cgroupHook struct {
emptyHook
provider mirrorProvider
basePath string
baseGroup string
created bool
Expand All @@ -36,7 +35,9 @@ func newCgroupHook(p mirrorProvider, basePath, baseGroup, subsystem, memLimit st
subsystem = "cpu"
}
return &cgroupHook{
provider: p,
emptyHook: emptyHook{
provider: p,
},
basePath: basePath,
baseGroup: baseGroup,
subsystem: subsystem,
Expand Down
17 changes: 9 additions & 8 deletions worker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (

type dockerHook struct {
emptyHook
provider mirrorProvider
image string
volumes []string
options []string
image string
volumes []string
options []string
}

func newDockerHook(p mirrorProvider, gCfg dockerConfig, mCfg mirrorConfig) *dockerHook {
Expand All @@ -23,10 +22,12 @@ func newDockerHook(p mirrorProvider, gCfg dockerConfig, mCfg mirrorConfig) *dock
options = append(options, mCfg.DockerOptions...)

return &dockerHook{
provider: p,
image: mCfg.DockerImage,
volumes: volumes,
options: options,
emptyHook: emptyHook{
provider: p,
},
image: mCfg.DockerImage,
volumes: volumes,
options: options,
}
}

Expand Down
6 changes: 4 additions & 2 deletions worker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ sleep 10
So(err, ShouldBeNil)

d := &dockerHook{
provider: provider,
image: "alpine",
emptyHook: emptyHook{
provider: provider,
},
image: "alpine",
volumes: []string{
fmt.Sprintf("%s:%s", cmdScript, "/bin/cmd.sh"),
},
Expand Down
9 changes: 5 additions & 4 deletions worker/exec_post_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const (

type execPostHook struct {
emptyHook
provider mirrorProvider

// exec on success or on failure
execOn uint8
Expand All @@ -37,9 +36,11 @@ func newExecPostHook(provider mirrorProvider, execOn uint8, command string) (*ex
}

return &execPostHook{
provider: provider,
execOn: execOn,
command: cmd,
emptyHook: emptyHook{
provider: provider,
},
execOn: execOn,
command: cmd,
}, nil
}

Expand Down
5 changes: 3 additions & 2 deletions worker/loglimit_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (

type logLimiter struct {
emptyHook
provider mirrorProvider
}

func newLogLimiter(provider mirrorProvider) *logLimiter {
return &logLimiter{
provider: provider,
emptyHook: emptyHook{
provider: provider,
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion worker/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ func newMirrorProvider(mirror mirrorConfig, cfg *Config) mirrorProvider {
retry: mirror.Retry,
}
p, err := newRsyncProvider(rc)
p.isMaster = isMaster
if err != nil {
panic(err)
}
p.isMaster = isMaster
provider = p
case provTwoStageRsync:
rc := twoStageRsyncConfig{
Expand Down
13 changes: 7 additions & 6 deletions worker/zfs_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (

type zfsHook struct {
emptyHook
provider mirrorProvider
zpool string
zpool string
}

func newZfsHook(provider mirrorProvider, zpool string) *zfsHook {
return &zfsHook{
provider: provider,
zpool: zpool,
emptyHook: emptyHook{
provider: provider,
},
zpool: zpool,
}
}

Expand All @@ -40,12 +41,12 @@ func (z *zfsHook) printHelpMessage() {
func (z *zfsHook) preJob() error {
workingDir := z.provider.WorkingDir()
if _, err := os.Stat(workingDir); os.IsNotExist(err) {
logger.Errorf("Directory %s doesn't exist", workingDir);
logger.Errorf("Directory %s doesn't exist", workingDir)
z.printHelpMessage()
return err
}
if err := sh.Command("mountpoint", "-q", workingDir).Run(); err != nil {
logger.Errorf("%s is not a mount point", workingDir);
logger.Errorf("%s is not a mount point", workingDir)
z.printHelpMessage()
return err
}
Expand Down

0 comments on commit 3872c41

Please sign in to comment.