Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Requires `innmind/io:~3.2`
- Requires `innmind/immutable:~5.15`
- `Innmind\OperatingSystem\Config::withHttpHeartbeat()` period is now expressed with a `Innmind\TimeContinuum\Period`
- `Innmind\OperatingSystem\CurrentProcess::halt()` now returns `Innmind\Immutable\Attempt<Innmind\Immutable\SideEffect>`

### Fixed

Expand Down
10 changes: 9 additions & 1 deletion src/CurrentProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
use Innmind\Server\Control\Server\Process\Pid;
use Innmind\Server\Status\Server\Memory\Bytes;
use Innmind\TimeContinuum\Period;
use Innmind\Immutable\{
Attempt,
SideEffect,
};

interface CurrentProcess
{
public function id(): Pid;
public function signals(): Signals;
public function halt(Period $period): void;

/**
* @return Attempt<SideEffect>
*/
public function halt(Period $period): Attempt;
public function memory(): Bytes;
}
5 changes: 3 additions & 2 deletions src/CurrentProcess/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Innmind\TimeContinuum\Period;
use Innmind\TimeWarp\Halt;
use Innmind\Signals\Handler;
use Innmind\Immutable\Attempt;

final class Generic implements CurrentProcess
{
Expand Down Expand Up @@ -45,9 +46,9 @@ public function signals(): Signals
}

#[\Override]
public function halt(Period $period): void
public function halt(Period $period): Attempt
{
($this->halt)($period);
return ($this->halt)($period);
}

#[\Override]
Expand Down
5 changes: 3 additions & 2 deletions src/CurrentProcess/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Innmind\Server\Control\Server\Process\Pid;
use Innmind\Server\Status\Server\Memory\Bytes;
use Innmind\TimeContinuum\Period;
use Innmind\Immutable\Attempt;
use Psr\Log\LoggerInterface;

final class Logger implements CurrentProcess
Expand Down Expand Up @@ -49,7 +50,7 @@ public function signals(): Signals
}

#[\Override]
public function halt(Period $period): void
public function halt(Period $period): Attempt
{
$this->logger->debug('Halting current process...', ['period' => [
'years' => $period->years(),
Expand All @@ -61,7 +62,7 @@ public function halt(Period $period): void
'milliseconds' => $period->milliseconds(),
]]);

$this->process->halt($period);
return $this->process->halt($period);
}

#[\Override]
Expand Down
5 changes: 1 addition & 4 deletions src/Remote/Resilient.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Innmind\Immutable\{
Maybe,
Attempt,
SideEffect,
};
use Formal\AccessLayer\Connection;

Expand Down Expand Up @@ -68,9 +67,7 @@ public function __construct(
#[\Override]
public function __invoke(Period $period): Attempt
{
$this->process->halt($period);

return Attempt::result(SideEffect::identity());
return $this->process->halt($period);
}
},
);
Expand Down
8 changes: 7 additions & 1 deletion tests/CurrentProcess/GenericTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Innmind\Server\Status\Server\Memory\Bytes;
use Innmind\TimeContinuum\Period;
use Innmind\TimeWarp\Halt;
use Innmind\Immutable\SideEffect;
use PHPUnit\Framework\TestCase;

class GenericTest extends TestCase
Expand All @@ -38,7 +39,12 @@ public function testHalt()
Halt\Usleep::new(),
);

$this->assertNull($process->halt(Period::millisecond(1)));
$this->assertInstanceOf(
SideEffect::class,
$process
->halt(Period::millisecond(1))
->unwrap(),
);
}

public function testSignals()
Expand Down
14 changes: 12 additions & 2 deletions tests/CurrentProcess/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
use Innmind\Server\Control\Server\Process\Pid;
use Innmind\Server\Status\Server\Memory\Bytes;
use Innmind\TimeContinuum\Period;
use Innmind\Immutable\{
Attempt,
SideEffect,
};
use Psr\Log\LoggerInterface;
use PHPUnit\Framework\TestCase;
use Innmind\BlackBox\{
Expand Down Expand Up @@ -74,15 +78,21 @@ public function testHalt()
$inner
->expects($this->once())
->method('halt')
->with($period);
->with($period)
->willReturn(Attempt::result(SideEffect::identity()));
$logger = $this->createMock(LoggerInterface::class);
$logger
->expects($this->once())
->method('debug')
->with('Halting current process...');
$process = Logger::psr($inner, $logger);

$this->assertNull($process->halt($period));
$this->assertInstanceOf(
SideEffect::class,
$process
->halt($period)
->unwrap(),
);
}

public function testMemory()
Expand Down