@@ -24,21 +24,74 @@ public function index() {
2424 ->orderBy ('updated_at ' )
2525 ->first ();
2626
27- $ maxDurationWorkflow = config ('workflows.stored_workflow_model ' , StoredWorkflow::class)::select ('* ' )
28- ->when (config ('database.default ' ) === 'mysql ' , function ($ q ) {
29- return $ q ->addSelect (DB ::raw ('TIMEDIFF(created_at, updated_at) as duration ' ));
30- })
31- ->when (config ('database.default ' ) === 'pgsql ' , function ($ q ) {
32- return $ q ->addSelect (DB ::raw ('(EXTRACT(EPOCH FROM created_at - updated_at)) as duration ' ));
33- })
34- ->where ('status ' , '!= ' , 'pending ' )
35- ->orderBy ('duration ' )
36- ->first ();
27+ if (config ('database.default ' ) === 'mongodb ' && $ maxWaitTimeWorkflow && $ maxWaitTimeWorkflow ->_id ) {
28+ $ maxWaitTimeWorkflow ->id = $ maxWaitTimeWorkflow ->_id ;
29+ }
3730
38- $ maxExceptionsWorkflow = config ('workflows.stored_workflow_model ' , StoredWorkflow::class)::withCount ('exceptions ' )
39- ->orderByDesc ('exceptions_count ' )
40- ->orderByDesc ('updated_at ' )
41- ->first ();
31+ if (config ('database.default ' ) === 'mongodb ' ) {
32+ $ maxDurationWorkflow = config ('workflows.stored_workflow_model ' , StoredWorkflow::class)::select ('* ' )
33+ ->raw (function ($ collection ) {
34+ return $ collection ->aggregate ([
35+ [
36+ '$match ' => [
37+ 'status ' => [ '$ne ' => 'pending ' ]
38+ ]
39+ ],
40+ [
41+ '$addFields ' => [
42+ 'duration ' => [
43+ '$subtract ' => [
44+ ['$toDate ' => '$updated_at ' ],
45+ ['$toDate ' => '$created_at ' ]
46+ ]
47+ ]
48+ ]
49+ ],
50+ [
51+ '$sort ' => ['duration ' => -1 ]
52+ ],
53+ [
54+ '$limit ' => 1
55+ ]
56+ ]);
57+ })
58+ ->first ();
59+ $ maxDurationWorkflow ->id = $ maxDurationWorkflow ->_id ;
60+ } else {
61+ $ maxDurationWorkflow = config ('workflows.stored_workflow_model ' , StoredWorkflow::class)::select ('* ' )
62+ ->when (config ('database.default ' ) === 'mysql ' , function ($ q ) {
63+ return $ q ->addSelect (DB ::raw ('TIMEDIFF(created_at, updated_at) as duration ' ));
64+ })
65+ ->when (config ('database.default ' ) === 'pgsql ' , function ($ q ) {
66+ return $ q ->addSelect (DB ::raw ('(EXTRACT(EPOCH FROM created_at - updated_at)) as duration ' ));
67+ })
68+ ->where ('status ' , '!= ' , 'pending ' )
69+ ->orderBy ('duration ' )
70+ ->first ();
71+ }
72+
73+ if (config ('database.default ' ) === 'mongodb ' ) {
74+ $ maxExceptionsWorkflow = null ;
75+
76+ $ mostExceptionWorkflowId = StoredWorkflowException::raw (function ($ collection ) {
77+ return $ collection ->aggregate ([
78+ ['$group ' => ['_id ' => '$stored_workflow_id ' , 'count ' => ['$sum ' => 1 ]]],
79+ ['$sort ' => ['count ' => -1 ]],
80+ ['$limit ' => 1 ]
81+ ]);
82+ })->first ()['_id ' ];
83+
84+ $ maxExceptionsWorkflow = StoredWorkflow::where ('_id ' , $ mostExceptionWorkflowId )->first ();
85+
86+ $ maxExceptionsWorkflow ->exceptions_count = StoredWorkflowException::where ('stored_workflow_id ' , $ mostExceptionWorkflowId )->count ();
87+
88+ $ maxExceptionsWorkflow ->id = $ maxExceptionsWorkflow ->_id ;
89+ } else {
90+ $ maxExceptionsWorkflow = config ('workflows.stored_workflow_model ' , StoredWorkflow::class)::withCount ('exceptions ' )
91+ ->orderByDesc ('exceptions_count ' )
92+ ->orderByDesc ('updated_at ' )
93+ ->first ();
94+ }
4295
4396 return response ()->json ([
4497 'flows ' => config ('workflows.stored_workflow_model ' , StoredWorkflow::class)::count (),
0 commit comments