Skip to content

Commit fcba1f7

Browse files
committed
Restart method for program resource
1 parent 8034b5a commit fcba1f7

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

examples/program-restart-async.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php declare(strict_types=1);
2+
3+
use ApiClients\Client\Supervisord\AsyncClient;
4+
use ApiClients\Client\Supervisord\Resource\Async\Program;
5+
use React\EventLoop\Factory;
6+
use function ApiClients\Foundation\resource_pretty_print;
7+
8+
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
9+
10+
$loop = Factory::create();
11+
$client = AsyncClient::create(require __DIR__ . DIRECTORY_SEPARATOR . 'resolve_host.php', $loop);
12+
13+
$client->programs()->take(1)->subscribe(function (Program $program) {
14+
resource_pretty_print($program);
15+
$program->restart()->done(function (Program $program) {
16+
resource_pretty_print($program);
17+
});
18+
}, function ($et) {
19+
echo (string)$et;
20+
});
21+
22+
$loop->run();

src/Resource/Async/Program.php

+9
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ public function disable(): PromiseInterface
3030
{
3131
return $this->handleCommand(new StopCommand($this->name));
3232
}
33+
34+
public function restart(): PromiseInterface
35+
{
36+
return $this->disable()->then(function () {
37+
return $this->enable();
38+
})->then(function () {
39+
return $this->refresh();
40+
});
41+
}
3342
}

0 commit comments

Comments
 (0)