Skip to content

Commit

Permalink
SourceFunctions are run in the Scheduler process so does not have its…
Browse files Browse the repository at this point in the history
… own set of environmental config variables (getenv(), $_ENV) like source processes do. We instead set a protected class variable $env that the SourceFunction can use.
  • Loading branch information
lucasnetau committed Jan 24, 2024
1 parent f4a2a60 commit d7982d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ public function setup_source_function(int|string $id): void
{
$config = $this->input_processes_config[$id];
$cmd = clone $config['cmd'];
$env = $config['env'];

$this->input_processes[$id] = $cmd;
/** Log any errors received. Wrapper will call exit after error */
Expand Down Expand Up @@ -342,8 +343,8 @@ public function setup_source_function(int|string $id): void
$this->shutdown();
}
});
$this->loop->futureTick(static function() use ($cmd) {
$cmd->start();
$this->loop->futureTick(static function() use ($cmd, $env) {
$cmd->start($env);
});
}

Expand Down
9 changes: 8 additions & 1 deletion src/Scheduler/SourceFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ abstract class SourceFunction implements LoggerAwareInterface, EventEmitterInter
protected bool $running = false;
protected LoopInterface $loop;

/** @var array The environment for this source function */
protected array $env;

public function __construct() {
$this->loop = Loop::get();
}

public function start(): void
/**
* @var null|array $env Set the environment for the source function or inherit if null
*/
public function start(null|array $env = null): void
{
$this->running = true;
$this->env = $env ?? getenv();
$this->functionStart();
}

Expand Down

0 comments on commit d7982d5

Please sign in to comment.