Show More
@@ -19,22 +19,37 b'' | |||||
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 | import os |
|
21 | import os | |
|
22 | import sys | |||
22 | import atexit |
|
23 | import atexit | |
23 | import logging |
|
24 | import logging | |
24 | import signal |
|
25 | import signal | |
|
26 | import rhodecode | |||
25 |
|
27 | |||
26 | log = logging.getLogger(__name__) |
|
28 | log = logging.getLogger(__name__) | |
27 |
|
29 | |||
28 | cache_keys_by_pid = set() |
|
30 | cache_keys_by_pid = set() | |
29 |
|
31 | |||
30 |
|
32 | |||
|
33 | def sigHandler(signo, frame): | |||
|
34 | """ | |||
|
35 | signals trigger sys.exit so there's a single handler to cleanup the code. | |||
|
36 | """ | |||
|
37 | if rhodecode.is_test: | |||
|
38 | return | |||
|
39 | ||||
|
40 | sys.exit(0) | |||
|
41 | ||||
|
42 | ||||
31 | def free_cache_keys(*args): |
|
43 | def free_cache_keys(*args): | |
|
44 | from rhodecode.model.db import Session, CacheKey | |||
|
45 | ||||
|
46 | if rhodecode.is_test: | |||
|
47 | return | |||
|
48 | ||||
32 | ssh_cmd = os.environ.get('RC_CMD_SSH_WRAPPER') |
|
49 | ssh_cmd = os.environ.get('RC_CMD_SSH_WRAPPER') | |
33 | if ssh_cmd: |
|
50 | if ssh_cmd: | |
34 | return |
|
51 | return | |
35 |
|
52 | |||
36 | from rhodecode.model.db import Session, CacheKey |
|
|||
37 |
|
||||
38 | if cache_keys_by_pid: |
|
53 | if cache_keys_by_pid: | |
39 | try: |
|
54 | try: | |
40 | for cache_proc in set(cache_keys_by_pid): |
|
55 | for cache_proc in set(cache_keys_by_pid): | |
@@ -48,7 +63,8 b' def free_cache_keys(*args):' | |||||
48 | except Exception: |
|
63 | except Exception: | |
49 | log.exception('Failed to clear keys, exiting gracefully') |
|
64 | log.exception('Failed to clear keys, exiting gracefully') | |
50 |
|
65 | |||
|
66 | atexit.register(free_cache_keys) | |||
51 |
|
67 | |||
52 | atexit.register(free_cache_keys) |
|
68 | signal.signal(signal.SIGTERM, sigHandler) | |
53 |
signal.signal(signal.SIGT |
|
69 | signal.signal(signal.SIGINT, sigHandler) | |
54 | signal.signal(signal.SIGINT, free_cache_keys) |
|
70 |
General Comments 0
You need to be logged in to leave comments.
Login now