Invokes a task.

 @param [Symbol] task
   The name of the task to run.

 @param [Shell] shell
   The shell to run the task in.

 @raise [RuntimeError]
   The task name was not known.

 @since 0.5.0
320212
def invoke_task(task,shell)
      unless TASKS.include?(task)
        raise("invalid task: #{task}")
      end

      if @before.has_key?(task)
        @before[task].each { |command| shell.exec(command) }
      end

      send(task,shell) if respond_to?(task)

      if @after.has_key?(task)
        @after[task].each { |command| shell.exec(command) }
      end
    end
1255500
function(task) {
  task.error = false;
  task.state = sStateTable[task.state][START];
  setTimeout(function() {
    if(task.state === RUNNING) {
      task.swapTime = +new Date();
      task.run(task);
      runNext(task, 0);
    }
  }, 0);
}
693714
def queue_task
      if @task.job_class.instance_method(:perform).arity.zero?
        @task.job_class.send(perform_method)
      else
        @task.job_class.send(perform_method, @scheduled_time.to_i)
      end
    end
890550
async def run_async_task(self, container, asynctask, newthread = True):
        ""
        e = TaskEvent(self, async_task = asynctask, newthread = newthread)
        await container.wait_for_send(e)
        ev = await TaskDoneEvent.createMatcher(e)
        if hasattr(ev, 'exception'):
            raise ev.exception
        else:
            return ev.result
289668
def run(argv)
      load_tasks

      return build_task(argv).run unless argv.empty?

      print_help_header
      print_help_body
    end
623795
def invoke(command, params={})
      command_string = compile_command(command, params)
      output_command(command_string)
      execute(command_string, params)
    end
719543
async def start_task(self, task: Task) -> None:
        ''''''

        try:
            Log.debug('task %s starting', task.name)
            before = time.time()
            task.counters['last_run'] = before

            task.running = True
            self.running_tasks.add(task)
            await task.run_task()
            Log.debug('task %s completed', task.name)

        except CancelledError:
            Log.debug('task %s cancelled', task.name)

        except Exception:
            Log.exception('unhandled exception in task %s', task.name)

        finally:
            self.running_tasks.discard(task)
            task.running = False
            task.task = None

            after = time.time()
            total = after - before
            task.counters['last_completed'] = after
            task.counters['duration'] = total
842958
def invoke_task(task, args):
    
    parser, proxy_args = get_task_parser(task)
    if proxy_args:
        return task(*args)
    else:
        pargs = parser.parse_args(args)
        return task(**vars(pargs))
459046
def run
      until @confirmed
        @namespace = capture_selection(
          title: 'Avalable Task Groups:',
          options: build_namespace_options
        )

        @task = capture_selection(
          title: "Available '#{@namespace}' commands:",
          options: build_task_options
        )

        unless @task.arg_names.empty?
          @task_arguments = @task.arg_names.each_with_object({}) { |arg, obj| obj[arg] = nil }
          capture_task_arguments while @task_arguments.values.any?(&:nil?)
        end

        @confirmed = capture_confirmation
      end

      # Invoke ensures that prerequirement tasks like rails :environment are run first.
      @task.invoke(*@task_arguments.values)
    end
530092
def execute(self, env, args):
        

        task_name = args.task_name
        clone_task = args.clone_task

        if not env.task.create(task_name, clone_task):
            raise errors.FocusError(u'Could not create task "{0}"'
                                    .format(task_name))

        # open in task config in editor
        if not args.skip_edit:
            task_config = env.task.get_config_path(task_name)

            if not _edit_task_config(env, task_config, confirm=True):
                raise errors.FocusError(u'Could not open task config: {0}'
                                        .format(task_config))
562485
def _run_task_internal(self, task):
        '''  '''

        hosts = self._list_available_hosts()
        self.inventory.restrict_to(hosts)

        runner = cirruscluster.ext.ansible.runner.Runner(
            pattern=task.play.hosts, inventory=self.inventory, module_name=task.module_name,
            module_args=task.module_args, forks=self.forks,
            remote_pass=self.remote_pass, module_path=self.module_path,
            timeout=self.timeout, remote_user=task.play.remote_user,
            remote_port=task.play.remote_port, module_vars=task.module_vars,
            private_key_file=self.private_key_file,
            private_key=self.private_key,
            setup_cache=self.SETUP_CACHE, basedir=task.play.basedir,
            conditional=task.only_if, callbacks=self.runner_callbacks,
            sudo=task.sudo, sudo_user=task.sudo_user,
            transport=task.transport, sudo_pass=task.sudo_pass, is_playbook=True
        )

        if task.async_seconds == 0:
            results = runner.run()
        else:
            results, poller = runner.run_async(task.async_seconds)
            self.stats.compute(results)
            if task.async_poll_interval > 0:
                # if not polling, playbook requested fire and forget, so don't poll
                results = self._async_poll(poller, task.async_seconds, task.async_poll_interval)

        contacted = results.get('contacted',{})
        dark      = results.get('dark', {})

        self.inventory.lift_restriction()

        if len(contacted.keys()) == 0 and len(dark.keys()) == 0:
            return None

        return results
120004
public <T> T execute(Task<T> task) {
        synchronized(task) {
            task.reset();
            // add it to the tail
            taskList.add(task);

            // invoke the execution
            lock.activate();

            // wait for the completion
            try {
            	while (!task.isDone()) {
            		task.wait();
            	}
            } catch (InterruptedException e) {
                task.exception = e; // we got interrupted, so task.result will be invalid! 
            }

            if(task.exception!=null) {
                Throwable e = task.exception;
                task.exception = null;
                throw new ExecutionException(e);
            } else {
                T r = task.result;
                task.result = null;
                return r;
            }
        }
    }
1040980
void registerTaskEnded(Task task) {
        synchronized (m_activeTasks) {
            String mapKey = createMapKey(task.getTenant(), task.getTaskID());
            if (m_activeTasks.remove(mapKey) == null) {
                m_logger.warn("Task {} registered as ended but was not running", mapKey);
            }
        }
    }
1201982
async def run_task(self) -> None:
        ''''''

        self.last_run = 0.0
        self.target = self.time() + self.DELAY

        while self.running:
            try:
                now = self.time()

                if now < self.target:
                    sleep = self.target - now
                    await self.sleep(sleep)

                elif self.last_run < self.target:
                    Log.debug('executing timer task %s', self.name)
                    self.last_run = self.time()
                    await self.run()
                    total = self.time() - self.last_run
                    Log.debug('finished timer task %s in %.1f seconds',
                              self.name, total)

                else:
                    sleep = min(5.0, self.DELAY)
                    await self.sleep(sleep)

            except CancelledError:
                Log.debug('cancelled timer task %s', self.name)
                raise

            except Exception:
                Log.exception('exception in timer task %s', self.name)
677817
private Object performTask(Task task) {

        Throwable reason = null;
        try {
            // Have to call fireTestStared/fireTestFinished via reflection as they unfortunately have protected access in Project
            final Method fireTaskStarted = Project.class.getDeclaredMethod("fireTaskStarted", Task.class);
            fireTaskStarted.setAccessible(true);
            fireTaskStarted.invoke(project, task);

            Object realThing;
            realThing = task;
            task.maybeConfigure();
            if (task instanceof UnknownElement) {
                realThing = ((UnknownElement) task).getRealThing();
            }

            DispatchUtils.execute(task);

            return realThing != null ? realThing : task;
        }
        catch (BuildException ex) {
            if (ex.getLocation() == Location.UNKNOWN_LOCATION) {
                ex.setLocation(task.getLocation());
            }
            reason = ex;
            throw ex;
        }
        catch (Exception ex) {
            reason = ex;
            BuildException be = new BuildException(ex);
            be.setLocation(task.getLocation());
            throw be;
        }
        catch (Error ex) {
            reason = ex;
            throw ex;
        }
        finally {
            try {
                final Method fireTaskFinished = Project.class.getDeclaredMethod("fireTaskFinished", Task.class, Throwable.class);
                fireTaskFinished.setAccessible(true);
                fireTaskFinished.invoke(project, task, reason);
            }
            catch (Exception e) {
                BuildException be = new BuildException(e);
                be.setLocation(task.getLocation());
                throw be;
            }
        }
    }
1327510
def execute_tasks(self):
        
        for t in self.tasks:
            print('RUNNING ' + str(t.task_id) + ' = ' + t.name)
            t.execute()
            if t.success != '__IGNORE__RESULT__':
                print(t)
                print('TASK RESULT :', t.result, ' but success = ' , t.success )
                if t.result != t.success:
                    #raise Exception('Project execution failed at task ' + str(t.task_id) + ' = ' + t.name)
                    print('ABORTING TASK EXECUTION SEQUENCE'  + str(t.task_id) + ' = ' + t.name)
                    break
1208612
def _comp_task(inbox, args, kwargs):
    
    # Note. this function uses a global variable which must be defined on the 
    # remote host.
    for func, args, kwargs in itertools.izip(TASK, args, kwargs):
        inbox = (func(inbox, *args, **kwargs),)
    return inbox[0]