Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added heartbeat internal method with tests
- Loading branch information
Showing
5 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
CREATE OR REPLACE FUNCTION increment_heartbeat(p_instance_id text) | ||
RETURNS SETOF integer AS | ||
$BODY$ | ||
DECLARE | ||
v_heartbeats integer; | ||
v_app_id integer; | ||
BEGIN | ||
|
||
SELECT app_id FROM instance WHERE id = p_instance_id | ||
LIMIT 1 | ||
INTO v_app_id; | ||
|
||
SELECT heartbeats FROM app WHERE id = v_app_id | ||
LIMIT 1 | ||
INTO v_heartbeats; | ||
|
||
IF v_heartbeats IS NOT null THEN | ||
UPDATE app | ||
SET heartbeats = heartbeats + 1 | ||
WHERE id = v_app_id; | ||
ELSE | ||
UPDATE app | ||
SET heartbeats = 1 | ||
WHERE id = v_app_id; | ||
END IF; | ||
|
||
RETURN QUERY SELECT app.heartbeats FROM app WHERE id = v_app_id; | ||
|
||
END; | ||
$BODY$ | ||
LANGUAGE plpgsql VOLATILE | ||
-- vim: set filetype=pgsql : | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE app ADD COLUMN heartbeats integer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters