1
0
Fork 0
mirror of synced 2024-07-01 12:40:34 +12:00

docs: add comments to events passing

This commit is contained in:
Torsten Dittmann 2022-05-09 14:36:29 +02:00
parent a470201205
commit fdb64de616
5 changed files with 64 additions and 18 deletions

View file

@ -221,6 +221,7 @@ App::shutdown(function ($utopia, $request, $response, $project, $events, $audits
$bucket = ($trigger && $trigger->getCollection() === 'buckets') ? $trigger : null; $bucket = ($trigger && $trigger->getCollection() === 'buckets') ? $trigger : null;
$target = Realtime::fromPayload( $target = Realtime::fromPayload(
// Pass first, most verbose event pattern
event: $allEvents[0], event: $allEvents[0],
payload: $payload, payload: $payload,
project: $project, project: $project,

View file

@ -6,14 +6,15 @@ use Utopia\Audit\Audit;
use Utopia\CLI\Console; use Utopia\CLI\Console;
use Utopia\Database\Document; use Utopia\Database\Document;
require_once __DIR__.'/../init.php'; require_once __DIR__ . '/../init.php';
Console::title('Audits V1 Worker'); Console::title('Audits V1 Worker');
Console::success(APP_NAME . ' audits worker v1 has started'); Console::success(APP_NAME . ' audits worker v1 has started');
class AuditsV1 extends Worker class AuditsV1 extends Worker
{ {
public function getName(): string { public function getName(): string
{
return "audits"; return "audits";
} }
@ -36,16 +37,23 @@ class AuditsV1 extends Worker
$userName = $user->getAttribute('name', ''); $userName = $user->getAttribute('name', '');
$userEmail = $user->getAttribute('email', ''); $userEmail = $user->getAttribute('email', '');
$event = $events[0];
$dbForProject = $this->getProjectDB($project->getId()); $dbForProject = $this->getProjectDB($project->getId());
$audit = new Audit($dbForProject); $audit = new Audit($dbForProject);
$audit->log($user->getId(), $event, $resource, $userAgent, $ip, '', [ $audit->log(
'userName' => $userName, userId: $user->getId(),
'userEmail' => $userEmail, // Pass first, most verbose event pattern
'mode' => $mode, event: $events[0],
'data' => $payload, resource: $resource,
]); userAgent: $userAgent,
ip: $ip,
location: '',
data: [
'userName' => $userName,
'userEmail' => $userEmail,
'mode' => $mode,
'data' => $payload,
]
);
} }
public function shutdown(): void public function shutdown(): void

View file

@ -31,7 +31,8 @@ class BuildsV1 extends Worker
return "builds"; return "builds";
} }
public function init(): void { public function init(): void
{
$this->executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST')); $this->executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST'));
} }
@ -129,7 +130,13 @@ class BuildsV1 extends Worker
'functionId' => $function->getId(), 'functionId' => $function->getId(),
'deploymentId' => $deployment->getId() 'deploymentId' => $deployment->getId()
]); ]);
$target = Realtime::fromPayload($allEvents[0], $build, $project); $target = Realtime::fromPayload(
// Pass first, most verbose event pattern
event: $allEvents[0],
payload: $build,
project: $project
);
Realtime::send( Realtime::send(
projectId: 'console', projectId: 'console',
payload: $build->getArrayCopy(), payload: $build->getArrayCopy(),
@ -196,7 +203,12 @@ class BuildsV1 extends Worker
/** /**
* Send realtime Event * Send realtime Event
*/ */
$target = Realtime::fromPayload($allEvents[0], $build, $project); $target = Realtime::fromPayload(
// Pass first, most verbose event pattern
event: $allEvents[0],
payload: $build,
project: $project
);
Realtime::send( Realtime::send(
projectId: 'console', projectId: 'console',
payload: $build->getArrayCopy(), payload: $build->getArrayCopy(),

View file

@ -102,7 +102,12 @@ class DatabaseV1 extends Worker
Console::error($th->getMessage()); Console::error($th->getMessage());
$dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'failed')); $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'failed'));
} finally { } finally {
$target = Realtime::fromPayload($events[0], $attribute, $project); $target = Realtime::fromPayload(
// Pass first, most verbose event pattern
event: $events[0],
payload: $attribute,
project: $project
);
Realtime::send( Realtime::send(
projectId: 'console', projectId: 'console',
@ -154,7 +159,12 @@ class DatabaseV1 extends Worker
Console::error($th->getMessage()); Console::error($th->getMessage());
$dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'stuck')); $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'stuck'));
} finally { } finally {
$target = Realtime::fromPayload($events[0], $attribute, $project); $target = Realtime::fromPayload(
// Pass first, most verbose event pattern
event: $events[0],
payload: $attribute,
project: $project
);
Realtime::send( Realtime::send(
projectId: 'console', projectId: 'console',
@ -255,7 +265,12 @@ class DatabaseV1 extends Worker
Console::error($th->getMessage()); Console::error($th->getMessage());
$dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'failed')); $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'failed'));
} finally { } finally {
$target = Realtime::fromPayload($events[0], $index, $project); $target = Realtime::fromPayload(
// Pass first, most verbose event pattern
event: $events[0],
payload: $index,
project: $project
);
Realtime::send( Realtime::send(
projectId: 'console', projectId: 'console',
@ -300,7 +315,12 @@ class DatabaseV1 extends Worker
Console::error($th->getMessage()); Console::error($th->getMessage());
$dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'stuck')); $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'stuck'));
} finally { } finally {
$target = Realtime::fromPayload($events[0], $index, $project); $target = Realtime::fromPayload(
// Pass first, most verbose event pattern
event: $events[0],
payload: $index,
project: $project
);
Realtime::send( Realtime::send(
projectId: 'console', projectId: 'console',

View file

@ -75,6 +75,7 @@ class FunctionsV1 extends Worker
function: $function, function: $function,
dbForProject: $database, dbForProject: $database,
trigger: 'event', trigger: 'event',
// Pass first, most verbose event pattern
event: $events[0], event: $events[0],
eventData: $payload, eventData: $payload,
user: $user user: $user
@ -329,7 +330,11 @@ class FunctionsV1 extends Worker
'functionId' => $function->getId(), 'functionId' => $function->getId(),
'executionId' => $execution->getId() 'executionId' => $execution->getId()
]); ]);
$target = Realtime::fromPayload($allEvents[0], $execution); $target = Realtime::fromPayload(
// Pass first, most verbose event pattern
event: $allEvents[0],
payload: $execution
);
Realtime::send( Realtime::send(
projectId: 'console', projectId: 'console',
payload: $execution->getArrayCopy(), payload: $execution->getArrayCopy(),