Esempio n. 1
0
 def test_complete_job(self):
     httpretty.register_uri(
         httpretty.POST,
         "https://test_server.com/qiita_db/jobs/example-job/complete/",
         body='{"success": true, "error": ""}'
     )
     job_id = "example-job"
     payload = {
         'success': True, 'error': '',
         'artifacts': [
             {'artifact_type': "Demultiplexed",
              'filepaths': [("fp1", "preprocessed_fasta"),
                            ("fp2", "preprocessed_fastq")],
              'can_be_submitted_to_ebi': True,
              'can_be_submitted_to_vamps': True}]}
     complete_job(self.qclient, job_id, payload)
Esempio n. 2
0
def execute_job(server_url, job_id, output_dir):
    """Starts the plugin and executes the assigned task

    Parameters
    ----------
    server_url : str
        The url of the server
    job_id : str
        The job id

    Raises
    ------
    RuntimeError
        If there is a problem gathering the job information
    """
    qclient = QiitaClient(server_url)
    # Request job information
    job_info = qclient.get("/qiita_db/jobs/%s" % job_id)
    # Check if we have received the job information so we can start it
    if job_info and job_info['success']:
        # Starting the heartbeat
        start_heartbeat(qclient, job_id)
        # Execute the given task
        task_name = job_info['command']
        task = TASK_DICT[task_name]

        if not exists(output_dir):
            makedirs(output_dir)
        try:
            payload = task(qclient, job_id, job_info['parameters'],
                           output_dir)
        except Exception:
            exc_str = repr(traceback.format_exception(*sys.exc_info()))
            error_msg = ("Error executing %s:\n%s" % (task_name, exc_str))
            payload = format_payload(False, error_msg=error_msg)
        # The job completed
        complete_job(qclient, job_id, payload)
    else:
        raise RuntimeError("Can't get job (%s) information" % job_id)
Esempio n. 3
0
def execute_job(server_url, job_id, output_dir):
    """Starts the plugin and executes the assigned task

    Parameters
    ----------
    server_url : str
        The url of the server
    job_id : str
        The job id

    Raises
    ------
    RuntimeError
        If there is a problem gathering the job information
    """
    qclient = QiitaClient(server_url)
    # Request job information
    job_info = qclient.get("/qiita_db/jobs/%s" % job_id)
    # Check if we have received the job information so we can start it
    if job_info and job_info['success']:
        # Starting the heartbeat
        start_heartbeat(qclient, job_id)
        # Execute the given task
        task_name = job_info['command']
        task = TASK_DICT[task_name]

        if not exists(output_dir):
            makedirs(output_dir)
        try:
            payload = task(qclient, job_id, job_info['parameters'], output_dir)
        except Exception:
            exc_str = repr(traceback.format_exception(*sys.exc_info()))
            error_msg = ("Error executing %s:\n%s" % (task_name, exc_str))
            payload = format_payload(False, error_msg=error_msg)
        # The job completed
        complete_job(qclient, job_id, payload)
    else:
        raise RuntimeError("Can't get job (%s) information" % job_id)