-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_options_and_logging.py
47 lines (39 loc) · 1.47 KB
/
custom_options_and_logging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import traceback
from rdh import Container, MessageContainer, create_parser, configure_redis, run_harness, log
def to_upper_case(msg_cont):
"""
Processes the message container, turning the message into upper case.
NB: This code is assumed to reside in a docker container.
:param msg_cont: the message container to process
:type msg_cont: MessageContainer
"""
msg = msg_cont.message['data'].decode()
# if in verbose mode, output the message
if msg_cont.params.config.verbose:
log(msg)
msg = msg.upper()
# if in verbose mode, output the processed string
if msg_cont.params.config.verbose:
log(msg)
msg_cont.message = None
msg_cont.params.redis.publish(msg_cont.params.channel_out, msg)
def main(args=None):
"""
Parses the supplied arguments; if None, uses the command-line arguments supplied to the process.
:param args: the arguments to parse
:type args: list
"""
parser = create_parser("String processing")
parser.add_argument('--verbose', action='store_true',
dest='verbose', help='Whether to output some debugging information')
parsed = parser.parse_args(args=args)
# place custom options in container
config = Container()
config.verbose = parsed.verbose
params = configure_redis(parsed, config=config)
run_harness(params, to_upper_case)
if __name__ == "__main__":
try:
main()
except Exception:
print(traceback.format_exc())