Exemplo n.º 1
0
Arquivo: tasks.py Projeto: raiju/bs
    # mkdir output directory
    out = os.path.join(outputs_directory, task_id)
    debug('mkdir out path : %s' % out)
    try:
        os.mkdir(out)
    except OSError, e:
        if e.errno == errno.EEXIST:
            io.rm(out)
            os.mkdir(out)
    debug('moving files')
    # moving files to the output directory
    for output_file, output_type in plugin.output_files:
        debug('f: %s' % output_file, 1)
        out_path = os.path.join(out, os.path.split(output_file)[1])
        io.mv(output_file, out)
        results.append({'is_file': True, 'path': out_path, 'type': output_type})

    # deleting plugin temporary files
    for todel in plugin.tmp_files:
        debug('deleting %s' % todel)
        shutil.rmtree(todel)

    # updating bioscript with the results
    URL(bioscript_callback).get_async(task_id=task_id, results=json.dumps(results))

    # callback
    if service_callback is not None:
        callback_service(service_callback, plugin_info['generated_id'], task_id, 'SUCCESS',
            results=json.dumps(results), additional=user_parameters)
Exemplo n.º 2
0
Arquivo: tasks.py Projeto: bbcf/bs
def plugin_job(user, plug, inputs_directory, outputs_directory, dwdfiles, plugin_info,
               user_parameters, service_callback, bioscript_callback, **form_parameters):
    

    debug('FETCHING FILES ... %s' % form_parameters)
    raised = False
    task_id = plugin_job.request.id
    try:
        # FETCHING FILES
        current_task.update_state(state='FETCHING FILES')
        inputs_directory = fetchurls(user, plug, dwdfiles, inputs_directory, form_parameters)

        debug('PLUGIN PROCESS STARTED ...')
        # PLUGIN PROCESS
        current_task.update_state(state='STARTED')
   
        try:
            debug('user params : %s' % user_parameters)
            user_parameters = json.loads(user_parameters)
        except TypeError as e:
            debug(e)
        

        if service_callback is not None:
            callback_service(service_callback, plugin_info['generated_id'], task_id, 'RUNNING', additional=user_parameters)

        debug('task launched user.name: %s, indir: %s, oudir: %s' % (user.name, inputs_directory, outputs_directory))
        # get plugin class
        plugin = operations.get_plugin_byId(plugin_info['generated_id'])
        if plugin is None:
            raise Exception('Plugin not found by the worker.')
        plugin.is_debug = DEBUG_PLUGINS

        debug('plugin operation start %s' % form_parameters)
        plugin._start_timer()
        results = []
        # call plugin with form parameters
        try:
            os.chdir(TMP_DIR)
            ret = plugin(**form_parameters)
            results = [{'is_file': False,
                        'value': ret}]
        except Exception as e:
            debug("ERROR %s" % e)
            util.print_traceback()
            if service_callback is not None:
                user_parameters.update({'error': str(e)})
                callback_service(service_callback, plugin_info['generated_id'], task_id, 'FAILED', additional=user_parameters)
            # deleting plugin temporary files
            for todel in plugin.tmp_files:
                debug('deleting %s' % todel)
                shutil.rmtree(todel, onerror=shutilerror)
            #debug('deleting %s' % outputs_directory)
            #shutil.rmtree(outputs_directory, onerror=shutilerror)
            if file_is_in_bs(TMP_DIR, inputs_directory):
                debug('deleting %s' % inputs_directory)
                shutil.rmtree(inputs_directory, onerror=shutilerror)

            if len(plugin.debug_stack) > 0:
                debug("Adding debug stack to error")
                debug_error = '\n [x] DEBUG STACK : %s' % '\n'.join([d for d in plugin.debug_stack])
                if not e.args:
                    e.args = ('',)
                e.args = (e.args[0] + debug_error,) + e.args[1:]
            raised = True
            raise

        # mkdir output directory
        out = os.path.join(outputs_directory, task_id)
        debug('mkdir out path : %s' % out)
        try:
            os.mkdir(out)
        except OSError, e:
            if e.errno == errno.EEXIST:
                io.rm(out)
                os.mkdir(out)
        debug('moving files')
        # moving files to the output directory
        for output_file, output_type in plugin.output_files:
            debug('f: %s to : %s' % (output_file, out))
            out_path = os.path.join(out, os.path.split(output_file)[1])
            io.mv(output_file, out)
            results.append({'is_file': True, 'path': out_path, 'type': output_type})

        # deleting plugin temporary files
        for todel in plugin.tmp_files:
            debug('deleting %s' % todel)
            shutil.rmtree(todel, onerror=shutilerror)
        if file_is_in_bs(TMP_DIR, inputs_directory):
                debug('deleting %s' % inputs_directory)
                shutil.rmtree(inputs_directory, onerror=shutilerror)

        # updating bioscript with the results
        debug('CALLBACK to %s for task %s' % (bioscript_callback, task_id))
        debug(cbbioscript(bioscript_callback, task_id, json.dumps(results)))
        debug("END")
        # callback
        if service_callback is not None:
            callback_service(service_callback, plugin_info['generated_id'], task_id, 'SUCCESS',
                results=json.dumps(results), additional=user_parameters)
Exemplo n.º 3
0
def plugin_job(user, plug, inputs_directory, outputs_directory, dwdfiles,
               plugin_info, user_parameters, service_callback,
               bioscript_callback, **form_parameters):

    debug('FETCHING FILES ... %s' % form_parameters)
    raised = False
    task_id = plugin_job.request.id
    try:
        # FETCHING FILES
        current_task.update_state(state='FETCHING FILES')
        inputs_directory = fetchurls(user, plug, dwdfiles, inputs_directory,
                                     form_parameters)

        debug('PLUGIN PROCESS STARTED ...')
        # PLUGIN PROCESS
        current_task.update_state(state='STARTED')

        try:
            debug('user params : %s' % user_parameters)
            user_parameters = json.loads(user_parameters)
        except TypeError as e:
            debug(e)

        if service_callback is not None:
            callback_service(service_callback,
                             plugin_info['generated_id'],
                             task_id,
                             'RUNNING',
                             additional=user_parameters)

        debug('task launched user.name: %s, indir: %s, oudir: %s' %
              (user.name, inputs_directory, outputs_directory))
        # get plugin class
        plugin = operations.get_plugin_byId(plugin_info['generated_id'])
        if plugin is None:
            raise Exception('Plugin not found by the worker.')
        plugin.is_debug = DEBUG_PLUGINS

        debug('plugin operation start %s' % form_parameters)
        plugin._start_timer()
        results = []
        # call plugin with form parameters
        try:
            os.chdir(TMP_DIR)
            ret = plugin(**form_parameters)
            results = [{'is_file': False, 'value': ret}]
        except Exception as e:
            debug("ERROR %s" % e)
            util.print_traceback()
            if service_callback is not None:
                user_parameters.update({'error': str(e)})
                callback_service(service_callback,
                                 plugin_info['generated_id'],
                                 task_id,
                                 'FAILED',
                                 additional=user_parameters)
            # deleting plugin temporary files
            for todel in plugin.tmp_files:
                debug('deleting %s' % todel)
                shutil.rmtree(todel, onerror=shutilerror)
            #debug('deleting %s' % outputs_directory)
            #shutil.rmtree(outputs_directory, onerror=shutilerror)
            if file_is_in_bs(TMP_DIR, inputs_directory):
                debug('deleting %s' % inputs_directory)
                shutil.rmtree(inputs_directory, onerror=shutilerror)

            if len(plugin.debug_stack) > 0:
                debug("Adding debug stack to error")
                debug_error = '\n [x] DEBUG STACK : %s' % '\n'.join(
                    [d for d in plugin.debug_stack])
                if not e.args:
                    e.args = ('', )
                e.args = (e.args[0] + debug_error, ) + e.args[1:]
            raised = True
            raise

        # mkdir output directory
        out = os.path.join(outputs_directory, task_id)
        debug('mkdir out path : %s' % out)
        try:
            os.mkdir(out)
        except OSError, e:
            if e.errno == errno.EEXIST:
                io.rm(out)
                os.mkdir(out)
        debug('moving files')
        # moving files to the output directory
        for output_file, output_type in plugin.output_files:
            debug('f: %s to : %s' % (output_file, out))
            out_path = os.path.join(out, os.path.split(output_file)[1])
            io.mv(output_file, out)
            results.append({
                'is_file': True,
                'path': out_path,
                'type': output_type
            })

        # deleting plugin temporary files
        for todel in plugin.tmp_files:
            debug('deleting %s' % todel)
            shutil.rmtree(todel, onerror=shutilerror)
        if file_is_in_bs(TMP_DIR, inputs_directory):
            debug('deleting %s' % inputs_directory)
            shutil.rmtree(inputs_directory, onerror=shutilerror)

        # updating bioscript with the results
        debug('CALLBACK to %s for task %s' % (bioscript_callback, task_id))
        debug(cbbioscript(bioscript_callback, task_id, json.dumps(results)))
        debug("END")
        # callback
        if service_callback is not None:
            callback_service(service_callback,
                             plugin_info['generated_id'],
                             task_id,
                             'SUCCESS',
                             results=json.dumps(results),
                             additional=user_parameters)