Minor work on Task

This commit is contained in:
Deon George 2013-10-10 12:13:29 +11:00
parent 317cc331ae
commit ac4ad76886
2 changed files with 88 additions and 13 deletions

View File

@ -22,19 +22,18 @@ class Controller_Admin_Task extends Controller_Task {
public function action_log() { public function action_log() {
Block::factory() Block::factory()
->title(_('Task Log')) ->title(_('Task Log'))
->body(Table::display( ->title_icon('icon-th-list')
ORM::factory('Task_Log')->find_all(), ->body(Table::factory()
25, ->page_items(50)
array( ->data(ORM::factory('Task_Log')->find_all())
'id'=>array('label'=>'ID','url'=>URL::link('admin','task/view/')), ->columns(array(
'date_orig'=>array('label'=>'Date'), 'id'=>'ID',
'task->display("name")'=>array('label'=>'Task'), 'date_orig'=>'Date',
'result'=>array('label'=>'Result'), 'task->display("name")'=>'Task',
'message'=>array('label'=>'Message'), 'result'=>'Result',
), 'message'=>'Message',
array( ))
'page'=>TRUE, );
)));
} }
} }
?> ?>

View File

@ -0,0 +1,76 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* Delete old data from the TASK_LOG
*
* @package Task
* @category Tasks
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Task_Task_Clean extends Minion_Task {
// @todo This needs to be more dynamic, without hard coding task_ids or messages.
protected function _execute(array $params) {
$tl = ORM::factory('Task_Log');
$delay = 86400*2;
foreach ($tl->find_all() as $to) {
// Delete Task already running messages.
if (preg_match('/^Task\ [0-9]+\ is already running$/',$to->message) AND $to->date_orig < time()+$delay) {
$to->delete();
continue;
}
// Delete Empty Invoices Sent
if (preg_match('/^Invoices Sent:\s+$/',$to->message) AND $to->date_orig < time()+$delay) {
$to->delete();
continue;
}
// Delete Overdue Notes Sent
if (preg_match('/^OverDue Notice #[0-9] Reminders Sent:\s+$/',$to->message) AND $to->date_orig < time()+$delay) {
$to->delete();
continue;
}
// Over Notes Sent
if (preg_match('/^(Overdue|Due) Reminders Sent:\s+$/',$to->message) AND $to->date_orig < time()+$delay) {
$to->delete();
continue;
}
// Services Invoiced
if (preg_match('/^Services Invoiced:\s+$/',$to->message) AND $to->date_orig < time()+$delay) {
$to->delete();
continue;
}
if (in_array($to->task_id,array(2,4,13)) AND $to->date_orig < time()+$delay) {
$to->delete();
continue;
}
if (in_array($to->task_id,array(3)) AND $to->date_orig < time()+86400*60) {
$to->delete();
continue;
}
// Errors
if ((preg_match('/ErrorException\s+/',$to->message)
OR preg_match('/^The requested URL\s+/',$to->message)
OR preg_match('/^Unable to find a route to match the URI:/',$to->message)
OR preg_match('/View_Exception\s+/',$to->message)
OR preg_match('/Kohana_Exception\s+/',$to->message))
AND $to->date_orig < time()+$delay) {
$to->delete();
continue;
}
continue;
print_r(array($to->object(),$to->display('date_orig')));die();
}
}
}
?>