2012-11-12 38 views
0

定時任務執行所以,我有下面的代碼cron作業:(PHP-Yii開發羣組)不停止

class UGCJReminder extends UGCronJob { 
/** 
* return the cron description 
*/ 
protected function getDescription() 
{ 
    return Yii::t('userGroupsModule.cron', 'manda email para os usuarios cadastrados para cadastrar suas atividades'); 
} 

/** 
* return the cron table model name 
*/ 
protected function getCronTable() 
{ 
    return 'UserGroupsCron'; 
} 

/** 
* return the cron name 
*/ 
protected function getName() 
{ 
    return 'reminder'; 
} 

/** 
* returns the number of days that have to pass before performing this cron job 
*/ 
protected function getLapse() 
{ 
    return 1; 
} 

/** 
* return the model 
*/ 
protected function getModel() 
{ 
    return new UserGroupsUser; 
} 

/** 
* return the action method 
*/ 
protected function getAction() 
{ 
     Yii::import('ext.yii-mail.YiiMailMessage'); 
     $message = new YiiMailMessage; 
     $message->setBody('Message', 'text/html'); 
     $message->subject = 'Lembrete'; 
     $message->addTo('my-email'); 
     $message->from = Yii::app()->params['adminEmail']; 
     return Yii::app()->mail->send($message); 
} 

/** 
* return the action criteria 
*/ 
protected function getCriteria() 
{ 
      return new CDbCriteria; 
} 

/** 
* return the interested database fields 
*/ 
protected function getColumns() 
{ 
     return array('email' => UserGroupsUser::ACTIVE); 
     #return NULL; 
} 
} 

我做的文檔該羣組中的所有其他變化(Yii的模塊)要求,和cron列表說我的cron已經安裝並正在運行。但是,它每天運行多次,每天只運行一次。那麼我做錯了什麼?

我還會接受針對此問題的另一個解決方案(每天在確定的時間發送電子郵件)。請考慮我正在使用Yii,並且因此想在框架內執行此操作(例如擴展名)

PS:如果您知道良好的文檔來源(因爲Usergroups,Cron-tab和Yii本身不是那麼強大的記錄如何所有這些工作)關於這一切,我仍然會對此感興趣

回答

0

我從來沒有使用過這個擴展。 但我看看源代碼,並在此片段注意:

https://github.com/nickcv/userGroups/blob/master/components/UGCron.php#L206

if ($cItem->last_occurrence <= date('Y-m-d', time() - (3600 * 24 * $cItem->lapse)).' 00:00:00') { 
    ... 
    $cItem->last_occurrence = date('Y-m-d').' 00:00:00';      
    $cItem->save(); 
} 

我想問你下一個問題:

  1. 是否if運營正常工作在你的案件?
  2. cron運行後$cItem->last_occurrence會更新嗎?
  3. 你使用什麼版本的PHP?
+0

由於cron作業在我點擊cron作業選項卡(在用戶組管理頁面上)後立即加載,我無法輸入這部分代碼來檢查。我懷疑這是有點因爲這個,但我結束了使用服務器crontab來做我所需要的。感謝你的回答 :) –