Skip to content

Commit

Permalink
fix json rest time
Browse files Browse the repository at this point in the history
  • Loading branch information
skyzh committed Jan 4, 2021
1 parent 39bbc46 commit 937d9fc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
3 changes: 3 additions & 0 deletions pkg/manager/.tmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"worker_info": {}
}
10 changes: 5 additions & 5 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ func NewManager(config *config.Config) (*Manager, error) {
if disabled, ok := repoConfig["disabled"].(bool); ok && disabled {
continue
}
w, err := worker.NewWorker(repoConfig)
if err != nil {
return nil, err
}
newManager.workers = append(newManager.workers, w)
name, _ := repoConfig["name"].(string)
if _, ok := newManager.workersLastInvokeTime[name]; !ok {
newManager.workersLastInvokeTime[name] = time.Now().AddDate(-1, 0, 0)
}
w, err := worker.NewWorker(repoConfig, newManager.workersLastInvokeTime[name])
if err != nil {
return nil, err
}
newManager.workers = append(newManager.workers, w)
}
return &newManager, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Status struct {
}

// NewWorker generates a worker by config and log.
func NewWorker(cfg config.RepoConfig) (Worker, error) {
func NewWorker(cfg config.RepoConfig, lastFinished time.Time) (Worker, error) {
if syncType, ok := cfg["type"]; ok {
switch syncType {
case "rsync":
Expand All @@ -45,7 +45,7 @@ func NewWorker(cfg config.RepoConfig) (Worker, error) {
newShellScriptExecutor(cfg),
Status{
Result: true,
LastFinished: time.Now().AddDate(-1, 0, 0),
LastFinished: lastFinished,
Idle: true,
Stdout: make([]string, 0),
Stderr: make([]string, 0),
Expand Down
11 changes: 6 additions & 5 deletions pkg/worker/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
"github.com/stretchr/testify/assert"

"errors"
"sync/atomic"

"github.com/sirupsen/logrus"
"github.com/sjtug/lug/pkg/config"
"sync/atomic"
)

func TestNewExternalWorker(t *testing.T) {
Expand All @@ -23,12 +24,12 @@ func TestNewExternalWorker(t *testing.T) {
"blahblah": "foobar",
"type": "external",
}
_, err := NewWorker(c)
_, err := NewWorker(c, time.Now())
// worker with no name is not allowed
asrt.NotNil(err)

c["name"] = "test_external"
w, err := NewWorker(c)
w, err := NewWorker(c, time.Now())
// config with name and dummy kv pairs should be allowed
asrt.Nil(err)

Expand All @@ -47,7 +48,7 @@ func TestNewShellScriptWorker(t *testing.T) {

asrt := assert.New(t)

w, _ := NewWorker(c)
w, _ := NewWorker(c, time.Now())

asrt.Equal(true, w.GetStatus().Result)
asrt.Equal("shell_script", w.GetConfig()["type"])
Expand Down Expand Up @@ -186,7 +187,7 @@ func TestShellScriptWorkerArgParse(t *testing.T) {
"name": "shell",
"script": "wc -l /proc/stat",
}
w, err := NewWorker(c)
w, err := NewWorker(c, time.Now())

asrt := assert.New(t)
asrt.Nil(err)
Expand Down

0 comments on commit 937d9fc

Please sign in to comment.