def test_persisted_change(): app = MyApplication() task = RetryableTask(app) # task.execution.state = 'RUNNING' # This is supposed to alter the state of the task # thus mark it as 'changed' task.update_state() # We expect task.changed to be true assert task.changed
def new_tasks(self, extra): # use the name of the executable as job name basename = os.path.basename(self.params.cmd) # fix an ordering of the subst parameters, independent of any runtime variable names = sorted(self.subst.iterkeys()) inputs = {} # decide whether CMD indicates a local file or a command # to be searched on the remote systems' PATH if os.path.exists(self.params.cmd): self.log.info("Uploading local file '%s' as executable.", self.params.cmd) gc3libs.utils.check_file_access(self.params.cmd, os.R_OK | os.X_OK) executable = './' + os.path.basename(self.params.cmd) inputs[os.path.abspath(self.params.cmd)] = os.path.basename( self.params.cmd) else: if not os.path.isabs(self.params.cmd): raise RuntimeError( "You cannot execute a command by calling a relative path," " because the remote execution directory is empty" " except for files we upload there; but there is" " no file named '%s' here, so I don't know what to upload.", self.params.cmd) executable = self.params.cmd # create a set of input files for each combination of the # substitution parameters for values in itertools.product(*(self.subst[name] for name in names)): subst = dict((name, value) for name, value in zip(names, values)) jobname = str.join( '_', [basename] + [("%s=%s" % (name, value.translate(None, r'\/&|=%$#!?<>()`"' + r"'" + '\a\b\n\r'))) for name, value in subst.iteritems()]) # construct argument list, substituting defined parameters arguments = [executable] for arg in self.params.args: if arg in subst: arguments.append(subst[arg]) else: arguments.append(arg) extra_args = extra.copy() extra_args['outputs'] = gc3libs.ANY_OUTPUT extra_args['output_dir'] = self.make_directory_path( self.params.output, jobname) extra_args['stdout'] = jobname + '.stdout.txt' extra_args['stderr'] = jobname + '.stderr.txt' if self.params.retry is not None: yield RetryableTask(SmartApplication(arguments, inputs, **extra_args), self.params.retry, jobname=jobname, **extra_args) else: yield SmartApplication(arguments, inputs, jobname=jobname, **extra_args)