Search in sources :

Example 1 with AbsoluteTimeDateFormat

use of org.apache.log4j.helpers.AbsoluteTimeDateFormat in project carbon-business-process by wso2.

the class SimpleScheduler method doLoadImmediate.

boolean doLoadImmediate() {
    if (log.isDebugEnabled()) {
        log.debug("LOAD IMMEDIATE started");
    }
    // don't load anything if we're already half-full;  we've got plenty to do already
    if (outstandingJobs.size() > todoLimit / 2) {
        return true;
    }
    List<Job> jobs = new ArrayList<Job>();
    try {
        // don't load more than we can chew
        int tps = 100;
        final int batch = Math.min((int) (immediateInterval * tps / 1000), todoLimit - outstandingJobs.size());
        // jobs might have been enqueued by #addTodoList meanwhile
        if (batch <= 0) {
            if (log.isDebugEnabled()) {
                log.debug("Max capacity reached: " + outstandingJobs.size() + " jobs dispacthed i.e. queued or being executed");
            }
            return true;
        }
        if (log.isDebugEnabled()) {
            log.debug("Started loading " + batch + " jobs from db");
        }
        // jobs = _db.dequeueImmediate(_nodeId, System.currentTimeMillis() + _immediateInterval, batch);
        List<HumanTaskJobDAO> htJobs = execTransaction(new Callable<List<HumanTaskJobDAO>>() {

            public List<HumanTaskJobDAO> call() throws Exception {
                return getConnection().dequeueImmediate(nodeId, System.currentTimeMillis() + immediateInterval, batch);
            }
        });
        for (HumanTaskJobDAO htJob : htJobs) {
            jobs.add(new Job(htJob));
        }
        if (log.isDebugEnabled()) {
            log.debug("loaded " + jobs.size() + " jobs from db");
        }
        long warningDelay = 0;
        long delayedTime = System.currentTimeMillis() - warningDelay;
        int delayedCount = 0;
        boolean runningLate;
        AbsoluteTimeDateFormat f = new AbsoluteTimeDateFormat();
        for (Job j : jobs) {
            // jobs might have been enqueued by #addTodoList meanwhile
            if (outstandingJobs.size() >= todoLimit) {
                if (log.isDebugEnabled()) {
                    log.debug("Max capacity reached: " + outstandingJobs.size() + " jobs dispacthed i.e. queued or being executed");
                }
                break;
            }
            runningLate = j.schedDate <= delayedTime;
            if (runningLate) {
                // TODO run the job here
                delayedCount++;
            }
            if (log.isDebugEnabled()) {
                log.debug("todo.enqueue job from db: " + j.getJobID() + " for " + j.schedDate + "(" + f.format(j.schedDate) + ") " + (runningLate ? " delayed=true" : ""));
            }
            enqueue(j);
        }
        if (delayedCount > 0) {
            log.warn("Dispatching jobs with more than " + (warningDelay / 60000) + " minutes delay. Either the server was down for some time or the job " + "load is greater than available capacity");
        }
        // clear only if the batch succeeded
        processedSinceLastLoadTask.clear();
        return true;
    } catch (Exception ex) {
        log.error("Error loading immediate jobs from database.", ex);
        return false;
    } finally {
        if (log.isDebugEnabled()) {
            log.debug("LOAD IMMEDIATE complete");
        }
    }
}
Also used : AbsoluteTimeDateFormat(org.apache.log4j.helpers.AbsoluteTimeDateFormat) HumanTaskJobDAO(org.wso2.carbon.humantask.core.dao.HumanTaskJobDAO) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) InvalidJobsInDbException(org.wso2.carbon.humantask.core.api.scheduler.InvalidJobsInDbException) InvalidUpdateRequestException(org.wso2.carbon.humantask.core.api.scheduler.InvalidUpdateRequestException)

Aggregations

AbsoluteTimeDateFormat (org.apache.log4j.helpers.AbsoluteTimeDateFormat)1 InvalidJobsInDbException (org.wso2.carbon.humantask.core.api.scheduler.InvalidJobsInDbException)1 InvalidUpdateRequestException (org.wso2.carbon.humantask.core.api.scheduler.InvalidUpdateRequestException)1 HumanTaskJobDAO (org.wso2.carbon.humantask.core.dao.HumanTaskJobDAO)1 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)1