UpgradeDaily.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Carbon;
  5. use Illuminate\Support\Facades\Log;
  6. class UpgradeDaily extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'upgrade:daily';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '每天的任务';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return int
  33. */
  34. public function handle()
  35. {
  36. if (\App\Tools\Tools::isStop()) {
  37. return 0;
  38. }
  39. $env = config('app.env');
  40. Log::info('daily task start ', ['app.env' => $env]);
  41. $start = time();
  42. if (app()->isLocal() == false) {
  43. $this->call('message:webhook', [
  44. 'listener' => 'dingtalk',
  45. 'url' => 'dingtalk1',
  46. 'title' => "后台任务",
  47. 'message' => " wikipali: 每日统计后台任务开始执行。app.env=" . $env,
  48. ]);
  49. }
  50. Log::info('wikipali: 每日统计后台任务开始执行{app.env}', ['app.env' => $env]);
  51. $message = "wikipali: 每日统计后台任务执行完毕。" . $env;
  52. //更新单词首选意思
  53. $this->call('upgrade:dict.default.meaning');
  54. $time = time() - $start;
  55. $message .= "dict.default.meaning:{$time}; ";
  56. $currTime = time();
  57. Log::info('更新单词首选意思完毕' . $env);
  58. //社区术语表
  59. $this->call('upgrade:community.term', ['lang' => 'zh-Hans']);
  60. $time = time() - $currTime;
  61. $message .= "community.term:{$time}; ";
  62. $currTime = time();
  63. Log::info('社区术语表完毕 {app.env}', ['app.env' => $env]);
  64. # 导出离线数据
  65. $this->call('export:offline', ['format' => 'lzma', '--driver' => 'str']);
  66. $time = time() - $currTime;
  67. $message .= "export:offline:{$time}; ";
  68. Log::info('导出离线数据完毕{app.env}', ['app.env' => $env]);
  69. $time = time() - $start;
  70. $message .= "总时间:{$time}; ";
  71. if (app()->isLocal() === false) {
  72. $this->call('message:webhook', [
  73. 'listener' => 'dingtalk',
  74. 'url' => 'dingtalk1',
  75. 'title' => "后台任务",
  76. 'message' => $message . ' app.env=' . $env,
  77. ]);
  78. //发送dingding消息
  79. $this->call('message:webhookarticlenew', [
  80. 'host' => 'https://oapi.dingtalk.com/robot/send?access_token=34143dbec80a8fc09c1cb5897a5639ee3a9a32ecfe31835ad29bf7013bdb9fdf',
  81. 'type' => 'dingtalk',
  82. ]);
  83. //发送微信消息
  84. $this->call('message:webhookarticlenew', [
  85. 'host' => 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=25dbd74f-c89c-40e5-8cbc-48b1ef7710b8',
  86. 'type' => 'wechat',
  87. ]);
  88. }
  89. return 0;
  90. }
  91. }