marcsello 7d30328e21
All checks were successful
continuous-integration/drone/push Build is passing
Added sync plugin
2021-04-11 13:53:21 +02:00

74 lines
2.0 KiB
Python

#!/usr/bin/env python3
import os
import sys
from config import Config
from plugins import WaitPlugin, SyncPlugin
from plugin_repository import PluginRepository
from program_executor import ProgramExecutor
from http_server import ControllerHTTPServer
import logging
import signal
class HTTPControl:
def GET_status(self, path, data):
return 200, "Very good!"
def POST_terminate(self, path, data):
return 200, "Will do sir!"
def POST_continue(self, path, data):
return 201, "Will do sir!"
def main():
# init
logging.basicConfig(
stream=sys.stdout,
format="%(asctime)s [%(levelname)s]: %(name)s: %(message)s",
level=logging.DEBUG
)
http_server = ControllerHTTPServer(HTTPControl())
http_server.start()
compiler_repo = PluginRepository()
compiler_repo.register_plugin(WaitPlugin)
compiler_repo.register_plugin(SyncPlugin)
# Example code:
compiler_repo.load_plugin("wait")
compiler_repo.load_plugin("sync")
program = []
program.append(compiler_repo.get_compiler("wait").compile(secs=2))
program.append(compiler_repo.get_compiler("wait").compile(secs=3))
program.append(compiler_repo.get_compiler("sync").compile(nodes=2, name="test"))
program.append(compiler_repo.get_compiler("wait").compile(secs=10))
program.append(compiler_repo.get_compiler("wait").compile(secs=10))
# prepare execution
executor = ProgramExecutor(program, loop=True)
def handle_stop_signal(signum, frame):
logging.warning(f"Signal {signum} received. Stopping execution!")
executor.abort()
# Should be possible to call only once
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGTERM, signal.SIG_IGN)
signal.signal(signal.SIGINT, handle_stop_signal)
signal.signal(signal.SIGTERM, handle_stop_signal)
# start execution
executor.start()
# End of execution
executor.join()
compiler_repo.close()
http_server.shutdown()
if __name__ == '__main__':
main()