def start_job()

in dyno/app/api/control.py [0:0]


def start_job() -> dict:
    """
    Start a load-generation job

    Exposed via HTTP at /api/start

    Supported HTTP methods: GET

    Note
    ----
    Paramaters are received via JSON in a Flask request object. They
    may not be passed directly to this function.

    Parameters
    ----------
    port : str
        The port number to target

    scenario : str
        The scenario to launch. Defaults to `molotov_scenarios`

    duration : str
        The duration for the test to run in seconds. Default is 365 *days*.

    delay : str
        The average delay between requests. See the Molotov documation
        for more information on this option.

        https://molotov.readthedocs.io/en/stable/cli/?highlight=delay#command-line-options

    workers : str
        The number of workers to start. See the Molotov documentation
        for more details on this option:

        https://molotov.readthedocs.io/en/stable/cli/?highlight=workers#command-line-options

    error_weight : str
        The relative "weight" of errors. Higher number result in the load
        generator choosing to hit pages known to produce errors a higher
        percentage of the time.

        This number is entirely arbitrary and is only relative to statically
        configured weights in the scenario file itself.

    app_latency_weight : str
        In the case of the `dyno` scenario, an app_latency_weight
        parameter can be passed which increases the rate at which a given
        label is accessed.

        Does NOT work with scenarios other than `dyno`!

    app_latency_label : str
        Used in conjunction with `app_latency_weightr` to specify a
        label which should be hit at a higher or lower rate.

    app_latency_lower_bound : int
        The lower bound of latency which should be applied to requests which
        hit the delayed endpoint

    app_latency_upper_bound : int
        The upper bound of latency which should be applied to requests which
        hit the delayed endpoint

    Examples
    --------
    Sample JSON payload to send to this endpoint:
    > {"job":"opbeans-python","port":"8000"}
    """
    r = request.get_json() or {}
    job = r.get('job')
    config = {
            'port': r.get('port'),
            'scenario': r.get('scenario', "molotov_scenarios"),
            'duration': r.get('duration', "31536000"),
            'delay': r.get('delay', "0.600"),
            'workers': r.get('workers', "3"),
            'error_weight': r.get('error_weight', "0"),
            'app_latency_weight': r.get('app_latency_weight', "0"),
            'app_latency_label': r.get('app_latency_label', 'dyno_latency'), # noqa
            'app_latency_lower_bound': r.get('app_latency_lower_bound', 1),  # noqa
            'app_latency_upper_bound': r.get('app_latency_upper_bound', 1000),  # noqa
            }

    job = job.replace('opbeans-', '')

    if config['scenario']:
        config['scenario'] = "scenarios/" + config['scenario'] + ".py"

    _launch_job(job, config)

    return {}