Skip to content

Commit 7b5db6e

Browse files
committed
Wait for daprd shutdown
1 parent 6d984d9 commit 7b5db6e

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/index.php

+6
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,12 @@ function (\Dapr\Client\DaprClient $client) {
476476
];
477477
}
478478

479+
$client->shutdown(afterRequest: false);
480+
481+
while ($client->isDaprHealthy()) {
482+
error_log('waiting for daprd shutdown...');
483+
}
484+
479485
return new \Nyholm\Psr7\Response($has_failed ? 500 : 200, body: json_encode($test_results));
480486
}
481487
);

src/lib/Client/DaprClient.php

+7
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,13 @@ abstract public function isDaprHealthy(): bool;
451451
*/
452452
abstract public function getMetadata(): MetadataResponse|null;
453453

454+
/**
455+
* Shutdown the Daprd sidecar
456+
*
457+
* @param bool $afterRequest If true, schedules a php shutdown function, otherwise fires the request immediately.
458+
*/
459+
abstract public function shutdown(bool $afterRequest = true): void;
460+
454461
/**
455462
* @param string $token
456463
* @return null|array{dapr-api-token: string}

src/lib/Client/DaprHttpClient.php

+11
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,15 @@ public function getMetadata(): MetadataResponse|null
6666
return null;
6767
}
6868
}
69+
70+
public function shutdown(bool $afterRequest = true): void
71+
{
72+
$shutdown = fn() => $this->httpClient->post('/v1.0/shutdown');
73+
if ($afterRequest) {
74+
register_shutdown_function($shutdown);
75+
return;
76+
}
77+
78+
$shutdown();
79+
}
6980
}

0 commit comments

Comments
 (0)