blob: e3a2fe4db9d5243e9c61d3039a4bf3f374186b71 [file] [log] [blame]
alshabib7941d402016-11-08 00:11:20 +01001#
2# Copyright 2016 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17from handlers import handler_start, handler_stop
18from structlog import get_logger
alshabib9d222022016-11-10 16:11:09 -080019from jinja2 import Template
alshabib7941d402016-11-08 00:11:20 +010020
21from common.utils.dockerhelpers import EventProcessor
22
23class Podder(object):
24
25 log = get_logger()
26
27 def __init__(self, args, slave_config):
28 self.log.info('Initializing Podder')
29 self.running = False
alshabib05fb71f2016-12-04 16:08:29 -080030 self.events = EventProcessor(threads=args.threads)
alshabib9d222022016-11-10 16:11:09 -080031 self.handlers = { 'podder_config' : Template(slave_config) }
alshabib7941d402016-11-08 00:11:20 +010032
33 def run(self):
34 if self.running:
35 return
36 self.running = True
37
38 self.initialize()
39
40 def shutdown(self):
41 try:
42 self.events.stop_listening()
43 except:
44 self.log.info('Shutting down')
45
46 def initialize(self):
47 self.define_handlers()
48 while True:
49 try:
50 self.events.listen_for_events(self.handlers)
51 except KeyboardInterrupt:
52 self.shutdown()
53 break
54 except Exception, e:
55 self.log.info('Handler exception', e)
56
57 def define_handlers(self):
58 self.handlers['start'] = handler_start
59 self.handlers['stop'] = handler_stop
60