|
1 | 1 | import logging
|
| 2 | +import os |
| 3 | +from signal import SIGUSR2 |
2 | 4 | from typing import Dict, Iterator, Mapping, Tuple
|
3 | 5 |
|
4 | 6 | from apscheduler import events
|
@@ -83,21 +85,27 @@ def on_missed(event: events.JobExecutionEvent) -> None:
|
83 | 85 | ####
|
84 | 86 |
|
85 | 87 |
|
| 88 | +def handle_exec_error(message: str): |
| 89 | + log.error(message) |
| 90 | + if cfg.exit_on_unexpected_container_states: |
| 91 | + os.kill(os.getpid(), SIGUSR2) |
| 92 | + |
| 93 | + |
86 | 94 | def exec_job(**definition) -> Tuple[int, bytes]:
|
87 | 95 | job_id = definition['job_id']
|
88 | 96 | container_id = definition['container_id']
|
89 | 97 | log.info(f"{container_name(container_id)}: Executing '{definition['job_name']}'.")
|
90 | 98 |
|
91 |
| - # some sanity checks, to be removed eventually |
| 99 | + # some sanity checks |
92 | 100 | assert scheduler.get_job(job_id) is not None
|
93 | 101 | if cfg.client.containers.list(filters={'id': container_id, 'status': 'paused'}):
|
94 |
| - raise AssertionError('Container is paused.') |
| 102 | + handle_exec_error('Container is paused.') |
95 | 103 |
|
96 | 104 | if not cfg.client.containers.list(
|
97 | 105 | filters={'id': container_id, 'status': 'running'}
|
98 | 106 | ):
|
99 | 107 | assert scheduler.get_job(job_id) is None
|
100 |
| - raise AssertionError('Container is not running.') |
| 108 | + handle_exec_error('Container is not running.') |
101 | 109 | # end of sanity checks
|
102 | 110 |
|
103 | 111 | return cfg.client.containers.get(container_id).exec_run(
|
|
0 commit comments