Пример #1
0
    def test_f(self):
        cwd = os.getcwd()
        recipe_test_dir = os.path.join(gs.TEST_DIR, 'recipe/task')
        with execute_in_dir(recipe_test_dir):
            self.assertEqual(os.path.join(cwd, recipe_test_dir), os.getcwd())
        self.assertEqual(cwd, os.getcwd())

        try:
            with execute_in_dir(recipe_test_dir):
                self.assertEqual(os.path.join(cwd, recipe_test_dir), os.getcwd())
                assert(False)
        except:
            self.assertEqual(cwd, os.getcwd())
        self.assertEqual(cwd, os.getcwd())
Пример #2
0
    def run(self, task_id, resume_job=False, logging_thread=None):
        """
        This function is executed to run this job.

        :param int task_id:
        :param bool resume_job:
        :param sisyphus.worker.LoggingThread logging_thread:
        """

        logging.debug("Task name: %s id: %s" % (self.name(), task_id))
        job = self._job

        logging.info("Start Job: %s Task: %s" % (job, self.name()))
        logging.info("Inputs:")
        for i in self._job._sis_inputs:
            logging.info(str(i))

            # each input must be at least X seconds old
            # if an input file is too young it's may not synced in a network filesystem yet
            try:
                input_age = time.time() - os.stat(i.get_path()).st_mtime
                time.sleep(max(0, gs.WAIT_PERIOD_MTIME_OF_INPUTS - input_age))
            except FileNotFoundError:
                logging.warning('Input path does not exist: %s' % i.get_path())

            if i.creator and gs.ENABLE_LAST_USAGE:
                # mark that input was used
                try:
                    os.unlink(
                        os.path.join(i.creator, gs.JOB_LAST_USER,
                                     os.getlogin()))
                except OSError as e:
                    if e.errno not in (2, 13):
                        # 2: file not found
                        # 13: permission denied
                        raise e

                try:
                    user_path = os.path.join(i.creator, gs.JOB_LAST_USER,
                                             os.getlogin())
                    os.symlink(os.path.abspath(job._sis_path()), user_path)
                    os.chmod(user_path, 0o775)
                except OSError as e:
                    if e.errno not in (2, 13, 17):
                        # 2: file not found
                        # 13: permission denied
                        # 17: file exists
                        raise e

        tools.get_system_informations(sys.stdout)

        sys.stdout.flush()

        try:
            if resume_job:
                if self._resume is not None:
                    task = self._resume
                else:
                    task = self._start
                    logging.warning(
                        'No resume function set (changed tasks after job was initialized?) '
                        'Fallback to normal start function: %s' % task)
            else:
                task = self._start
            assert task is not None, "Error loading task"
            # save current directory and change into work directory
            with tools.execute_in_dir(self.path(gs.JOB_WORK_DIR)):
                f = getattr(self._job, task)

                # get job arguments
                for arg_id in self._get_arg_idx_for_task_id(task_id):
                    args = self._args[arg_id]
                    if not isinstance(args, (list, tuple)):
                        args = [args]
                    logging.info("-" * 60)
                    logging.info("Starting subtask for arg id: %d args: %s" %
                                 (arg_id, str(args)))
                    logging.info("-" * 60)
                    f(*args)
        except sp.CalledProcessError as e:
            if e.returncode == 137:
                # TODO move this into engine class
                logging.error(
                    "Command got killed by SGE (probably out of memory):")
                logging.error("Cmd: %s" % e.cmd)
                logging.error("Args: %s" % str(e.args))
                logging.error("Return-Code: %s" % e.returncode)
                logging_thread.out_of_memory = True
                logging_thread.stop()
            else:
                logging.error("Executed command failed:")
                logging.error("Cmd: %s" % e.cmd)
                logging.error("Args: %s" % str(e.args))
                logging.error("Return-Code: %s" % e.returncode)
                logging_thread.stop()
                self.error(task_id, True)
        except Exception as e:
            # Job failed
            logging.error("Job failed, traceback:")
            sys.excepthook(*sys.exc_info())
            logging_thread.stop()
            self.error(task_id, True)
            # TODO handle failed job
        else:
            # Job finished normally
            logging_thread.stop()
            if not self.continuable:
                self.finished(task_id, True)
            sys.stdout.flush()
            sys.stderr.flush()
            logging.info("Job finished successful")
Пример #3
0
 def test_run(self):
     with execute_in_dir(TEST_DIR):
         from recipe.task.test import Test
         job = Test(text=Path("input_text.gz"))
         job._sis_setup_directory()