Search in sources :

Example 1 with JobMetaData

use of dk.dbc.pgqueue.consumer.JobMetaData in project solr-document-store by DBCDK.

the class Worker method makeWorker.

public JobConsumer<QueueJob> makeWorker() {
    return new JobConsumer<QueueJob>() {

        @Override
        public void accept(Connection connection, QueueJob job, JobMetaData metaData) throws FatalQueueError, NonFatalQueueError, PostponedNonFatalQueueError {
            log.info("job = {}, metadata = {}", job, metaData);
            try {
                JsonNode sourceDoc = docProducer.fetchSourceDoc(job);
                SolrInputDocument solrDocument = docProducer.createSolrDocument(sourceDoc);
                String bibliographicShardId = docProducer.bibliographicShardId(sourceDoc);
                docProducer.deleteSolrDocuments(bibliographicShardId, job.getCommitwithin());
                docProducer.deploy(solrDocument, job.getCommitwithin());
            } catch (IOException ex) {
                throw new NonFatalQueueError(ex);
            } catch (SolrServerException ex) {
                throw new FatalQueueError(ex);
            }
        }
    };
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) JobMetaData(dk.dbc.pgqueue.consumer.JobMetaData) PostponedNonFatalQueueError(dk.dbc.pgqueue.consumer.PostponedNonFatalQueueError) NonFatalQueueError(dk.dbc.pgqueue.consumer.NonFatalQueueError) SolrServerException(org.apache.solr.client.solrj.SolrServerException) Connection(java.sql.Connection) JobConsumer(dk.dbc.pgqueue.consumer.JobConsumer) JsonNode(com.fasterxml.jackson.databind.JsonNode) PostponedNonFatalQueueError(dk.dbc.pgqueue.consumer.PostponedNonFatalQueueError) FatalQueueError(dk.dbc.pgqueue.consumer.FatalQueueError) NonFatalQueueError(dk.dbc.pgqueue.consumer.NonFatalQueueError) IOException(java.io.IOException) QueueJob(dk.dbc.search.solrdocstore.queue.QueueJob)

Example 2 with JobMetaData

use of dk.dbc.pgqueue.consumer.JobMetaData in project solr-document-store by DBCDK.

the class QueueJobIT method testStoreRetrieve.

@Test(timeout = 5000L)
public void testStoreRetrieve() throws Exception {
    System.out.println("store-retrieve");
    QueueJob job1 = new QueueJob(888888, "clazzifier", "12345678");
    QueueJob job2 = new QueueJob(888888, "clazzifier", "87654321", 1000);
    try (Connection connection = dataSource.getConnection()) {
        PreparedQueueSupplier<QueueJob> supplier = QUEUE_SUPPLIER.preparedSupplier(connection);
        supplier.enqueue(QUEUE, job1);
        supplier.enqueue(QUEUE, job2);
        BlockingDeque<QueueJob> list = new LinkedBlockingDeque<>();
        QueueWorker worker = QueueWorker.builder().consume(QUEUE).dataSource(dataSource).build(QueueJob.STORAGE_ABSTRACTION, (JobConsumer<QueueJob>) (Connection connection1, QueueJob job, JobMetaData metaData) -> {
            list.add(job);
        });
        worker.start();
        QueueJob actual1 = list.pollFirst(5, TimeUnit.SECONDS);
        QueueJob actual2 = list.pollFirst(5, TimeUnit.SECONDS);
        worker.stop();
        assertEquals(job1.toString(), actual1.toString());
        assertEquals(job2.toString(), actual2.toString());
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) JobMetaData(dk.dbc.pgqueue.consumer.JobMetaData) Connection(java.sql.Connection) QueueWorker(dk.dbc.pgqueue.consumer.QueueWorker) Test(org.junit.Test)

Aggregations

JobMetaData (dk.dbc.pgqueue.consumer.JobMetaData)2 Connection (java.sql.Connection)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 FatalQueueError (dk.dbc.pgqueue.consumer.FatalQueueError)1 JobConsumer (dk.dbc.pgqueue.consumer.JobConsumer)1 NonFatalQueueError (dk.dbc.pgqueue.consumer.NonFatalQueueError)1 PostponedNonFatalQueueError (dk.dbc.pgqueue.consumer.PostponedNonFatalQueueError)1 QueueWorker (dk.dbc.pgqueue.consumer.QueueWorker)1 QueueJob (dk.dbc.search.solrdocstore.queue.QueueJob)1 IOException (java.io.IOException)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 Test (org.junit.Test)1