Skip to content

Pass the $worker object to the Logger instance#79

Open
dd32 wants to merge 2 commits intohumanmade:masterfrom
dd32:add-worker-to-logger
Open

Pass the $worker object to the Logger instance#79
dd32 wants to merge 2 commits intohumanmade:masterfrom
dd32:add-worker-to-logger

Conversation

@dd32
Copy link
Copy Markdown
Contributor

@dd32 dd32 commented Apr 9, 2025

The Logger instance does not have access to the STDOUT or STDERR pipes of the worker by default.

This is achievable using something like this in older PHP versions, but this causes PHP Deprecated warnings in newer PHPs.

$runner->hooks->register( 'Runner.run_job.started', function( Worker $worker, Job $job ) {
	$job->_worker = $worker;
} );

It would also be possible for the logger to not update it's datastore on log_job_failed()/log_job_completed() and instead to wait for the following hook Runner.check_workers.job_completed to be fired to then update it's data:

$runner->hooks->register( 'Runner.check_workers.job_completed', function( $worker, $job, $logger ) {
	$logger->completed( $job, $worker );
} );

class MyLogger extends Logger {
	public $message = '';

	public function log_job_completed( Job $job, $message = '' ) {
		$this->message = $message;
	}

	public function completed( Job $job, Worker $worker ) {
		$data = json_encode( array_filter(array(
			'message' => $this->message,
			'stdout'  => $worker->output,
			'stderr'  => $worker->error_output
		) ) );

		$this->log_run( $job->id, 'completed', $data );
	}
....

Be nice to just have everything accessible though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant