Skip to content

Commit

Permalink
Merge pull request xlvector#15 from GapYearWanted/master
Browse files Browse the repository at this point in the history
add url in Cmd.Output;remove time sleep
  • Loading branch information
GapYearWanted committed May 31, 2016
2 parents 6d1a76c + 2f555ff commit d40ed88
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ type Output struct {
NeedParam string `json:"need_param"`
Id string `json:"id"`
Data string `json:"data"`
Url string `json:"url"`
}
15 changes: 13 additions & 2 deletions task/task_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
hproxy "github.com/xlvector/higgs/proxy"
"github.com/xlvector/higgs/util"
"io/ioutil"
"math/rand"
_"math/rand"
"net/url"
"os"
"runtime/debug"
Expand All @@ -33,6 +33,7 @@ type TaskCmd struct {
userId string
passWord string
path string
url string
message chan *cmd.Output
input chan map[string]string
args map[string]string
Expand Down Expand Up @@ -143,6 +144,7 @@ func (s *TaskCmdFactory) createCommandWithPrivateKey(params url.Values, task *Ta
RedisHost: config.Instance.Redis.Host,
RedisTimeout: time.Duration(config.Instance.Redis.Timeout),
}, s.proxyManager)
dlog.Println(ret.downloader.Client)

dlog.Warn("output folder: %s", ret.downloader.OutputFolder)
ret.downloader.Context.Set("_id", ret.GetId())
Expand Down Expand Up @@ -283,7 +285,7 @@ func (p *TaskCmd) run() {
}

step := p.task.Steps[c]
time.Sleep(time.Duration(rand.Int63n(300)) * time.Millisecond)
//time.Sleep(time.Duration(rand.Int63n(300)) * time.Millisecond)

if len(step.NeedParam) > 0 {
tks := strings.Split(step.NeedParam, ",")
Expand All @@ -296,6 +298,9 @@ func (p *TaskCmd) run() {
val = util.DecodePassword(val, p.privateKey)
}
p.downloader.Context.Set(tk, val)
} else {
url,_ := p.downloader.Context.Get(tk)
p.url = url.(string)
}
}
}
Expand Down Expand Up @@ -324,6 +329,7 @@ func (p *TaskCmd) run() {
Status: cmd.WRONG_RESPONSE,
Id: p.GetArgsValue("id"),
Data: p.downloader.Context.Parse(step.Message["data"]),
Url: p.url,
}

p.message <- msg
Expand All @@ -340,6 +346,7 @@ func (p *TaskCmd) run() {
Status: cmd.TMPL_BLOCK,
Id: p.GetArgsValue("id"),
Data: data,
Url: p.url,
}
dlog.Println(data)
p.message <- msg
Expand All @@ -353,6 +360,7 @@ func (p *TaskCmd) run() {
Status: step.Message["status"],
Id: p.GetArgsValue("id"),
Data: data,
Url: p.url,
}

if needParam, ok := step.Message["need_param"]; ok {
Expand All @@ -377,6 +385,7 @@ func (p *TaskCmd) run() {
Id: p.GetArgsValue("id"),
NeedParam: action.Message["need_param"],
Data: actionInfo,
Url: p.url,
}

p.message <- msg
Expand Down Expand Up @@ -405,6 +414,7 @@ func (p *TaskCmd) run() {
Status: cmd.FAIL,
Id: p.GetArgsValue("id"),
Data: actionInfo,
Url: p.url,
}
p.message <- msg
dlog.Warn("%s Status:%s", p.GetId(), "retry fail "+step.Page)
Expand Down Expand Up @@ -450,6 +460,7 @@ func (p *TaskCmd) run() {
Status: cmd.FINISH_FETCH_DATA,
Id: p.GetArgsValue("id"),
Data: p.downloader.ExtractorResultString(),
Url: p.url,
}

p.message <- message
Expand Down

0 comments on commit d40ed88

Please sign in to comment.