Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"php" : ">=7.3",
"ext-json" : "*",
"ext-curl" : "*",
"g4/runner" : ">=0.22.0",
"g4/runner" : ">=0.26.0",
"g4/utility" : "*",
"g4/value-object" : "*",
"g4/version" : "^0.0.2",
Expand Down
3 changes: 1 addition & 2 deletions src/Adapter/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public function save(array $data)
} catch (\Exception $exception) {
error_log ($exception->getMessage(), 0);
}

}


Expand Down Expand Up @@ -88,4 +87,4 @@ public function doRPushBatch(array $data)
$this->client->rPush((string) $this->key, ...$arguments);
}

}
}
13 changes: 12 additions & 1 deletion src/AdapterAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ public function appendData(array $data)
return $this;
}

public function clearData()
{
// clear all log data except keys _index and _type
foreach ($this->data as $key => $value) {
if (!in_array($key, ['_index', '_type'])) {
unset($this->data[$key]);
}
}
return $this;
}

public function beLazy()
{
$this->shouldBeLazy = true;
Expand All @@ -51,4 +62,4 @@ public function shouldSaveInOneCall()
{
return $this->shouldSaveInOneCall;
}
}
}
69 changes: 55 additions & 14 deletions src/Data/TaskerExecution.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class TaskerExecution extends LoggerAbstract
{
const LOG_TYPE = 'execution';
const CONTENT_LIMIT = 512;
const CONTENT_LIMIT = 30000;

/**
* @var \G4\Tasker\Model\Domain\Task
Expand All @@ -35,42 +35,78 @@ class TaskerExecution extends LoggerAbstract
*/
private $profiler;

private $taskFinished = false;

public function taskStarted()
{
$this->taskFinished = false;
}

public function taskFinished()
{
$this->taskFinished = true;
}

public function getRawData()
{
$rawData = [
$rawData = $this->taskFinished
? $this->getRawDataEnd()
: $this->getRawDataStart();
return $rawData;
}

private function getRawDataStart()
{
return [
'id' => $this->getId(),
'timestamp' => $this->getJsTimestamp(),
'hostname' => \gethostname(),
'pid' => \getmypid(),
'type' => $this->logType ?: self::LOG_TYPE,
'memory_peak_usage' => memory_get_peak_usage(),
'exception' => $this->exception === null ? null : \json_encode([
'message' => $this->exception->getMessage(),
'line' => $this->exception->getLine(),
'code' => $this->exception->getCode(),
'trace' => $this->exception->getTrace(),
]
),

'task_id' => $this->task->getTaskId(),
'recu_id' => $this->task->getRecurringId(),
'identifier' => $this->task->getIdentifier(),
'task' => $this->task->getTask(),
'data' => $this->task->getData(),
'output' => $this->getOutput(),
'request_uuid' => $this->task->getRequestUuid(),
'priority' => $this->task->getPriority(),
'status' => $this->task->getStatus(),
'ts_created' => $this->task->getTsCreated(),
'ts_started' => $this->task->getTsStarted(),
'exec_time' => $this->task->getExecTime(),
'exec_time_ms' => (int)($this->task->getExecTime() * 1000),
'started_count' => $this->task->getStartedCount(),
'php_version' => str_replace(PHP_EXTRA_VERSION, '', PHP_VERSION),
'app_version' => $this->getAppVersionNumber(),
'queue_source' => method_exists($this->task, 'getQueueSource')
? $this->task->getQueueSource() : null,
];
}

private function getRawDataEnd()
{
$profilerOutput = $this->profiler
? $this->profiler->getTaskerProfilerOutput($this->task->getExecTime())
: null;

$rawData = [
'id' => $this->getId(),
'ts_finished' => $this->task->getTsFinished(),
'memory_peak_usage' => memory_get_peak_usage(),
'exception' => $this->exception === null
? null
: \json_encode([
'message' => $this->exception->getMessage(),
'line' => $this->exception->getLine(),
'code' => $this->exception->getCode(),
'trace' => $this->exception->getTrace(),
]
),
'output' => $this->getOutput(),
'exec_time' => $this->task->getExecTime(),
'exec_time_ms' => (int)($this->task->getExecTime() * 1000),
'status' => $this->task->getStatus(),
'started_count' => $this->task->getStartedCount(),
'profiler' => $profilerOutput ? \json_encode($profilerOutput) : null,
];

$rawData += $this->getCpuLoad();

Expand Down Expand Up @@ -113,6 +149,11 @@ public function setProfiler(Profiler $profiler)
return $this;
}

public function hasProfiler()
{
return $this->profiler !== null;
}

/**
* @param string
*/
Expand Down
11 changes: 11 additions & 0 deletions src/Data/TaskerStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class TaskerStart extends LoggerAbstract
*/
private $options;

/**
* @var string
*/
private $type;

/**
* @return array
*/
Expand All @@ -18,6 +23,7 @@ public function getRawData()
$rawData = [
'id' => $this->getId(),
'timestamp' => $this->getJsTimestamp(),
'type' => $this->type,
'datetime' => \date('Y-m-d H:i:s'),
'options' => \json_encode($this->options),
'hostname' => \gethostname(),
Expand All @@ -40,4 +46,9 @@ public function setOptions($options)
$this->options = $options;
return $this;
}

public function setType($type)
{
$this->type = $type;
}
}
5 changes: 5 additions & 0 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public function logAppend(\G4\Log\Data\LoggerAbstract $data)
$this->adapter->saveAppend($data->getRawData());
}

public function clearData()
{
$this->adapter->clearData();
}

/**
* @param mixed $var
* @param string $tag
Expand Down