drupal的cron中的计划任务执行问题

时间:2021-01-24 08:02:02

I have module, called parser2, which does parsing from html pages. Everything works perfectly, except cron schedule. It just doesnt add my task to cron tasks, and in logs, i see there are 0 scheduled tasks, everytime cron runs. The next issue, if i manually start cron few times, after i'm getting white screen of death, and the only 1 thing that helps me, its delete parser2 tables from DB, and from system.table, and then run update.php. Here is the code that should be doing all this work, but i cant understand where is error here

我有一个名为parser2的模块,它从html页面进行解析。一切都很完美,除了cron schedule。它只是没有将我的任务添加到cron任务,并且在日志中,我看到每次cron运行时都有0个计划任务。下一个问题,如果我手动启动cron几次,在我得到白屏死机后,唯一有帮助我的东西,它从DB中删除parser2表,从system.table,然后运行update.php 。这是应该完成所有这些工作的代码,但我不明白这里的错误在哪里

 function parser_cron_queue_info() {
    $info = array();
    $info['get_parser_weather'] = array(
    'worker callback' => 'parser_weather',
    'time' => 10,      
  );
    $query = db_select('parser_jobs', 'pn')
    ->fields('pn', array('id','time_run_in_crone'))
    ->condition('run_in_crone', 1)
    ->execute();
    foreach ($query as $job){
        $info['get_parser_weather_'.$job->id] = array(
        'worker callback' => 'parser_weather',
        'time' => $job->time_run_in_crone,      
   };
  }
  return $info;
}


function parser_cron() {

  $query = db_select('parser_jobs', 'pn')
    ->fields('pn', array('id','time_run_in_crone'))
    ->condition('run_in_crone', 1)
    ->execute();
  foreach ($query as $job){
    $queue = DrupalQueue::get('get_parser_weather_'.$job->id);
    $queue->createItem($job->id);
  }


}

function  parser_weather($job_id){

    $job = parser_job_load($job_id);
   _parser_url_delete_all();
   _parser_url_add($job->start_url);
   while (_parser_url_get_not_parsed())
   {
      parser_parse2($job);
    };
}

1 个解决方案

#1


1  

Try getting the cron command the code is generating and then run it in you command line to make sure it is correct also double check if the user your script is running has permission to add new task.

尝试获取代码生成的cron命令,然后在命令行中运行它以确保它是正确的,同时仔细检查脚本运行的用户是否有权添加新任务。

#1


1  

Try getting the cron command the code is generating and then run it in you command line to make sure it is correct also double check if the user your script is running has permission to add new task.

尝试获取代码生成的cron命令,然后在命令行中运行它以确保它是正确的,同时仔细检查脚本运行的用户是否有权添加新任务。

相关文章