graphql-engine/server/src-rsr/mssql/mssql_fetch_events.sql.shakespeare
paritosh-08 3d4c66041f server: add event_processing_time metric
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6987
GitOrigin-RevId: 4f5948a225b18e2db59572482d2a608117fbb7d0
2022-12-06 15:11:04 +00:00

13 lines
945 B
Plaintext

UPDATE hdb_catalog.event_log
SET locked = SYSDATETIMEOFFSET()
OUTPUT CONVERT(varchar(MAX), inserted.id), inserted.schema_name, inserted.table_name, inserted.trigger_name, CONVERT(varchar(MAX), inserted.payload), inserted.tries, CONVERT(varchar(MAX), inserted.created_at), CONVERT(varchar(MAX), inserted.next_retry_at)
WHERE id in
(SELECT TOP(#{fetchBatchSize}) l.id
FROM hdb_catalog.event_log l WITH (UPDLOCK, READPAST)
WHERE (l.delivered = 0 and l.error = 0)
AND (l.locked IS NULL or l.locked < DATEADD(MINUTE, -30, SYSDATETIMEOFFSET()))
AND (l.next_retry_at is NULL or l.next_retry_at <= SYSDATETIMEOFFSET())
AND l.archived = 0
AND l.trigger_name IN #{triggerNamesTxt}
-- Note: In MSSQL, when you order it by ASC - it implies nulls first
ORDER BY l.locked ASC, l.next_retry_at ASC, l.created_at)