Skip to content

Commit

Permalink
Allow actions to set their process title via the option action_name
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasnetau committed Dec 7, 2023
1 parent d0d51af commit 5ed220d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bin/save_state.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
use React\EventLoop\Loop;
use React\EventLoop\LoopInterface;

use function EdgeTelemetrics\EventCorrelation\disableOutputBuffering;

require_once __DIR__ . '/composer.php';

disableOutputBuffering();

$filename = getenv('SAVESTATE_FILENAME');
if ($filename === false) {
fwrite(STDERR, 'No filename configured for save state to be written to. Set environment variable SAVESTATE_FILENAME' . PHP_EOL);
Expand All @@ -24,7 +28,7 @@
public function __construct(protected string $saveFileName) {
$directory = dirname($this->saveFileName);

$this->processWrap = new ActionHelper(['json_buffer_size' => 10485760*2]);
$this->processWrap = new ActionHelper(['action_name' => 'checkpointer', 'json_buffer_size' => 10485760*2]);

$this->loop = Loop::get();

Expand All @@ -43,7 +47,6 @@ public function __construct(protected string $saveFileName) {
$this->returnError($request, "Save state sync failed." . json_encode(error_get_last()));
return;
}

$this->processWrap->write(new JsonRpcResponse($request->getId(), [
'saveStateBeginTime' => $request->getParam('time'),
'saveStateSizeBytes' => $saveStateSize,
Expand Down
5 changes: 5 additions & 0 deletions src/Library/Actions/ActionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public function __construct(array $options = []) {
disableOutputBuffering();
$this->loop = Loop::get();

if (function_exists('\cli_set_process_title')){
$myName = $options['action_name'] ?? 'action process';
@\cli_set_process_title($myName); //Silence it as macOS prior to certain PHP versions it does not work
}

//Drop the process into its own process group so that SIGINT isn't propagated when running under a shell
if (function_exists('\posix_setpgid')) {
\posix_setpgid(0,0);
Expand Down

0 comments on commit 5ed220d

Please sign in to comment.