def run(environ): """Performs the work passed in ``environ``. Returns the modified ``environ``. It might be modified in-place by work implementations. The following keys in ``environ`` have special meaning: ``job_type`` Mandatory key naming the job to be run. ``prefilters`` Optional list of filter names to apply before performing the work. ``postfilters`` Optional list of filter names to apply after performing the work. Refer to :ref:`sio-workers-filters` for more information about filters. """ original_cwd = os.getcwd() tmpdir = tempfile.mkdtemp() try: os.chdir(tmpdir) environ = _run_filters('prefilters', environ) environ = first_entry_point('sio.jobs', environ['job_type'])(environ) environ['result'] = 'SUCCESS' environ = _run_filters('postfilters', environ) except Failure, e: environ = _save_failure(e, environ) try: environ = _run_filters('postfilters', environ) except Failure, e: pass
def run(environ): if 'compiler' not in environ: _, extension = os.path.splitext(environ['source_file']) environ['compiler'] = 'default-' + extension[1:].lower() compiler = first_entry_point('sio.compilers', environ['compiler'].split('.')[0]) environ = compiler(environ) assert ( 'compiler_output' in environ ), "Mandatory key 'compiler_output' not returned by job." assert 'result_code' in environ, "Mandatory key 'result_code' not returned by job." return environ
def run(environ): if 'compiler' not in environ: _, extension = os.path.splitext(environ['source_file']) environ['compiler'] = 'default-' + extension[1:].lower() compiler = first_entry_point('sio.compilers', environ['compiler'].split('.')[0]) environ = compiler(environ) assert 'compiler_output' in environ, \ "Mandatory key 'compiler_output' not returned by job." assert 'result_code' in environ, \ "Mandatory key 'result_code' not returned by job." return environ
def run(environ): """Performs the work passed in ``environ``. Returns the modified ``environ``. It might be modified in-place by work implementations. The following keys in ``environ`` have special meaning: ``job_type`` Mandatory key naming the job to be run. ``prefilters`` Optional list of filter names to apply before performing the work. ``postfilters`` Optional list of filter names to apply after performing the work. The following are added during processing: ``worker`` Hostname of the machine running the job (i.e. the machine executing this function). Refer to :ref:`sio-workers-filters` for more information about filters. """ with TemporaryCwd(): try: if environ.get('filetracker_url', None): init_instance(environ['filetracker_url']) environ = _run_filters('prefilters', environ) environ = _add_meta(environ) environ = first_entry_point('sio.jobs', environ['job_type'])(environ) environ['result'] = 'SUCCESS' environ = _run_filters('postfilters', environ) except Failure as e: environ = _save_failure(e, environ) try: environ = _run_filters('postfilters', environ) except Failure as e: pass return environ
def _run_filters(key, environ): for f in environ.get(key, ()): environ = first_entry_point('sio.workers.filters', f)(environ) return environ