Java Examples for com.redhat.rhn.taskomatic.task.threaded.TaskQueue
The following java examples will help you to understand the usage of com.redhat.rhn.taskomatic.task.threaded.TaskQueue. These source code samples are taken from different open source projects.
Example 1
| Project: spacewalk-master File: RhnQueueJob.java View source code |
/**
* {@inheritDoc}
*/
public void execute(JobExecutionContext ctx) throws JobExecutionException {
TaskQueueFactory factory = TaskQueueFactory.get();
String queueName = getQueueName();
TaskQueue queue = factory.getQueue(queueName);
if (queue == null) {
try {
queue = factory.createQueue(queueName, getDriverClass(), getLogger());
} catch (Exception e) {
getLogger().error(e);
return;
}
}
if (queue.changeRun(jobRun)) {
jobRun.start();
HibernateFactory.commitTransaction();
HibernateFactory.closeSession();
logToNewFile();
getLogger().debug("Starting run " + jobRun.getId());
} else {
// close current run
TaskoRun run = (TaskoRun) HibernateFactory.reload(jobRun);
run.appendToOutputLog("Run with id " + queue.getQueueRun().getId() + " handles the whole task queue.");
run.skipped();
HibernateFactory.commitTransaction();
HibernateFactory.closeSession();
}
int defaultItems = 3;
if (queueName.equals("channel_repodata")) {
defaultItems = 1;
}
int maxWorkItems = Config.get().getInt("taskomatic." + queueName + "_max_work_items", defaultItems);
int queueSize = queue.getQueueSize();
if (getLogger().isDebugEnabled()) {
getLogger().debug("Queue size (before run): " + queueSize);
}
if (queueSize < maxWorkItems) {
queue.run();
} else {
getLogger().warn("Maximum number of workers already put ... skipping.");
}
}