Search in sources :

Example 16 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class DictionaryBasedImport method handleDataRow.

private void handleDataRow(int index, Values row) {
    if (row.length() == 0) {
        return;
    }
    Context context = filterEmptyValues(dictionary.load(row, false));
    if (!isEmptyContext(context)) {
        Watch watch = Watch.start();
        errorContext.handle(() -> {
            try {
                rowHandler.invoke(Tuple.create(index, context));
            } catch (Exception exception) {
                process.incCounter("LineBasedJob.erroneousRow");
                throw exception;
            }
        });
        process.addTiming(NLS.smartGet(rowCounterName), watch.elapsedMillis());
    }
}
Also used : ErrorContext(sirius.biz.process.ErrorContext) TaskContext(sirius.kernel.async.TaskContext) Context(sirius.kernel.commons.Context) ProcessContext(sirius.biz.process.ProcessContext) Watch(sirius.kernel.commons.Watch) HandledException(sirius.kernel.health.HandledException)

Example 17 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class EntityImportJob method handleRow.

@Override
protected final void handleRow(int index, Context context) {
    Watch watch = Watch.start();
    if (contextExtender != null) {
        contextExtender.accept(context);
    }
    E entity = findAndLoad(context);
    errorContext.performImport(entity::toString, () -> {
        if (shouldSkip(entity)) {
            process.incCounter("EntityImportJob.rowIgnored");
            return;
        }
        fillAndVerify(entity, context);
        boolean isNew = entity.isNew();
        if (mode == ImportMode.CHECK_ONLY) {
            enforceSaveConstraints(entity, context);
        } else {
            createOrUpdate(entity, context);
        }
        if (isNew) {
            process.addTiming(NLS.get("EntityImportJob.entityCreated"), watch.elapsedMillis());
        } else {
            process.addTiming("EntityImportJob.entityUpdated", watch.elapsedMillis());
        }
    });
}
Also used : Watch(sirius.kernel.commons.Watch)

Example 18 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class JupiterSync method executeDataProvider.

private void executeDataProvider(ProcessContext processContext, JupiterDataProvider provider) {
    Watch watch = Watch.start();
    processContext.log(ProcessLog.info().withFormattedMessage("Executing data provider: %s", provider.getName()));
    Blob blob = blobStorage.getSpace(localRepoSpaceName).findOrCreateByPath(tenants.getTenantUserManager().getSystemTenantId(), provider.getFilename());
    try (OutputStream out = blob.createOutputStream(Files.getFilenameAndExtension(provider.getFilename()))) {
        provider.execute(out);
        processContext.log(ProcessLog.info().withFormattedMessage("Creating '%s' took %s...", provider.getFilename(), watch.duration()));
    } catch (Exception e) {
        processContext.log(ProcessLog.error().withMessage(Exceptions.handle().to(Jupiter.LOG).error(e).withSystemErrorMessage("Failed to execute data provider %s: %s (%s)", provider.getName()).handle().getMessage()));
    }
}
Also used : Blob(sirius.biz.storage.layer2.Blob) OutputStream(java.io.OutputStream) Watch(sirius.kernel.commons.Watch) HandledException(sirius.kernel.health.HandledException)

Example 19 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class RelationalEntityImportJob method handleRow.

@Override
protected final void handleRow(int index, Context context) {
    Watch watch = Watch.start();
    if (contextExtender != null) {
        contextExtender.accept(context);
    }
    E entity = findAndLoad(context);
    if (mode == SyncMode.DELETE_EXISTING) {
        if (!entity.isNew()) {
            importer.deleteNow(entity);
            process.addTiming(NLS.get("EntityImportJob.entityDeleted"), watch.elapsedMillis());
        }
    } else {
        createOrUpdateEntity(entity, context, watch);
    }
}
Also used : Watch(sirius.kernel.commons.Watch)

Example 20 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class FileImportJob method handleAuxiliaryFile.

/**
 * Gets invoked for every entry in a given ZIP archive which cannot be processed by this job itself.
 * <p>
 * This might be used e.g. if an XML file is being processed which is accompanied with some media files to
 * move them into the proper directory in the {@link sirius.biz.storage.layer3.VirtualFileSystem}.
 * <p>
 * By default this is attempted if the {@link #determineAuxiliaryFilesDirectory()} returns a non-null result.
 * Otherwise these files are simply ignored.
 *
 * @param extractedFile the extracted file which cannot be handled by the job itself
 */
protected boolean handleAuxiliaryFile(ExtractedFile extractedFile) {
    try {
        Watch watch = Watch.start();
        VirtualFile basePath = determineAuxiliaryFilesBasePath();
        if (basePath == null) {
            return false;
        }
        VirtualFile targetFile = basePath.resolve(getTargetPath(extractedFile));
        if (extractor.updateFile(extractedFile, targetFile, auxiliaryFileMode.overrideMode) != ArchiveExtractor.UpdateResult.SKIPPED) {
            process.addTiming(NLS.get("FileImportJob.auxiliaryFileCopied"), watch.elapsedMillis());
        } else {
            process.addTiming(NLS.get("FileImportJob.auxiliaryFileSkipped"), watch.elapsedMillis());
        }
        return true;
    } catch (Exception e) {
        process.handle(Exceptions.handle().error(e).to(Log.BACKGROUND).withNLSKey("FileImportJob.copyAuxiliaryFileFailed").set("file", extractedFile.getFilePath()).set("message", e.getMessage()).handle());
        return false;
    }
}
Also used : VirtualFile(sirius.biz.storage.layer3.VirtualFile) Watch(sirius.kernel.commons.Watch)

Aggregations

Watch (sirius.kernel.commons.Watch)53 PreparedStatement (java.sql.PreparedStatement)8 SQLException (java.sql.SQLException)8 Connection (java.sql.Connection)6 HandledException (sirius.kernel.health.HandledException)6 Document (org.bson.Document)5 ResultSet (java.sql.ResultSet)4 TaskContext (sirius.kernel.async.TaskContext)4 ArrayList (java.util.ArrayList)3 OMA (sirius.db.jdbc.OMA)3 Property (sirius.db.mixing.Property)3 BasicDBObject (com.mongodb.BasicDBObject)2 ProcessContext (sirius.biz.process.ProcessContext)2 ObjectStorageSpace (sirius.biz.storage.layer1.ObjectStorageSpace)2 Operator (sirius.db.jdbc.Operator)2 Operation (sirius.kernel.async.Operation)2 Context (sirius.kernel.commons.Context)2 Limit (sirius.kernel.commons.Limit)2 AS400 (com.ibm.as400.access.AS400)1 ProgramCall (com.ibm.as400.access.ProgramCall)1