88namespace OCA \ContextChat \Service ;
99
1010use OCP \AppFramework \Services \IAppConfig ;
11- use OCP \Exceptions \AppConfigTypeConflictException ;
1211use OCP \Util ;
1312use Psr \Log \LoggerInterface ;
1413
@@ -20,42 +19,13 @@ public function __construct(
2019 ) {
2120 }
2221
23- /**
24- * @return array
25- * @throws AppConfigTypeConflictException
26- */
27- public function getBackgroundJobDiagnostics (): array {
28- return $ this ->appConfig ->getAppValueArray ('background_jobs_diagnostics ' , [], true );
29- }
30-
31- /**
32- * @param array $value
33- * @return void
34- * @throws AppConfigTypeConflictException
35- * @throws \JsonException
36- */
37- private function setBackgroundJobDiagnostics (array $ value ): void {
38- $ this ->appConfig ->setAppValueArray ('background_jobs_diagnostics ' , $ value , true );
39- }
40-
4122 /**
4223 * @param string $class
4324 * @param int $id
4425 * @return void
4526 */
4627 public function sendJobTrigger (string $ class , int $ id ): void {
4728 $ this ->logger ->info ('CONTEXT_CHAT_DIAGNOSTICS: ' . $ class . ' ' . $ id . ' triggered ' );
48- $ key = $ class . '- ' . $ id ;
49- try {
50- $ diagnostics = $ this ->getBackgroundJobDiagnostics ();
51- if (!isset ($ diagnostics [$ key ])) {
52- $ diagnostics [$ key ] = [];
53- }
54- $ diagnostics [$ key ] = array_merge (['last_triggered ' => time ()], $ diagnostics [$ key ]);
55- $ this ->setBackgroundJobDiagnostics ($ diagnostics );
56- } catch (\OCP \Exceptions \AppConfigTypeConflictException |\JsonException $ e ) {
57- $ this ->logger ->warning ('Error during context chat diagnostic jobStart ' , ['exception ' => $ e ]);
58- }
5929 }
6030
6131 /**
@@ -65,22 +35,6 @@ public function sendJobTrigger(string $class, int $id): void {
6535 */
6636 public function sendJobStart (string $ class , int $ id ): void {
6737 $ this ->logger ->info ('CONTEXT_CHAT_DIAGNOSTICS: ' . $ class . ' ' . $ id . ' started ' );
68- $ key = $ class . '- ' . $ id ;
69- try {
70- $ diagnostics = $ this ->getBackgroundJobDiagnostics ();
71- if (!isset ($ diagnostics [$ key ])) {
72- $ diagnostics [$ key ] = [];
73- }
74- $ diagnostics [$ key ] = array_merge (['last_started ' => time ()], $ diagnostics [$ key ]);
75- if (isset ($ diagnostics [$ key ]['started_count ' ])) {
76- $ diagnostics [$ key ]['started_count ' ]++;
77- } else {
78- $ diagnostics [$ key ]['started_count ' ] = 1 ;
79- }
80- $ this ->setBackgroundJobDiagnostics ($ diagnostics );
81- } catch (\OCP \Exceptions \AppConfigTypeConflictException |\JsonException $ e ) {
82- $ this ->logger ->warning ('Error during context chat diagnostic jobStart ' , ['exception ' => $ e ]);
83- }
8438 }
8539
8640 /**
@@ -90,17 +44,6 @@ public function sendJobStart(string $class, int $id): void {
9044 */
9145 public function sendJobEnd (string $ class , int $ id ): void {
9246 $ this ->logger ->info ('CONTEXT_CHAT_DIAGNOSTICS: ' . $ class . ' ' . $ id . ' ended ' );
93- $ key = $ class . '- ' . $ id ;
94- try {
95- $ diagnostics = $ this ->getBackgroundJobDiagnostics ();
96- if (!isset ($ diagnostics [$ key ])) {
97- $ diagnostics [$ key ] = [];
98- }
99- $ diagnostics [$ key ] = array_merge (['last_ended ' => time ()], $ diagnostics [$ key ]);
100- $ this ->setBackgroundJobDiagnostics ($ diagnostics );
101- } catch (\OCP \Exceptions \AppConfigTypeConflictException |\JsonException $ e ) {
102- $ this ->logger ->warning ('Error during context chat diagnostic jobStart ' , ['exception ' => $ e ]);
103- }
10447 }
10548
10649 /**
@@ -110,17 +53,6 @@ public function sendJobEnd(string $class, int $id): void {
11053 */
11154 public function sendHeartbeat (string $ class , int $ id ): void {
11255 $ this ->logger ->info ('CONTEXT_CHAT_DIAGNOSTICS: ' . $ class . ' ' . $ id . ' running ' );
113- $ key = $ class . '- ' . $ id ;
114- try {
115- $ diagnostics = $ this ->getBackgroundJobDiagnostics ();
116- if (!isset ($ diagnostics [$ key ])) {
117- $ diagnostics [$ key ] = [];
118- }
119- $ diagnostics [$ key ] = array_merge (['last_seen ' => time ()], $ diagnostics [$ key ]);
120- $ this ->setBackgroundJobDiagnostics ($ diagnostics );
121- } catch (\OCP \Exceptions \AppConfigTypeConflictException |\JsonException $ e ) {
122- $ this ->logger ->warning ('Error during context chat diagnostic heartbeat ' , ['exception ' => $ e ]);
123- }
12456 }
12557
12658 /**
0 commit comments