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 {
17- $ tableName = ScheduledJob::TABLE_NAME ;
18- $ query = <<<MySQL
19- SELECT COUNT(*) FROM {$ tableName }
20- WHERE groupname = :groupName
21- MySQL ;
2223 return $ this ->fetchOne (
23- $ query ,
24+ static :: TOTAL_COUNT_QUERY ,
2425 [
2526 'groupName ' => $ groupName
2627 ],
@@ -31,36 +32,22 @@ public function getTotalJobCount(string $groupName): int {
3132 }
3233
3334 public function getRunningJobCount (string $ groupName ): int {
34- $ 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 ;
4235 return $ this ->fetchOne (
43- $ query ,
36+ static :: RUNNING_COUNT_QUERY ,
4437 [
45- 'groupName ' => $ groupName
38+ 'groupName ' => $ groupName ,
39+ 'seconds ' => $ this ->scheduler ->getStaleJobTimeoutSeconds ()
4640 ],
4741 [
48- 'groupName ' => Types::STRING
42+ 'groupName ' => Types::STRING ,
43+ 'seconds ' => Types::INTEGER
4944 ]
5045 );
5146 }
5247
5348 public function getPendingJobCount (string $ groupName ): int {
54- $ 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 ;
6249 return $ this ->fetchOne (
63- $ query ,
50+ static :: PENDING_COUNT_QUERY ,
6451 [
6552 'groupName ' => $ groupName
6653 ],
@@ -70,37 +57,23 @@ public function getPendingJobCount(string $groupName): int {
7057 );
7158 }
7259
73- public function getStaleJobCount (string $ groupName , int $ minutes ): int {
74- $ 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 ;
60+ public function getStaleJobCount (string $ groupName ): int {
8261 return $ this ->fetchOne (
83- $ query ,
62+ static :: STALE_COUNT_QUERY ,
8463 [
8564 "groupName " => $ groupName ,
86- "minutes " => $ minutes
65+ "seconds " => $ this -> scheduler -> getStaleJobTimeoutSeconds ()
8766 ],
8867 [
8968 "groupName " => Types::STRING ,
90- "minutes " => Types::INTEGER
69+ "seconds " => Types::INTEGER
9170 ]
9271 );
9372 }
9473
9574 public function getFailedJobCount (string $ groupName ): int {
96- $ tableName = ScheduledJob::TABLE_NAME ;
97- $ query = <<<MySQL
98- SELECT COUNT(*) FROM {$ tableName }
99- WHERE claimed LIKE 'failed(%)'
100- AND groupname = :groupName
101- MySQL ;
10275 return $ this ->fetchOne (
103- $ query ,
76+ static :: FAILED_COUNT_QUERY ,
10477 [
10578 'groupName ' => $ groupName
10679 ],
0 commit comments