Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2P定时任务-使用Shell指令执行任务问题 #94

Closed
CenBoMin opened this issue Jun 26, 2021 · 8 comments
Closed

V2P定时任务-使用Shell指令执行任务问题 #94

CenBoMin opened this issue Jun 26, 2021 · 8 comments

Comments

@CenBoMin
Copy link

由于最近某APP的验证机制,这几天该定时任务尝试使用Shell指令来执行node指令:

node /usr/local/app/script/JSFile/jd_joy_new.js

今天发现任务并没有执行完毕,而是在执行第三个账号就直接断开finished...上网搜索问题之后,猜想可能是使用指令执行没有进程守护,可能是导致任务直接跳出断开的原因...

由于学习相关知识可能需要花费挺长的时间,所以想直接请教怎么解决这个问题...

麻烦了,谢谢...

@elecV2
Copy link
Owner

elecV2 commented Jun 26, 2021

定时任务的 Shell 指令默认 timeout 为 60 秒。
目前的解决方法: 写一个 JS 使用 $exec 函数来运行脚本。比如:

$exec('node xxx.js', {
  cwd: 'script/JSFile', timeout: 0,
  cb(data, error){
    error ? console.error(error) : console.log(data)
  }
}

另外,原来的shell 指令也可以写为: node xxx.js -cwd script/JSFile
之后的版本可能会增加个 -timeout 的选项

@CenBoMin
Copy link
Author

@elecV2 谢谢,我现在去试试:)

@CenBoMin
Copy link
Author

CenBoMin commented Jun 27, 2021

参照了JS的文档https://github.com/elecV2/elecV2P-dei/blob/master/docs/04-JS.md
$exec(command, options = { cwd, env, timeout, cb, stdin })
想使用env的环境变量的部分但是返回node: not found,以下是代码的部分,不知道哪里出了问题?

$exec('node jd_bean_change.js', {
  cwd: 'script/JSFile',
  env: {
    JD_COOKIE: "pt_key=AAJg2GkOADDkLukj6LOzv4obUsasrg5lJHarO-fqQldyL13k-o0UiZqBWthvq5dPt0Yguvv6A;pt_pin=12345678_p;"
  },
  timeout: 0,
  cb(data, error){
    error ? console.error(error) : console.log(data)
  }
})

另外不知道env可不可以用$store来获取cookie值,如下这样:

$exec('node jd_bean_change.js', {
  cwd: 'script/JSFile',
  env: {
    JD_COOKIE: $store.get('CookiesJDV2P', 'string'),  
  },
  timeout: 0,
  cb(data, error){
    error ? console.error(error) : console.log(data)
  }
})

@elecV2
Copy link
Owner

elecV2 commented Jun 28, 2021

3.4.0 及之前的版本使用 env 会缺少默认的环境变量 path 等。
解决:

// @grant nodejs    (首行添加这句

$exec('node xxx.js', {
  env: {
    ...process.env,     // env 中添加这句,其他保持不变
    jc: '你的其他 env 变量'
  }
})

或者直接升级到 v3.4.1。

可以使用 $store

@CenBoMin
Copy link
Author

@elecV2 好的 我现在更新并修改试试,谢谢

@fanfan008
Copy link

大佬,新版的v2p增加node运行的timeout选项了吗?没找到,昨天运行了一下,还是6s结束啊

@EchoChan314
Copy link

大佬,新版的v2p增加node运行的timeout选项了吗?没找到,昨天运行了一下,还是6s结束啊

这样,node https://raw.githubusercontent.com/***.js -timeout=0

@fanfan008
Copy link

大佬,新版的v2p增加node运行的timeout选项了吗?没找到,昨天运行了一下,还是6s结束啊

这样,node https://raw.githubusercontent.com/***.js -timeout=0

非常感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants