protected WorkSchedulePath(WorkSchedulePath parent, Work work) { parentPath = parent.getPath(); name = name(work); scheduleStackTrace = isCaptureStackEnabled() ? new Trace(parent.scheduleStackTrace) : null; }
/** * Returns a key that can be used by the WorkManager implementation to guarantee that works with the same partition * key will be executed in the order they are submitted. * * @since 9.3 */ default String getPartitionKey() { return getId(); }
@Override public void signalStop() { if (work != null) { work.setWorkInstanceSuspending(); } }
@SuppressWarnings("deprecation") public String migrate(final int batchSize) { final String MIGRATION_WORK_ID = "AuditMigration"; WorkManager wm = Framework.getService(WorkManager.class); State migrationState = wm.getWorkState(MIGRATION_WORK_ID); if (migrationState != null) { return "Migration already scheduled : " + migrationState.toString(); } Work migrationWork = new ESAuditMigrationWork(MIGRATION_WORK_ID, batchSize); wm.schedule(migrationWork); return "Migration work started : " + MIGRATION_WORK_ID; }
public boolean canStartPurge() { WorkManager workManager = Framework.getService(WorkManager.class); return workManager.getMetrics(PermissionsPurgeWork.CATEGORY).getRunning().intValue() <= 0; }
protected static String name(Work work) { return work.getCategory() + ":" + work.getId(); }
@Override public Progress getProgress() { if (importer != null && importer.totalRecords > 0) { return new Progress(importer.currentRecord, importer.totalRecords); } return super.getProgress(); }
public static void newInstance(Work work) { Work entered = enteredLocal.get(); WorkSchedulePath path = new WorkSchedulePath(entered == null ? EMPTY : entered.getSchedulePath(), work); work.setSchedulePath(path); }
public boolean waitForCompletion(long timeoutMillis) throws InterruptedException { WorkManager workManager = getWorkManager(); if (workManager == null) { return false; } return workManager.awaitCompletion(timeoutMillis, TimeUnit.MILLISECONDS); }
@SuppressWarnings("deprecation") @Override public long getPendingWorkerCount() { WorkManager wm = Framework.getService(WorkManager.class); // api is deprecated for completed work return wm.getQueueSize(INDEXING_QUEUE_ID, Work.State.SCHEDULED); }
@Override synchronized protected WorkQueueMetrics metrics() { return new WorkQueueMetrics(queueId, scheduledCount, runningCount, completedCount, cancelledCount); }
/** * Returns {@code true} if the given state is not {@code null} and matches the state of the given work or if the * state is {@code null} and the work's state is either {@link State#SCHEDULED} or {@link State#RUNNING}, * {@code false} otherwise. * * @since 9.3 */ protected static boolean workHasState(Work work, State state) { State workState = work.getWorkInstanceState(); return state == null ? (workState == State.SCHEDULED || workState == State.RUNNING) : workState == state; }
protected Trace(Trace cause) { super(getPath(), cause); }
public String getPath() { return path(this); }
@Override public boolean isProcessingEnabled(String queueId) { WorkQueueDescriptor wqd = getWorkQueueDescriptor(queueId); return wqd != null && wqd.isProcessingEnabled(); }
@Override public boolean isQueuingEnabled(String queueId) { WorkQueueDescriptor wqd = getWorkQueueDescriptor(queueId); return wqd != null && wqd.isQueuingEnabled(); }
public void init() { WorkManager workManager = getWorkManager(); if (workManager != null) { workManager.init(); } }
public boolean shutdown(long timeoutMillis) throws InterruptedException { WorkManager workManager = getWorkManager(); if (workManager == null) { return true; } return workManager.shutdown(timeoutMillis, TimeUnit.MILLISECONDS); }
public boolean canStartPurge() { WorkManager workManager = Framework.getLocalService(WorkManager.class); return workManager.getMetrics(PermissionsPurgeWork.CATEGORY).getRunning().intValue() <= 0; }
WorkQueueMetrics metrics(String queueId, Number[] counters) { return new WorkQueueMetrics(queueId, counters[0], counters[1], counters[2], counters[3]); }