Analyze state and queue tasks.
199621
def scan(self):
        """"""

        log.debug("scanning machine: %s..." % self.name)

        deployed = set()
        services = yield self.client.get_children(self.path + "/services")

        for name in services:
            log.debug("checking service: '%s'..." % name)

            try:
                value, metadata = yield self.client.get(
                    self.path + "/services/" + name + "/machines"
                    )
            except NoNodeException:
                log.warn(
                    "missing machines declaration for service: %s." %
                    name
                    )
                machines = []
            else:
                machines = json.loads(value)

            if machines:
                log.debug("machines: %s." % ", ".join(machines))

                if self.name in machines:
                    deployed.add(name)
            else:
                log.debug("service not configured for any machine.")

        count = len(deployed)
        log.debug("found %d service(s) configured for this machine." % count)

        running = yield self.client.get_children(
            self.path + "/machines/" + self.name
            )

        self.stopped = deployed - set(running)

        if self.stopped:
            log.debug("services not running: %s." % ", ".join(
                map(repr, self.stopped)))
        elif running:
            log.debug("all services are up.")
1051688
def todo_tasks(self):
        """"""
        tasks = [task for task in self.all_tasks if task._state == NewTask._PENDING]
        return tasks
538611
def examine(self):
        """"""
        if self._changes:
            return self._changes.pop()

        # clean filepath
        self.filepath = None
        delays = set()
        for path in self._tasks:
            item = self._tasks[path]
            if self.is_changed(path, item['ignore']):
                func = item['func']
                delay = item['delay']
                if delay and isinstance(delay, float):
                    delays.add(delay)
                if func:
                    name = getattr(func, 'name', None)
                    if not name:
                        name = getattr(func, '__name__', 'anonymous')
                    logger.info(
                        "Running task: {} (delay: {})".format(name, delay))
                    func()

        if delays:
            delay = max(delays)
        else:
            delay = None
        return self.filepath, delay
635629
def inspect_periodic_tasks(self) -> List[Tuple[int, str]]:
        
        return [(int(e[0]), e[3][0].name) for e in self._scheduler.queue]
124356
def view_all_work_queues():
    """"""
    count_list = list(
        db.session.query(
            work_queue.WorkQueue.queue_name,
            work_queue.WorkQueue.status,
            func.count(work_queue.WorkQueue.task_id))
        .group_by(work_queue.WorkQueue.queue_name,
                  work_queue.WorkQueue.status))

    queue_dict = {}
    for name, status, count in count_list:
        queue_dict[(name, status)] = dict(
            name=name, status=status, count=count)

    max_created_list = list(
        db.session.query(
            work_queue.WorkQueue.queue_name,
            work_queue.WorkQueue.status,
            func.max(work_queue.WorkQueue.created))
        .group_by(work_queue.WorkQueue.queue_name,
                  work_queue.WorkQueue.status))

    for name, status, newest_created in max_created_list:
        queue_dict[(name, status)]['newest_created'] = newest_created

    min_eta_list = list(
        db.session.query(
            work_queue.WorkQueue.queue_name,
            work_queue.WorkQueue.status,
            func.min(work_queue.WorkQueue.eta))
        .group_by(work_queue.WorkQueue.queue_name,
                  work_queue.WorkQueue.status))

    for name, status, oldest_eta in min_eta_list:
        queue_dict[(name, status)]['oldest_eta'] = oldest_eta

    queue_list = list(queue_dict.values())
    queue_list.sort(key=lambda x: (x['name'], x['status']))

    context = dict(
        queue_list=queue_list,
    )
    return render_template('view_work_queue_index.html', **context)
421959
def run(self):
        '''
        '''
        if self.verbose:
            pbar = tqdm(total=100)
        while True:
            task_remain = self._task_queue.qsize()
            task_finished = int((float(self.total_task - task_remain) /
                                 float(self.total_task)) * 100)
            if task_finished % 20 == 0 and task_finished != self.current_state:
                self.current_state = task_finished
                logger.info('{0}% done'.format(task_finished))
                if self.verbose and task_finished > 0:
                    pbar.update(20)
            if task_remain == 0:
                break
        logger.debug('All task data cleared')
356747
def get_state(self):
        """"""
        return {"started": (True if self.background_process and
                            self.background_process.is_alive() else False),
                "paused": self._pause.value,
                "stopped": self._end.value,
                "tasks": len(self.current_tasks),
                "busy_tasks": len(self.busy_tasks),
                "free_tasks": len(self.free_tasks)}
788235
function(state)
  {
    console.log('# Started batch process\n');
    console.log('## Initial State:\n');
    console.log('```');
    console.log(JSON.stringify(sortKeys(state), null, 2));
    console.log('```');
    console.log('\n## Execution\n');
  }
889402
def filter_tasks(self, request, context):
        """"""
        _log_request(request, context)
        tasks_pattern, tasks_negate = PATTERN_PARAMS_OP(request.tasks_filter)
        state_pattern = request.state_pattern
        limit, reverse = request.limit, request.reverse

        pregex = re.compile(tasks_pattern)  # pattern filter condition
        sregex = re.compile(state_pattern)  # state filter condition

        def pcondition(task):
            return accepts(pregex, tasks_negate, task.name, task.routing_key)

        def scondition(task):
            return accepts(sregex, tasks_negate, task.state)

        found_tasks = (task for _, task in
                       self.listener.memory.tasks_by_time(limit=limit or None,
                                                          reverse=reverse)
                       if pcondition(task) and scondition(task))

        def callback(t):
            logger.debug('%s iterated %d tasks in %s (%s)', self.filter_tasks.__name__,
                         t.count, t.duration_human, t.throughput_human)

        for task in about_time(callback, found_tasks):
            yield ClearlyServer._event_to_pb(task)[1]
631943
public static void analyze(
      VisitorState state, LockEventListener listener, Predicate<Tree> isSuppressed) {
    HeldLockSet locks = HeldLockSet.empty();
    locks = handleMonitorGuards(state, locks);
    new LockScanner(state, listener, isSuppressed).scan(state.getPath(), locks);
  }
578230
def dequeue
      _, line = RRRSpec.redis.blpop(STATISTICS_UPDATER_QUEUE_KEY, 0)
      request = JSON.parse(line)

      [Taskset.new(request['taskset']), request['recalculate']]
    end
536968
def _analyze_state(state: GlobalState):
    
    instruction = state.get_current_instruction()

    annotations = cast(
        List[MultipleSendsAnnotation],
        list(state.get_annotations(MultipleSendsAnnotation)),
    )
    if len(annotations) == 0:
        log.debug("Creating annotation for state")
        state.annotate(MultipleSendsAnnotation())
        annotations = cast(
            List[MultipleSendsAnnotation],
            list(state.get_annotations(MultipleSendsAnnotation)),
        )

    calls = annotations[0].calls

    if instruction["opcode"] in ["CALL", "DELEGATECALL", "STATICCALL", "CALLCODE"]:
        call = get_call_from_state(state)
        if call:
            calls += [call]

    else:  # RETURN or STOP
        if len(calls) > 1:

            description_tail = (
                "Consecutive calls are executed at the following bytecode offsets:\n"
            )

            for call in calls:
                description_tail += "Offset: {}\n".format(
                    call.state.get_current_instruction()["address"]
                )

            description_tail += (
                "Try to isolate each external call into its own transaction,"
                " as external calls can fail accidentally or deliberately.\n"
            )

            issue = Issue(
                contract=state.environment.active_account.contract_name,
                function_name=state.environment.active_function_name,
                address=instruction["address"],
                swc_id=MULTIPLE_SENDS,
                bytecode=state.environment.code.bytecode,
                title="Multiple Calls in a Single Transaction",
                severity="Medium",
                description_head="Multiple sends are executed in one transaction.",
                description_tail=description_tail,
                gas_used=(state.mstate.min_gas_used, state.mstate.max_gas_used),
            )

            return [issue]

    return []
1098150
def check_urls (urlqueue, logger):
    """"""
    while not urlqueue.empty():
        url_data = urlqueue.get()
        try:
            check_url(url_data, logger)
        finally:
            urlqueue.task_done(url_data)
627252
def _run(cls):
        """"""
        if cls._thread:
            with cls._lock:
                # First run: execute each task once to get it started
                for task in cls.tasks:
                    cls._execute_task(task)
                cls.tasks.sort()
                cls._last_execution = time.time()

        while cls._thread:
            with cls._lock:
                if cls.tasks:
                    for task in cls.tasks:
                        if task.next_execution - cls._last_execution < 0.5:
                            cls._execute_task(task)
                        else:
                            break
                    cls.tasks.sort()
                    cls._last_execution = time.time()
                    cls._sleep_delay = cls.tasks[0].next_execution - cls._last_execution

                else:
                    cls._sleep_delay = 1

                sleep_delay = max(0.1, cls._sleep_delay)

            # Don't hold cls._lock while sleeping, sleep delay should be 1 second when no tasks are present
            time.sleep(sleep_delay)
455757
def _analyze(self):
        """"""
        self._analyze_start_time = time.time()
        self._clear_ui()
        try:
            self._analysis_process.terminate()  # clear anything existing
        except AttributeError:  # there wasn't actually a process
            pass
        # self._analysis_process = _AsyncReadyFunction(self._analysis_function,
        #                                              None, 'async_results_q')
        out_q = mp.Queue()
        self._analysis_process = mp.Process(target=self._analysis_function,
                                            kwargs={'async_results_q': out_q})
        setattr(self._analysis_process, 'out_q', out_q)
        self._analysis_process.start()
        self._base.after(self._POLL_PERIOD_MILLISECONDS,
                         self._scheduled_check_for_summaries)
        self._update_notification('Analyzing the on-screen game.')
112024
def analyze(self, args):
        
        self.log.info("Running catalog analysis")

        if args.count:
            self.count()

        return
94149
private void checkQueue() {
        if (LOG) {
            Log.d(TAG, "- Checking queue");
        }

        int activeDownloads = 0;
        for (QueueItem queueItem : queue) {
            if (queueItem.isStarted) {
                activeDownloads++;
            }
        }

        if (activeDownloads >= SIM_MAX_DOWNLOADS) {
            if (LOG) {
                Log.d(TAG, "- Already have max number of simultaneous downloads");
            }
            return;
        }

        QueueItem pendingQueue = null;
        for (QueueItem queueItem : queue) {
            if (!queueItem.isStarted && !queueItem.isStopped) {
                pendingQueue = queueItem;
                break;
            }
        }
        if (pendingQueue == null) {
            if (LOG) {
                Log.d(TAG, "- No work for downloading");
            }
            return;
        }
        if (LOG) {
            Log.d(TAG, "- Starting download file #" + pendingQueue.fileReference.getFileId());
        }

        pendingQueue.isStarted = true;

        final QueueItem finalPendingQueue = pendingQueue;
        pendingQueue.taskRef = system().actorOf(Props.create(() -> new DownloadTask(finalPendingQueue.fileReference, self(), context())).changeDispatcher("heavy"), "actor/download/task_" + RandomUtils.nextRid());
    }