Skip to content

Commit

Permalink
Merge pull request #246 from crawlab-team/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
wo10378931 authored Oct 8, 2019
2 parents 2627dc4 + ffe69f3 commit 89c446e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
26 changes: 19 additions & 7 deletions backend/services/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"runtime/debug"
"strconv"
"sync"
"syscall"
"time"
)

Expand Down Expand Up @@ -142,7 +143,7 @@ func ExecuteShellCmd(cmdStr string, cwd string, t model.Task, s model.Spider) (e
log.Infof("cancel process signal: %s", signal)
if signal == constants.TaskCancel && cmd.Process != nil {
// 取消进程
if err := cmd.Process.Kill(); err != nil {
if err := syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL); err != nil {
log.Errorf("process kill error: %s", err.Error())
debug.PrintStack()
}
Expand All @@ -152,19 +153,24 @@ func ExecuteShellCmd(cmdStr string, cwd string, t model.Task, s model.Spider) (e
t.Status = constants.StatusFinished
}
t.FinishTs = time.Now()
t.Error = "user kill the process ..."
if err := t.Save(); err != nil {
log.Infof("save task error: %s", err.Error())
debug.PrintStack()
return
}
}()

// 在选择所有节点执行的时候,实际就是随机一个节点执行的,
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}

// 异步启动进程
if err := cmd.Start(); err != nil {
log.Errorf("start spider error:{}", err.Error())
debug.PrintStack()
return err
}

// 保存pid到task
t.Pid = cmd.Process.Pid
if err := t.Save(); err != nil {
Expand All @@ -176,12 +182,18 @@ func ExecuteShellCmd(cmdStr string, cwd string, t model.Task, s model.Spider) (e
if err := cmd.Wait(); err != nil {
log.Errorf("wait process finish error: %s", err.Error())
debug.PrintStack()

// 发生一次也需要保存
t.Error = err.Error()
t.FinishTs = time.Now()
t.Status = constants.StatusFinished
_ = t.Save()
if exitError, ok := err.(*exec.ExitError); ok {
exitCode := exitError.ExitCode()
log.Errorf("exit error, exit code: %d", exitCode)
// 非kill 的错误类型
if exitCode != -1 {
// 非手动kill保存为错误状态
t.Error = err.Error()
t.FinishTs = time.Now()
t.Status = constants.StatusError
_ = t.Save()
}
}
return err
}
ch <- constants.TaskFinish
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crawlab",
"version": "0.3.2",
"version": "0.3.4",
"private": true,
"scripts": {
"serve": "vue-cli-service serve --ip=0.0.0.0 --mode=development",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/layout/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</span>
<el-dropdown-menu slot="dropdown" class="user-dropdown">
<el-dropdown-item>
<span style="display:block;">v0.3.2</span>
<span style="display:block;">v0.3.4</span>
</el-dropdown-item>
<el-dropdown-item>
<span style="display:block;" @click="logout">{{$t('Logout')}}</span>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/spider/SpiderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<el-tab-pane v-if="isConfigurable" :label="$t('Config')" name="配置">
<config-list/>
</el-tab-pane>
<el-tab-pane v-if="isCustomized" :label="$t('Files')" name="files">
<el-tab-pane :label="$t('Files')" name="files">
<file-list/>
</el-tab-pane>
<el-tab-pane :label="$t('Environment')" name="environment">
Expand Down

0 comments on commit 89c446e

Please sign in to comment.