1
0
Fork 0
mirror of synced 2024-10-01 01:37:56 +13:00

Finish log streaming

This commit is contained in:
Matej Bačo 2023-06-14 10:57:30 +02:00
parent 6604a33e46
commit c933f8b4c2
2 changed files with 28 additions and 36 deletions

View file

@ -1141,9 +1141,13 @@ App::delete('/v1/functions/:functionId/deployments/:deploymentId')
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND);
}
if ($deviceFunctions->delete($deployment->getAttribute('path', ''))) {
if (!$dbForProject->deleteDocument('deployments', $deployment->getId())) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove deployment from DB');
if (!$dbForProject->deleteDocument('deployments', $deployment->getId())) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove deployment from DB');
}
if (!empty($deployment->getAttribute('path', ''))) {
if (!($deviceFunctions->delete($deployment->getAttribute('path', '')))) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove deployment from storage');
}
}

View file

@ -275,26 +275,38 @@ class BuildsV1 extends Worker
$response = null;
Co\run(function () use ($project, $deployment, &$response, $source, $function, $runtime, $vars, $command, &$build, $dbForProject) {
Co\run(function () use ($project, $deployment, &$response, $source, $function, $runtime, $vars, $command, &$build, $dbForProject, $allEvents) {
Co::join([
Co\go(function () use ($project, $deployment, &$response, &$build, $dbForProject) {
\var_dump("Start 1");
Co\go(function () use ($project, $deployment, &$response, &$build, $dbForProject, $allEvents) {
$this->executor->getLogs(
projectId: $project->getId(),
deploymentId: $deployment->getId(),
callback: function ($logs) use (&$response, &$build, $dbForProject) {
\var_dump("Callback");
if($response === null) {
callback: function ($logs) use (&$response, &$build, $dbForProject, $allEvents, $project) {
if ($response === null) {
$build = $build->setAttribute('stdout', $build->getAttribute('stdout', '') . $logs);
$build = $dbForProject->updateDocument('builds', $build->getId(), $build);
\var_dump("Writing" . $logs);
/**
* Send realtime Event
*/
$target = Realtime::fromPayload(
// Pass first, most verbose event pattern
event: $allEvents[0],
payload: $build,
project: $project
);
Realtime::send(
projectId: 'console',
payload: $build->getArrayCopy(),
events: $allEvents,
channels: $target['channels'],
roles: $target['roles']
);
}
}
);
\var_dump("End 1");
}),
Co\go(function () use (&$response, $project, $deployment, $source, $function, $runtime, $vars, $command) {
\var_dump("Start 2");
$response = $this->executor->createRuntime(
projectId: $project->getId(),
deploymentId: $deployment->getId(),
@ -307,31 +319,7 @@ class BuildsV1 extends Worker
variables: $vars,
command: 'tar -zxf /tmp/code.tar.gz -C /mnt/code && helpers/build.sh "' . $command . '"'
);
\var_dump("End 2");
}),
Co\go(function () {
\var_dump("Start 3");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://matejbaco2.loca.lt/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$headers = array();
$headers[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($ch);
\var_dump($output);
curl_close($ch);
\var_dump("End 3");
})
]);
});