コード例 #1
0
def bootstrap_worker(workspace: str, config_map: dict):
    """
    Bootstrap a Triggerflow worker manually, without the intervention of the controller.
    Used for testing and development purposes.
    """
    worker = TriggerflowWorker(workspace=workspace, config=config_map)
    worker.run()
コード例 #2
0
ファイル: controller.py プロジェクト: triggerflow/triggerflow
def start_worker(workspace):
    """
    Auxiliary method to start a worker
    """
    global workers

    if workspace not in workers or not workers[workspace].is_alive():
        logging.info('Starting {} workspace'.format(workspace))
        workers[workspace] = Worker(workspace, config_map)
        workers[workspace].start()
コード例 #3
0
ファイル: controller.py プロジェクト: triggerflow/triggerflow
def create_worker(workspace):
    global trigger_storage

    if not trigger_storage.workspace_exists(workspace):
        return jsonify({
            'error':
            'Workspace {} does not exist in the database'.format(workspace)
        }), 400

    if workspace in workers and workers[
            workspace].state == Worker.State.RUNNING:
        return jsonify(
            {'error':
             'Workspace {} is already created'.format(workspace)}), 400

    logging.info('Starting {} workspace'.format(workspace))
    workers[workspace] = Worker(workspace, config_map)
    workers[workspace].start()

    return jsonify({'workspace': workspace}), 201
コード例 #4
0
ファイル: controller.py プロジェクト: triggerflow/triggerflow
        logger.addHandler(fh)

    logging.info('Loading private credentials')
    with open(CONFIG_MAP_PATH, 'r') as config_file:
        config_map = yaml.safe_load(config_file)

    # Instantiate trigger storage client
    logging.info('Creating trigger storage client')
    backend = config_map['trigger_storage']['backend']
    trigger_storage_class = getattr(storage,
                                    backend.capitalize() + 'TriggerStorage')
    trigger_storage = trigger_storage_class(
        **config_map['trigger_storage']['parameters'])

    port = int(os.getenv('PORT', 5000))
    server = WSGIServer(('', port), app, log=logging.getLogger())
    logging.info('Triggerflow service started on port {}'.format(port))

    active_workspaces = trigger_storage.list_workspaces()
    for active_workspace in active_workspaces:
        workers[active_workspace] = Worker(active_workspace, config_map)
        workers[active_workspace].start()

    try:
        server.serve_forever()
    except KeyboardInterrupt:
        print('exiting...')
    finally:
        # Kill all child processes
        os.killpg(0, signal.SIGKILL)
コード例 #5
0
import yaml
import os
import logging

from triggerflow.service.worker import Worker

CONFIG_MAP_PATH = 'config_map.yaml'

if __name__ == '__main__':
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)
    stream_handler = logging.StreamHandler()
    formatter = logging.Formatter(
        '[%(asctime)s.%(msecs)03dZ][%(levelname)s][triggerflow] %(message)s',
        datefmt="%Y-%m-%dT%H:%M:%S")
    stream_handler.setFormatter(formatter)
    logger.addHandler(stream_handler)

    with open(CONFIG_MAP_PATH, 'r') as config_map_file:
        config_map = yaml.safe_load(config_map_file)

    workspace = os.environ['TRIGGERFLOW_BOOTSTRAP_WORKSPACE']

    logging.info(
        'Starting Triggerflow Worker for workspace {}'.format(workspace))
    worker = Worker(workspace=workspace, config=config_map)
    worker.start()
    worker.join()