workflowRunId = $workflowRunId; $this->stepId = $stepId; $this->args = $args; $this->status = self::STATUS_RUNNING; if ($id) { $this->id = $id; } $now = new DateTimeImmutable(); $this->createdAt = $now; $this->errors = []; $this->data = []; } public function getId(): int { return $this->id; } public function getWorkflowRunId(): int { return $this->workflowRunId; } public function getStepId(): string { return $this->stepId; } public function getStatus(): string { return $this->status; } public function getArgs(): array { return $this->args; } public function getErrors(): array { return $this->errors; } public function getData(): array { return $this->data; } /** * @return DateTimeImmutable|null */ public function getCompletedAt() { return $this->completedAt; } /** * @param string $key * @param mixed $value * @return void */ public function setData(string $key, $value): void { $this->data[$key] = $value; } public function getCreatedAt(): DateTimeImmutable { return $this->createdAt; } public function toArray(): array { return [ 'workflow_run_id' => $this->workflowRunId, 'step_id' => $this->stepId, 'status' => $this->status, 'created_at' => $this->createdAt->format(DateTimeImmutable::W3C), 'completed_at' => $this->completedAt ? $this->completedAt->format(DateTimeImmutable::W3C) : null, 'args' => Json::encode($this->args), 'errors' => Json::encode($this->errors), 'data' => Json::encode($this->data), ]; } public function markCompletedSuccessfully(): void { $this->status = self::STATUS_COMPLETED; $this->completedAt = new DateTimeImmutable(); } public function markFailed(): void { $this->status = self::STATUS_FAILED; $this->completedAt = new DateTimeImmutable(); } public function addError(Throwable $error, string $userFacingMessage = ''): void { $error = [ 'message' => $error->getMessage(), 'errorClass' => get_class($error), 'userFacingMessage' => $userFacingMessage, 'code' => $error->getCode(), 'trace' => $error->getTrace(), ]; $this->errors[] = $error; } public static function fromArray(array $data): self { $workflowRunLog = new WorkflowRunLog((int)$data['workflow_run_id'], $data['step_id'], []); $workflowRunLog->id = (int)$data['id']; $workflowRunLog->status = $data['status']; $workflowRunLog->errors = Json::decode($data['errors']); $workflowRunLog->data = Json::decode($data['data']); $workflowRunLog->args = Json::decode($data['args']); $workflowRunLog->createdAt = new DateTimeImmutable($data['created_at']); if ($data['completed_at']) { $workflowRunLog->completedAt = new DateTimeImmutable($data['completed_at']); } return $workflowRunLog; } }