Cron.php 794 B

12345678910111213141516171819202122232425
  1. <?php namespace Manage\Api;
  2. use Dever;
  3. use Dever\Helper\Cmd;
  4. class Cron
  5. {
  6. public function run()
  7. {
  8. $time = time();
  9. # 获取所有的计划任务
  10. $data = Dever::db('cron', 'manage')->load(array('ldate' => array('<=', $time)));
  11. if ($data) {
  12. foreach ($data as $k => $v) {
  13. Cmd::run($v['interface'], array(), $v['project']);
  14. $param['ldate'] = $v['ldate'] + $v['time'];
  15. if ($param['ldate'] < $time) {
  16. $param['ldate'] = $time + $v['time'];
  17. }
  18. if ($v['time'] <= 0) {
  19. $param['state'] = 2;
  20. }
  21. Dever::db('cron', 'manage')->update($v['id'], $param);
  22. }
  23. }
  24. }
  25. }