Search in sources :

Example 1 with JobHistoryQuery

use of com.runwaysdk.system.scheduler.JobHistoryQuery in project geoprism-registry by terraframe.

the class ListTypeTest method waitUntilPublished.

@Request
private void waitUntilPublished(String oid) {
    List<? extends JobHistory> histories = null;
    int waitTime = 0;
    while (histories == null) {
        if (waitTime > 10000) {
            Assert.fail("Job was never scheduled. Unable to find any associated history.");
        }
        QueryFactory qf = new QueryFactory();
        PublishListTypeVersionJobQuery jobQuery = new PublishListTypeVersionJobQuery(qf);
        jobQuery.WHERE(jobQuery.getListType().EQ(oid));
        JobHistoryQuery jhq = new JobHistoryQuery(qf);
        jhq.WHERE(jhq.job(jobQuery));
        List<? extends JobHistory> potentialHistories = jhq.getIterator().getAll();
        if (potentialHistories.size() > 0) {
            histories = potentialHistories;
        } else {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
                Assert.fail("Interrupted while waiting");
            }
            waitTime += 1000;
        }
    }
    for (JobHistory history : histories) {
        try {
            SchedulerTestUtils.waitUntilStatus(history.getOid(), AllJobStatus.SUCCESS);
        } catch (InterruptedException e) {
            e.printStackTrace();
            Assert.fail("Interrupted while waiting");
        }
    }
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) JobHistoryQuery(com.runwaysdk.system.scheduler.JobHistoryQuery) JobHistory(com.runwaysdk.system.scheduler.JobHistory) PublishListTypeVersionJobQuery(net.geoprism.registry.etl.PublishListTypeVersionJobQuery) Request(com.runwaysdk.session.Request)

Example 2 with JobHistoryQuery

use of com.runwaysdk.system.scheduler.JobHistoryQuery in project geoprism-registry by terraframe.

the class ListTypeService method publishVersion.

@Request(RequestType.SESSION)
public JsonObject publishVersion(String sessionId, String oid) {
    ListTypeVersion version = ListTypeVersion.get(oid);
    // Only a working version can be republished.
    if (!version.getWorking()) {
        throw new UnsupportedOperationException();
    }
    this.enforceReadPermissions(version.getListType());
    QueryFactory factory = new QueryFactory();
    PublishListTypeVersionJobQuery query = new PublishListTypeVersionJobQuery(factory);
    query.WHERE(query.getVersion().EQ(version));
    JobHistoryQuery q = new JobHistoryQuery(factory);
    q.WHERE(q.getStatus().containsAny(AllJobStatus.NEW, AllJobStatus.QUEUED, AllJobStatus.RUNNING));
    q.AND(q.job(query));
    if (q.getCount() > 0) {
        throw new DuplicateJobException("This version has already been queued for publishing");
    }
    PublishListTypeVersionJob job = new PublishListTypeVersionJob();
    job.setRunAsUserId(Session.getCurrentSession().getUser().getOid());
    job.setVersion(version);
    job.setListType(version.getListType());
    job.apply();
    NotificationFacade.queue(new GlobalNotificationMessage(MessageType.PUBLISH_JOB_CHANGE, null));
    final JobHistory history = job.start();
    JsonObject resp = new JsonObject();
    resp.addProperty("jobOid", history.getOid());
    return resp;
}
Also used : PublishListTypeVersionJob(net.geoprism.registry.etl.PublishListTypeVersionJob) QueryFactory(com.runwaysdk.query.QueryFactory) JobHistoryQuery(com.runwaysdk.system.scheduler.JobHistoryQuery) DuplicateJobException(net.geoprism.registry.etl.DuplicateJobException) JobHistory(com.runwaysdk.system.scheduler.JobHistory) PublishListTypeVersionJobQuery(net.geoprism.registry.etl.PublishListTypeVersionJobQuery) JsonObject(com.google.gson.JsonObject) ListTypeVersion(net.geoprism.registry.ListTypeVersion) GlobalNotificationMessage(net.geoprism.registry.ws.GlobalNotificationMessage) Request(com.runwaysdk.session.Request)

Aggregations

QueryFactory (com.runwaysdk.query.QueryFactory)2 Request (com.runwaysdk.session.Request)2 JobHistory (com.runwaysdk.system.scheduler.JobHistory)2 JobHistoryQuery (com.runwaysdk.system.scheduler.JobHistoryQuery)2 PublishListTypeVersionJobQuery (net.geoprism.registry.etl.PublishListTypeVersionJobQuery)2 JsonObject (com.google.gson.JsonObject)1 ListTypeVersion (net.geoprism.registry.ListTypeVersion)1 DuplicateJobException (net.geoprism.registry.etl.DuplicateJobException)1 PublishListTypeVersionJob (net.geoprism.registry.etl.PublishListTypeVersionJob)1 GlobalNotificationMessage (net.geoprism.registry.ws.GlobalNotificationMessage)1