1010#[Flow \Scope("singleton " )]
1111abstract class JobStatusService {
1212
13+ protected const string TOTAL_COUNT_QUERY = "" ;
14+ protected const string RUNNING_COUNT_QUERY = "" ;
15+ protected const string PENDING_COUNT_QUERY = "" ;
16+ protected const string STALE_COUNT_QUERY = "" ;
17+ protected const string FAILED_COUNT_QUERY = "" ;
18+
1319 #[Flow \Inject]
1420 protected Scheduler $ scheduler ;
1521
1622 public function getTotalJobCount (string $ groupName ): int {
1723 $ tableName = ScheduledJob::TABLE_NAME ;
18- $ query = <<<MySQL
19- SELECT COUNT(*) FROM {$ tableName }
20- WHERE groupname = :groupName
21- MySQL ;
2224 return $ this ->fetchOne (
23- $ query ,
25+ self :: TOTAL_COUNT_QUERY ,
2426 [
2527 'groupName ' => $ groupName
2628 ],
@@ -32,35 +34,23 @@ public function getTotalJobCount(string $groupName): int {
3234
3335 public function getRunningJobCount (string $ groupName ): int {
3436 $ tableName = ScheduledJob::TABLE_NAME ;
35- $ query = <<<MySQL
36- SELECT COUNT(*) FROM {$ tableName }
37- WHERE running = 1
38- AND claimed NOT LIKE 'failed(%)'
39- AND groupname = :groupName
40- AND activity > NOW() - INTERVAL 2 SECOND
41- MySQL ;
4237 return $ this ->fetchOne (
43- $ query ,
38+ self :: RUNNING_COUNT_QUERY ,
4439 [
45- 'groupName ' => $ groupName
40+ 'groupName ' => $ groupName ,
41+ 'seconds ' => $ this ->scheduler ->getStaleJobTimeoutSeconds ()
4642 ],
4743 [
48- 'groupName ' => Types::STRING
44+ 'groupName ' => Types::STRING ,
45+ 'seconds ' => Types::INTEGER
4946 ]
5047 );
5148 }
5249
5350 public function getPendingJobCount (string $ groupName ): int {
5451 $ tableName = ScheduledJob::TABLE_NAME ;
55- $ query = <<<MySQL
56- SELECT COUNT(*) FROM {$ tableName }
57- WHERE ((running = 0
58- AND claimed = '')
59- OR running = 2)
60- AND groupname = :groupName
61- MySQL ;
6252 return $ this ->fetchOne (
63- $ query ,
53+ self :: PENDING_COUNT_QUERY ,
6454 [
6555 'groupName ' => $ groupName
6656 ],
@@ -70,37 +60,25 @@ public function getPendingJobCount(string $groupName): int {
7060 );
7161 }
7262
73- public function getStaleJobCount (string $ groupName, int $ minutes ): int {
63+ public function getStaleJobCount (string $ groupName ): int {
7464 $ tableName = ScheduledJob::TABLE_NAME ;
75- $ query = <<<MySQL
76- SELECT COUNT(*) FROM {$ tableName }
77- WHERE running = 1
78- AND claimed NOT LIKE 'failed(%)'
79- AND groupname = :groupName
80- AND activity < NOW() - INTERVAL :minutes MINUTE
81- MySQL ;
8265 return $ this ->fetchOne (
83- $ query ,
66+ self :: STALE_COUNT_QUERY ,
8467 [
8568 "groupName " => $ groupName ,
86- "minutes " => $ minutes
69+ "seconds " => $ this -> scheduler -> getStaleJobTimeoutSeconds ()
8770 ],
8871 [
8972 "groupName " => Types::STRING ,
90- "minutes " => Types::INTEGER
73+ "seconds " => Types::INTEGER
9174 ]
9275 );
9376 }
9477
9578 public function getFailedJobCount (string $ groupName ): int {
9679 $ tableName = ScheduledJob::TABLE_NAME ;
97- $ query = <<<MySQL
98- SELECT COUNT(*) FROM {$ tableName }
99- WHERE claimed LIKE 'failed(%)'
100- AND groupname = :groupName
101- MySQL ;
10280 return $ this ->fetchOne (
103- $ query ,
81+ self :: FAILED_COUNT_QUERY ,
10482 [
10583 'groupName ' => $ groupName
10684 ],
0 commit comments