def _run(self): if os.path.exists(self._output_file_path): self._set_completion_state(TaskState.SUCCESS) return TaskState.SUCCESS status = super(LocalFSPersistentTask, self)._run() assert self.completed if status == TaskState.SUCCESS: base.touch(self._output_file_path) return status
def test_touch(self): path = base.random_alpha_num_word(16) try: self.assertFalse(os.path.exists(path)) base.touch(path) self.assertTrue(os.path.exists(path)) base.touch(path) self.assertTrue(os.path.exists(path)) finally: base.remove(path)
def testPersistentTaskNoRunIfFile(self): """Persistent task does not run if output file already exists.""" class PTask(workflow.LocalFSPersistentTask): def run(self): return self.FAILURE flow = workflow.Workflow() file_path = base.random_alpha_num_word(16) base.touch(file_path) try: task = PTask(output_file_path=file_path, task_id="task", workflow=flow) flow.build() self.assertTrue(os.path.exists(file_path)) self.assertTrue(flow.process()) self.assertTrue(os.path.exists(file_path)) finally: base.remove(file_path)
def testPersistentTaskNoRunIfFile(self): """Persistent task does not run if output file already exists.""" class PTask(workflow.LocalFSPersistentTask): def run(self): return self.FAILURE flow = workflow.Workflow() file_path = base.random_alpha_num_word(16) base.touch(file_path) try: task = PTask( output_file_path=file_path, task_id='task', workflow=flow, ) flow.build() self.assertTrue(os.path.exists(file_path)) self.assertTrue(flow.process()) self.assertTrue(os.path.exists(file_path)) finally: base.remove(file_path)