Jump to content

Log when tasks were run (even if they were successful)


TSP

Recommended Posts

I'm trying to investigate frequent downtime periods that happens fairly daily, but still not with a clear interval between each time. 

In doing that I'm trying to now look over whether any of the tasks cause this. The problem I have with that is that there are no log entries for when each task has actually been executed, so I can't see if any of the previous execution times for tasks corresponds to the times our servers tend to go down. 

Link to comment
Share on other sites

And you should log how long time the task spent. 

I've added some custom code to log this myself now in system/Task/Task.php

	public function runAndLog()
	{
		# HW_CUSTOM log task runnings
		\IPS\Log::i( LOG_NOTICE )->write( "Start to run task {$this->id}($this->key)", 'taskRunLog' );
		$start = microtime( true );
		$result = NULL;
		$error = FALSE;
		
		try
		{
			$result = $this->run();
		}
		catch ( \IPS\Task\Exception $e )
		{
			$result = $e->getMessage();
			$error  = 1;
		}
		$end_time = round( microtime( true ) - $start, 5 );
		\IPS\Log::i( LOG_NOTICE )->write( "Task {$this->id}($this->key) was finished in {$end_time} seconds", 'taskRunLog' );
		
		if ( $error !== FALSE or $result !== NULL )
		{
			\IPS\Db::i()->insert( 'core_tasks_log', array(
				'task'	=> $this->id,
				'error'	=> $error,
				'log'	=> json_encode( $result ),
				'time'	=> time()
			) );
		}
	}

But I feel you should log this information to the database table. 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...