Skip to content

Commit 6fdf5f6

Browse files
committed
RHINENG-22546: let mark_stale job also unstale systems
1 parent 67ce524 commit 6fdf5f6

3 files changed

Lines changed: 53 additions & 5 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CREATE OR REPLACE FUNCTION mark_stale_systems(mark_limit integer)
2+
RETURNS INTEGER
3+
AS
4+
$fun$
5+
DECLARE
6+
marked integer;
7+
BEGIN
8+
WITH ids AS (
9+
SELECT rh_account_id, id
10+
FROM system_platform
11+
WHERE stale_warning_timestamp < now()
12+
AND stale = false
13+
ORDER BY rh_account_id, id FOR UPDATE OF system_platform
14+
LIMIT mark_limit
15+
)
16+
UPDATE system_platform sp
17+
SET stale = true
18+
FROM ids
19+
WHERE sp.rh_account_id = ids.rh_account_id
20+
AND sp.id = ids.id;
21+
GET DIAGNOSTICS marked = ROW_COUNT;
22+
RETURN marked;
23+
END;
24+
$fun$ LANGUAGE plpgsql;
25+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CREATE OR REPLACE FUNCTION mark_stale_systems(mark_limit integer)
2+
RETURNS INTEGER
3+
AS
4+
$fun$
5+
DECLARE
6+
marked integer;
7+
BEGIN
8+
WITH ids AS (
9+
SELECT rh_account_id, id, stale_warning_timestamp < now() as expired
10+
FROM system_platform
11+
WHERE stale != (stale_warning_timestamp < now())
12+
ORDER BY rh_account_id, id FOR UPDATE OF system_platform
13+
LIMIT mark_limit
14+
)
15+
UPDATE system_platform sp
16+
SET stale = ids.expired
17+
FROM ids
18+
WHERE sp.rh_account_id = ids.rh_account_id
19+
AND sp.id = ids.id;
20+
GET DIAGNOSTICS marked = ROW_COUNT;
21+
RETURN marked;
22+
END;
23+
$fun$ LANGUAGE plpgsql;
24+

database_admin/schema/create_schema.sql

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS schema_migrations
77

88

99
INSERT INTO schema_migrations
10-
VALUES (139, false);
10+
VALUES (140, false);
1111

1212
-- ---------------------------------------------------------------------------
1313
-- Functions
@@ -416,15 +416,14 @@ DECLARE
416416
marked integer;
417417
BEGIN
418418
WITH ids AS (
419-
SELECT rh_account_id, id
419+
SELECT rh_account_id, id, stale_warning_timestamp < now() as expired
420420
FROM system_platform
421-
WHERE stale_warning_timestamp < now()
422-
AND stale = false
421+
WHERE stale != (stale_warning_timestamp < now())
423422
ORDER BY rh_account_id, id FOR UPDATE OF system_platform
424423
LIMIT mark_limit
425424
)
426425
UPDATE system_platform sp
427-
SET stale = true
426+
SET stale = ids.expired
428427
FROM ids
429428
WHERE sp.rh_account_id = ids.rh_account_id
430429
AND sp.id = ids.id;

0 commit comments

Comments
 (0)