Created
April 9, 2010 16:43
-
-
Save sumskyi/361356 to your computer and use it in GitHub Desktop.
clear runaway conferences
This file contains hidden or 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
DELIMITER $$ | |
DROP PROCEDURE IF EXISTS clear_runaway_conferences$$ | |
CREATE PROCEDURE clear_runaway_conferences() | |
MODIFIES SQL DATA | |
BEGIN | |
DROP TABLE IF EXISTS _in_process; | |
CREATE TEMPORARY TABLE _in_process (`state` VARCHAR(32)); | |
INSERT INTO _in_process VALUES ('created'), ('seeker_answered'), ('advisor_answered'), ('billing_started'); | |
DROP TABLE IF EXISTS _runaway_conferences; | |
CREATE TEMPORARY TABLE _runaway_conferences AS | |
SELECT lc.id, c.id AS cid FROM live_conferences lc | |
INNER JOIN conferences c ON ( | |
c.id = lc.conference_id | |
) | |
LEFT JOIN conference_events ce ON ( | |
ce.conference_id = lc.id | |
AND ce.`type` = 'HeartbeatConferenceEvent' | |
) | |
WHERE | |
(c.aasm_state NOT IN (SELECT `state` FROM _in_process) OR lc.created_at < (NOW() - INTERVAL 36000 SECOND) ) | |
AND ce.`type` IS NULL; | |
SELECT cid AS conference_id FROM _runaway_conferences; | |
DELETE FROM live_conferences WHERE id IN (SELECT id FROM _runaway_conferences); | |
END$$ | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment