Checks the api endpoint to check if the async job progress
174477
def _request_status(self):
        
        if self.item_id:
            return True

        response = self.con.get(self.monitor_url)
        if not response:
            return False

        data = response.json()

        self.status = data.get('status', 'inProgress')
        self.completion_percentage = data.get(self._cc('percentageComplete'),
                                              0)
        self.item_id = data.get(self._cc('resourceId'), None)

        return self.item_id is not None
100332
def finished(cls, jobid):
        """"""
        output = subprocess.check_output(
            [SACCT, '-n', '-X', '-o', "end", '-j', str(jobid)]
        )
        end = output.strip().decode()
        return end not in {'Unknown', ''}
117429
function (result) {
		item.done = true;
		
		// clear timeout if any
		if (timeout_trigger) {
			clearTimeout(timeout_trigger);
			timeout_trigger = undefined;
		}
		
		if (result === false) {
			that.all_passed = false;
			
			// ready to stop if this job is a showstopper
			if (item.keep === false)
				return that.done();
		}
		that.curr++;
		that.next();
	}
977756
def isRunning(self, serviceJobNode):
        
        return (not self.jobStore.fileExists(serviceJobNode.startJobStoreID)) and self.isActive(serviceJobNode)
110867
def check():
    
    t = time.time()
    results = Client(BASE_URL).version()
    print("Endpoint", BASE_URL)
    print("Response Time %0.2f" % (time.time() - t))
    print("Headers")
    for k, v in results.headers.items():
        print(" %s: %s" % (k, v))
    print("Body")
    print(results.text)
860197
function checkLoaded() {
            var waitInterval = config.waitSeconds * 1000,
                //It is possible to disable the wait interval by using waitSeconds of 0.
                expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
                noLoads = "", hasLoadedProp = false, stillLoading = false, prop,
                err, manager;

            //If there are items still in the paused queue processing wait.
            //This is particularly important in the sync case where each paused
            //item is processed right away but there may be more waiting.
            if (context.pausedCount > 0) {
                return undefined;
            }

            //Determine if priority loading is done. If so clear the priority. If
            //not, then do not check
            if (config.priorityWait) {
                if (isPriorityDone()) {
                    //Call resume, since it could have
                    //some waiting dependencies to trace.
                    resume();
                } else {
                    return undefined;
                }
            }

            //See if anything is still in flight.
            for (prop in loaded) {
                if (!(prop in empty)) {
                    hasLoadedProp = true;
                    if (!loaded[prop]) {
                        if (expired) {
                            noLoads += prop + " ";
                        } else {
                            stillLoading = true;
                            break;
                        }
                    }
                }
            }

            //Check for exit conditions.
            if (!hasLoadedProp && !context.waitCount) {
                //If the loaded object had no items, then the rest of
                //the work below does not need to be done.
                return undefined;
            }
            if (expired && noLoads) {
                //If wait time expired, throw error of unloaded modules.
                err = makeError("timeout", "Load timeout for modules: " + noLoads);
                err.requireType = "timeout";
                err.requireModules = noLoads;
                return req.onError(err);
            }
            if (stillLoading || context.scriptCount) {
                //Something is still waiting to load. Wait for it, but only
                //if a timeout is not already in effect.
                if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) {
                    checkLoadedTimeoutId = setTimeout(function () {
                        checkLoadedTimeoutId = 0;
                        checkLoaded();
                    }, 50);
                }
                return undefined;
            }

            //If still have items in the waiting cue, but all modules have
            //been loaded, then it means there are some circular dependencies
            //that need to be broken.
            //However, as a waiting thing is fired, then it can add items to
            //the waiting cue, and those items should not be fired yet, so
            //make sure to redo the checkLoaded call after breaking a single
            //cycle, if nothing else loaded then this logic will pick it up
            //again.
            if (context.waitCount) {
                //Cycle through the waitAry, and call items in sequence.
                for (i = 0; (manager = waitAry[i]); i++) {
                    forceExec(manager, {});
                }

                //Only allow this recursion to a certain depth. Only
                //triggered by errors in calling a module in which its
                //modules waiting on it cannot finish loading, or some circular
                //dependencies that then may add more dependencies.
                //The value of 5 is a bit arbitrary. Hopefully just one extra
                //pass, or two for the case of circular dependencies generating
                //more work that gets resolved in the sync node case.
                if (checkLoadedDepth < 5) {
                    checkLoadedDepth += 1;
                    checkLoaded();
                }
            }

            checkLoadedDepth = 0;

            //Check for DOM ready, and nothing is waiting across contexts.
            req.checkReadyState();

            return undefined;
        }
940000
def check_running_job_count():
    """"""
    try:
        job_list = current_k8s_batchv1_api_client.\
            list_job_for_all_namespaces()
        if len(job_list.items) > K8S_MAXIMUM_CONCURRENT_JOBS:
            return False
    except ApiException as e:
        log.error('Something went wrong while getting running job list.')
        log.error(e)
        return False
    return True
184266
function(endpoint,args,done) {

    var qs = util.getPaginationQS(args);

    endpoint +=  '?' + qs;
    util.getEndpoint(endpoint,args,done);
}
484187
def check_status(self, delay=0):
        
        if not self.item_id:
            while not self._request_status():
                # wait until _request_status returns True
                yield self.status, self.completion_percentage
                if self.item_id is None:
                    sleep(delay)
        else:
            yield self.status, self.completion_percentage
466192
function(job, done) {
                    Async.whilst(
                        function() { return !job.properties().isDone; },
                        function(iterationDone) {
                            job.fetch(function(err, job) {
                                if (err) {
                                    callback(err);
                                }
                                else {
                                    // If the user asked for verbose output,
                                    // then write out the status of the search
                                    var properties = job.properties();
                                    if (isVerbose) {
                                        var progress    = (properties.doneProgress * 100.0) + "%";
                                        var scanned     = properties.scanCount;
                                        var matched     = properties.eventCount;
                                        var results     = properties.resultCount;
                                        var stats = "-- " +
                                            progress + " done | " +
                                            scanned  + " scanned | " +
                                            matched  + " matched | " +
                                            results  + " results";
                                        print("\r" + stats + "                                          ");
                                    }
                                    
                                    Async.sleep(1000, iterationDone);
                                }
                            });
                        },
                        function(err) {
                            if (isVerbose) {
                                print("\r");
                            }
                            done(err, job);
                        }
                    );
                }
862282
def check_job(self, job_id):
        
        resp = self._call(endpoint='status', data={'job_id': job_id})
        map = {'id': 'job_id', 'status': 'status_code', 'type': 'type_code'}
        job_status_args = {map.get(k, k): v for k, v in resp.items()}
        return JobStatus(**job_status_args)
484549
def update_api_endpoint():
    """"""
    environment = subprocess.check_output(['pipenv',
                                           'run',
                                           'runway',
                                           'whichenv']).decode().strip()
    environment_file = os.path.join(
        os.path.dirname(os.path.realpath(__file__)),
        'src',
        'environments',
        'environment.prod.ts' if environment == 'prod' else 'environment.ts'
    )
    cloudformation = boto3.resource('cloudformation')
    stack = cloudformation.Stack(STACK_PREFIX + environment)
    endpoint = [i['OutputValue'] for i in stack.outputs
                if i['OutputKey'] == 'ServiceEndpoint'][0]

    with open(environment_file, 'r') as stream:
        content = stream.read()
    content = re.sub(r'api_url: \'.*\'$',
                     "api_url: '%s/api'" % endpoint,
                     content,
                     flags=re.M)
    with open(environment_file, 'w') as stream:
        stream.write(content)
1229037
function () {
                    //Check if any input was added dynamically
                    if (job.input.length > 0) {
                        job.is_complete = false;
                        return false;
                    }

                    //Wait for workers or instances that are still working
                    return worker_count > 0 ? areWorkersComplete() : job.instances <= 0;
                }
811614
def check_status(self):
        
        # 1) see it the job is blocked
        # 2) see if an error occured at submitting the job the job was submitted, TODO these problems can be solved
        # 3) see if there is output
        # 4) see if abinit reports problems
        # 5) see if both err files exist and are empty
        # 6) no output and no err files, the job must still be running
        # 7) try to find out what caused the problems
        # 8) there is a problem but we did not figure out what ...
        # 9) the only way of landing here is if there is a output file but no err files...

        # 1) A locked task can only be unlocked by calling set_status explicitly.
        # an errored task, should not end up here but just to be sure
        black_list = (self.S_LOCKED, self.S_ERROR)
        #if self.status in black_list: return self.status

        # 2) Check the returncode of the job script
        if self.returncode != 0:
            msg = "job.sh return code: %s\nPerhaps the job was not submitted properly?" % self.returncode
            return self.set_status(self.S_QCRITICAL, msg=msg)

        # If we have an abort file produced by Abinit
        if self.mpiabort_file.exists:
            return self.set_status(self.S_ABICRITICAL, msg="Found ABINIT abort file")

        # Analyze the stderr file for Fortran runtime errors.
        # getsize is 0 if the file is empty or it does not exist.
        err_msg = None
        if self.stderr_file.getsize() != 0:
            err_msg = self.stderr_file.read()

        # Analyze the stderr file of the resource manager runtime errors.
        # TODO: Why are we looking for errors in queue.qerr?
        qerr_info = None
        if self.qerr_file.getsize() != 0:
            qerr_info = self.qerr_file.read()

        # Analyze the stdout file of the resource manager (needed for PBS !)
        qout_info = None
        if self.qout_file.getsize():
            qout_info = self.qout_file.read()

        # Start to check ABINIT status if the output file has been created.
        #if self.output_file.getsize() != 0:
        if self.output_file.exists:
            try:
                report = self.get_event_report()
            except Exception as exc:
                msg = "%s exception while parsing event_report:\n%s" % (self, exc)
                return self.set_status(self.S_ABICRITICAL, msg=msg)

            if report is None:
                return self.set_status(self.S_ERROR, msg="got None report!")

            if report.run_completed:
                # Here we  set the correct timing data reported by Abinit
                self.datetimes.start = report.start_datetime
                self.datetimes.end = report.end_datetime

                # Check if the calculation converged.
                not_ok = report.filter_types(self.CRITICAL_EVENTS)
                if not_ok:
                    return self.set_status(self.S_UNCONVERGED, msg='status set to unconverged based on abiout')
                else:
                    return self.set_status(self.S_OK, msg="status set to ok based on abiout")

            # Calculation still running or errors?
            if report.errors:
                # Abinit reported problems
                logger.debug('Found errors in report')
                for error in report.errors:
                    logger.debug(str(error))
                    try:
                        self.abi_errors.append(error)
                    except AttributeError:
                        self.abi_errors = [error]

                # The job is unfixable due to ABINIT errors
                logger.debug("%s: Found Errors or Bugs in ABINIT main output!" % self)
                msg = "\n".join(map(repr, report.errors))
                return self.set_status(self.S_ABICRITICAL, msg=msg)

            # 5)
            if self.stderr_file.exists and not err_msg:
                if self.qerr_file.exists and not qerr_info:
                    # there is output and no errors
                    # The job still seems to be running
                    return self.set_status(self.S_RUN, msg='there is output and no errors: job still seems to be running')

        # 6)
        if not self.output_file.exists:
            logger.debug("output_file does not exists")
            if not self.stderr_file.exists and not self.qerr_file.exists:
                # No output at allThe job is still in the queue.
                return self.status

        # 7) Analyze the files of the resource manager and abinit and execution err (mvs)
        # MG: This section has been disabled: several portability issues
        # Need more robust logic in error_parser, perhaps logic provided by users via callbacks.
        if False and (qerr_info or qout_info):
            from pymatgen.io.abinit.scheduler_error_parsers import get_parser
            scheduler_parser = get_parser(self.manager.qadapter.QTYPE, err_file=self.qerr_file.path,
                                          out_file=self.qout_file.path, run_err_file=self.stderr_file.path)

            if scheduler_parser is None:
                return self.set_status(self.S_QCRITICAL,
                                       msg="Cannot find scheduler_parser for qtype %s" % self.manager.qadapter.QTYPE)

            scheduler_parser.parse()

            if scheduler_parser.errors:
                # Store the queue errors in the task
                self.queue_errors = scheduler_parser.errors
                # The job is killed or crashed and we know what happened
                msg = "scheduler errors found:\n%s" % str(scheduler_parser.errors)
                return self.set_status(self.S_QCRITICAL, msg=msg)

            elif lennone(qerr_info) > 0:
                # if only qout_info, we are not necessarily in QCRITICAL state,
                # since there will always be info in the qout file
                self.history.info('Found unknown message in the queue qerr file: %s' % str(qerr_info))
                #try:
                #    rt = self.datetimes.get_runtime().seconds
                #except:
                #    rt = -1.0
                #tl = self.manager.qadapter.timelimit
                #if rt > tl:
                #    msg += 'set to error : runtime (%s) exceded walltime (%s)' % (rt, tl)
                #    print(msg)
                #    return self.set_status(self.S_ERROR, msg=msg)
                # The job may be killed or crashed but we don't know what happened
                # It may also be that an innocent message was written to qerr, so we wait for a while
                # it is set to QCritical, we will attempt to fix it by running on more resources

        # 8) analyzing the err files and abinit output did not identify a problem
        # but if the files are not empty we do have a problem but no way of solving it:
        # The job is killed or crashed but we don't know what happend
        # it is set to QCritical, we will attempt to fix it by running on more resources
        if err_msg:
            msg = 'Found error message:\n %s' % str(err_msg)
            self.history.warning(msg)
            #return self.set_status(self.S_QCRITICAL, msg=msg)

        # 9) if we still haven't returned there is no indication of any error and the job can only still be running
        # but we should actually never land here, or we have delays in the file system ....
        # print('the job still seems to be running maybe it is hanging without producing output... ')

        # Check time of last modification.
        if self.output_file.exists and \
           (time.time() - self.output_file.get_stat().st_mtime > self.manager.policy.frozen_timeout):
            msg = "Task seems to be frozen, last change more than %s [s] ago" % self.manager.policy.frozen_timeout
            return self.set_status(self.S_ERROR, msg=msg)

        # Handle weird case in which either run.abo, or run.log have not been produced
        #if self.status not in (self.S_INIT, self.S_READY) and (not self.output.file.exists or not self.log_file.exits):
        #    msg = "Task have been submitted but cannot find the log file or the output file"
        #    return self.set_status(self.S_ERROR, msg)

        return self.set_status(self.S_RUN, msg='final option: nothing seems to be wrong, the job must still be running')
516536
function completeJob(loader, job, callback) {
    var nextJob;

    loader.jobsInProgress--;

    if ((!loader.jobLimit || loader.jobsInProgress < loader.jobLimit) && loader.jobQueue.length > 0) {
        nextJob = loader.jobQueue.shift();
        nextJob.start();
        loader.jobsInProgress++;
    }

    callback(job.image, job.errorMsg, job.request);
}
918151
def check_if_cached(self, job_spec, step, workflow_workspace):
        """"""
        response, http_response = self._client.job_cache.check_if_cached(
            job_spec=json.dumps(job_spec),
            workflow_json=json.dumps(step),
            workflow_workspace=workflow_workspace).\
            result()
        if http_response.status_code == 400:
            raise HTTPBadRequest('Bad request to check cache. Error: {}'.
                                 format(http_response.data))
        elif http_response.status_code == 500:
            raise HTTPInternalServerError('Internal Server Error. Error: {}'.
                                          format(http_response.data))
        return http_response
481940
def has_completed(self):
        """"""
        objects_in_db = WorkflowObjectModel.query.filter(
            WorkflowObjectModel.id_workflow == self.uuid,
            WorkflowObjectModel.id_parent == None,  # noqa
        ).filter(WorkflowObjectModel.status.in_([
            workflow_object_class.known_statuses.COMPLETED
        ])).count()
        return objects_in_db == len(list(self.objects))