Skip to content

Commit 34977a3

Browse files
AP-1207 - abort query on tap termination (transferwise#168)
1 parent da2fad9 commit 34977a3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tap_postgres/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import psycopg2.extensions
77
import singer
88
import singer.schema
9+
import signal
910

1011
from singer import utils, metadata, get_bookmark
1112
from singer.catalog import Catalog
@@ -21,6 +22,20 @@
2122
dump_catalog, clear_state_on_replication_change,
2223
is_selected_via_metadata, refresh_streams_schema, any_logical_streams)
2324

25+
26+
psycopg2.extensions.set_wait_callback(psycopg2.extras.wait_select)
27+
28+
29+
def handle_signal(sig=None, frame=None):
30+
"""
31+
signal handler for sigterms
32+
raise sigint because that's how psycopg2 aborts running queries
33+
"""
34+
raise KeyboardInterrupt("RECEIVED SIGTERM. RAISING SIGINT TO ABORT POSTGRES QUERY")
35+
36+
37+
signal.signal(signal.SIGTERM, handle_signal)
38+
2439
LOGGER = singer.get_logger('tap_postgres')
2540

2641
REQUIRED_CONFIG_KEYS = [

0 commit comments

Comments
 (0)