88class TaskerExecution extends LoggerAbstract
99{
1010 const LOG_TYPE = 'execution ' ;
11- const CONTENT_LIMIT = 512 ;
11+ const CONTENT_LIMIT = 30000 ;
1212
1313 /**
1414 * @var \G4\Tasker\Model\Domain\Task
@@ -35,42 +35,78 @@ class TaskerExecution extends LoggerAbstract
3535 */
3636 private $ profiler ;
3737
38+ private $ taskFinished = false ;
39+
40+ public function taskStarted ()
41+ {
42+ $ this ->taskFinished = false ;
43+ }
44+
45+ public function taskFinished ()
46+ {
47+ $ this ->taskFinished = true ;
48+ }
49+
3850 public function getRawData ()
3951 {
40- $ rawData = [
52+ $ rawData = $ this ->taskFinished
53+ ? $ this ->getRawDataEnd ()
54+ : $ this ->getRawDataStart ();
55+ return $ rawData ;
56+ }
57+
58+ private function getRawDataStart ()
59+ {
60+ return [
4161 'id ' => $ this ->getId (),
4262 'timestamp ' => $ this ->getJsTimestamp (),
4363 'hostname ' => \gethostname (),
4464 'pid ' => \getmypid (),
4565 'type ' => $ this ->logType ?: self ::LOG_TYPE ,
46- 'memory_peak_usage ' => memory_get_peak_usage (),
47- 'exception ' => $ this ->exception === null ? null : \json_encode ([
48- 'message ' => $ this ->exception ->getMessage (),
49- 'line ' => $ this ->exception ->getLine (),
50- 'code ' => $ this ->exception ->getCode (),
51- 'trace ' => $ this ->exception ->getTrace (),
52- ]
53- ),
54-
5566 'task_id ' => $ this ->task ->getTaskId (),
5667 'recu_id ' => $ this ->task ->getRecurringId (),
5768 'identifier ' => $ this ->task ->getIdentifier (),
5869 'task ' => $ this ->task ->getTask (),
5970 'data ' => $ this ->task ->getData (),
60- 'output ' => $ this ->getOutput (),
6171 'request_uuid ' => $ this ->task ->getRequestUuid (),
6272 'priority ' => $ this ->task ->getPriority (),
6373 'status ' => $ this ->task ->getStatus (),
6474 'ts_created ' => $ this ->task ->getTsCreated (),
6575 'ts_started ' => $ this ->task ->getTsStarted (),
66- 'exec_time ' => $ this ->task ->getExecTime (),
67- 'exec_time_ms ' => (int )($ this ->task ->getExecTime () * 1000 ),
6876 'started_count ' => $ this ->task ->getStartedCount (),
6977 'php_version ' => str_replace (PHP_EXTRA_VERSION , '' , PHP_VERSION ),
7078 'app_version ' => $ this ->getAppVersionNumber (),
7179 'queue_source ' => method_exists ($ this ->task , 'getQueueSource ' )
7280 ? $ this ->task ->getQueueSource () : null ,
7381 ];
82+ }
83+
84+ private function getRawDataEnd ()
85+ {
86+ $ profilerOutput = $ this ->profiler
87+ ? $ this ->profiler ->getTaskerProfilerOutput ($ this ->task ->getExecTime ())
88+ : null ;
89+
90+ $ rawData = [
91+ 'id ' => $ this ->getId (),
92+ 'ts_finished ' => $ this ->task ->getTsFinished (),
93+ 'memory_peak_usage ' => memory_get_peak_usage (),
94+ 'exception ' => $ this ->exception === null
95+ ? null
96+ : \json_encode ([
97+ 'message ' => $ this ->exception ->getMessage (),
98+ 'line ' => $ this ->exception ->getLine (),
99+ 'code ' => $ this ->exception ->getCode (),
100+ 'trace ' => $ this ->exception ->getTrace (),
101+ ]
102+ ),
103+ 'output ' => $ this ->getOutput (),
104+ 'exec_time ' => $ this ->task ->getExecTime (),
105+ 'exec_time_ms ' => (int )($ this ->task ->getExecTime () * 1000 ),
106+ 'status ' => $ this ->task ->getStatus (),
107+ 'started_count ' => $ this ->task ->getStartedCount (),
108+ 'profiler ' => $ profilerOutput ? \json_encode ($ profilerOutput ) : null ,
109+ ];
74110
75111 $ rawData += $ this ->getCpuLoad ();
76112
@@ -113,6 +149,11 @@ public function setProfiler(Profiler $profiler)
113149 return $ this ;
114150 }
115151
152+ public function hasProfiler ()
153+ {
154+ return $ this ->profiler !== null ;
155+ }
156+
116157 /**
117158 * @param string
118159 */
0 commit comments