Пример #1
0
def check_htcondor_max_runtime(specification):
    """Check if the field htcondor_max_runtime has a valid input.

    :param reana_specification: reana specification of workflow.
    """
    check_pass = True
    steps_with_max_runtime = (step for step in specification["steps"]
                              if step.get("htcondor_max_runtime", False))
    for i, step in enumerate(steps_with_max_runtime):
        htcondor_max_runtime = step["htcondor_max_runtime"]
        if (not str.isdigit(htcondor_max_runtime)
                and htcondor_max_runtime not in HTCONDOR_JOB_FLAVOURS):
            check_pass = False
            click.secho(
                "In step {0}:\n'{1}' is not a valid input for htcondor_max_runtime. Inputs must be a digit in the form of a string, or one of the following job flavours: '{2}'."
                .format(
                    step.get("name", i),
                    htcondor_max_runtime,
                    "' '".join([
                        k for k, v in sorted(HTCONDOR_JOB_FLAVOURS.items(),
                                             key=lambda key: key[1])
                    ]),
                ),
                fg="red",
            )
    return check_pass
 def execute(self):
     """Execute / submit a job with HTCondor."""
     os.chdir(self.workflow_workspace)
     job_ad = classad.ClassAd()
     job_ad["JobDescription"] = (
         self.workflow.get_full_workflow_name() + "_" + self.job_name
     )
     job_ad["JobMaxRetries"] = 3
     job_ad["LeaveJobInQueue"] = classad.ExprTree(
         "(JobStatus == 4) && ((StageOutFinish =?= UNDEFINED) || "
         "(StageOutFinish == 0))"
     )
     job_ad["Cmd"] = (
         "./job_wrapper.sh"
         if not self.unpacked_img
         else "./job_singularity_wrapper.sh"
     )
     if not self.unpacked_img:
         job_ad["Arguments"] = self._format_arguments()
         job_ad["DockerImage"] = self.docker_img
         job_ad["WantDocker"] = True
     job_ad["Environment"] = self._format_env_vars()
     job_ad["Out"] = classad.ExprTree(
         'strcat("reana_job.", ClusterId, ".", ProcId, ".out")'
     )
     job_ad["Err"] = classad.ExprTree(
         'strcat("reana_job.", ClusterId, ".", ProcId, ".err")'
     )
     job_ad["log"] = classad.ExprTree('strcat("reana_job.", ClusterId, ".err")')
     job_ad["ShouldTransferFiles"] = "YES"
     job_ad["WhenToTransferOutput"] = "ON_EXIT"
     job_ad["TransferInput"] = self._get_input_files()
     job_ad["TransferOutput"] = "."
     job_ad["PeriodicRelease"] = classad.ExprTree("(HoldReasonCode == 35)")
     if self.htcondor_max_runtime in HTCONDOR_JOB_FLAVOURS.keys():
         job_ad["JobFlavour"] = self.htcondor_max_runtime
     elif str.isdigit(self.htcondor_max_runtime):
         job_ad["MaxRunTime"] = int(self.htcondor_max_runtime)
     else:
         job_ad["MaxRunTime"] = 3600
     if self.htcondor_accounting_group:
         job_ad["AccountingGroup"] = self.htcondor_accounting_group
     future = current_app.htcondor_executor.submit(self._submit, job_ad)
     clusterid = future.result()
     return clusterid