in dyno/app/api/control.py [0:0]
def _launch_job(job: str, config: dict) -> None:
"""
Spawn a new load-generation job
This function can only be called directly and is
not accessible via HTTP.
Parameters
----------
job : str
config : dict
A configuration dictionary containing a valid configuration
for the job.
Returns
-------
None
Examples
--------
>>> config = {'duration': '90', 'delay': '91', \
'scenario': 'dyno', 'workers': '92',\
'error_weight': '93', 'port': '95'}
>>> update_status('python', config)
"""
if DEBUG:
print(
'Job launch received: ', config
)
if DEBUG:
cmd = ['sleep', '10']
else:
cmd = [
"/app/venv/bin/python",
"/app/venv/bin/molotov",
"-v",
"--duration",
str(config['duration']),
"--delay",
str(config['delay']),
"--uvloop",
"--workers",
str(int(config['workers'])),
"--statsd",
"--statsd-address",
"udp://stats-d:8125",
config['scenario']
]
s = socketio.Client()
s.emit('service_state', {'data': {job: 'start'}})
if DEBUG:
print('Launching with: ', cmd)
toxi_env = _construct_toxi_env(
job,
config['port'],
config['scenario'],
config['error_weight'],
# TODO These are optional so that we don't
# break backward compatability with older clients.
# Eventually the lookup fallbacks can be removed.
config.get('app_latency_weight'),
config.get('app_latency_label'),
config.get('app_latency_lower_bound'),
config.get('app_latency_upper_bound'),
)
_update_status(job, config)
# “I may not have gone where I intended to go, but I think I have ended up
# where I needed to be.”
# ― Douglas Adams, The Long Dark Tea-Time of the Soul
p = subprocess.Popen(cmd, cwd="../", preexec_fn=os.setsid, env=toxi_env)
JOB_MANAGER[job] = p