class TranscribeQueueJob implements AcmSchedulableBean {

    @Override
    public void executeTask()
    {
        try
        {
            getAuditPropertyEntityAdapter().setUserId("TRANSCRIBE_SERVICE");

            TranscribeConfiguration configuration = getArkCaseTranscribeService().getConfiguration();
            List<Transcribe> processingTranscribeObjects = getArkCaseTranscribeService()
                    .getAllByStatus(TranscribeStatusType.PROCESSING.toString());
            List<Transcribe> processingTranscribeAutomaticObjects = processingTranscribeObjects.stream()
                    .filter(t -> TranscribeType.AUTOMATIC.toString().equalsIgnoreCase(t.getType())).collect(Collectors.toList());
            List<Transcribe> processingTranscribeObjectsDistinctByProcessId = processingTranscribeAutomaticObjects.stream()
                    .filter(TranscribeUtils.distinctByProperty(Transcribe::getProcessId)).collect(Collectors.toList());

            if (configuration.getNumberOfFilesForProcessing() > processingTranscribeObjectsDistinctByProcessId.size())
            {
                String key = TranscribeBusinessProcessVariableKey.STATUS.toString();
                String value = TranscribeStatusType.QUEUED.toString();
                List<ProcessInstance> processInstances = getActivitiRuntimeService().createProcessInstanceQuery().includeProcessVariables()
                        .variableValueEqualsIgnoreCase(key, value).list();

                if (processInstances != null && processInstances.size() > 0)
                {
                    processInstances.sort(new TranscribeProcessInstanceCreatedDateComparator());
                    ProcessInstance processInstance = processInstances.get(0);
                    List<Long> ids = (List<Long>) processInstance.getProcessVariables().get("IDS");

                    if (ids != null && ids.size() > 0)
                    {
                        Transcribe transcribe = getArkCaseTranscribeService().get(ids.get(0));
                        if (transcribe != null)
                        {
                            getArkCaseTranscribeService().getTranscribeServiceFactory().getService(configuration.getProvider())
                                    .create(transcribe);
                            getArkCaseTranscribeService().signal(processInstance, TranscribeStatusType.PROCESSING.toString(),
                                    TranscribeActionType.PROCESSING.toString());
                        }
                    }
                }
            }
        }
        catch (GetConfigurationException | GetTranscribeException | CreateTranscribeException
                | TranscribeServiceProviderNotFoundException e)
        {
            LOG.error("Could not move Transcribe from the queue. REASON=[{}]", e.getMessage(), e);
        }
    }

}