public ExecuteAsyncRunnable(Job job, ProcessEngineConfigurationImpl processEngineConfiguration) { this.job = job; this.jobId = job.getId(); this.processEngineConfiguration = processEngineConfiguration; }
public void jobRejected(AsyncExecutor asyncExecutor, Job job) { try { // execute rejected work in caller thread (potentially blocking job // acquisition) new ExecuteAsyncRunnable((JobEntity) job, asyncExecutor.getProcessEngineConfiguration()).run(); } catch (Exception e) { log.error("Failed to execute rejected job " + job.getId(), e); } }
protected void unlockJobIfNeeded() { try { if (job.isExclusive()) { processEngineConfiguration.getCommandExecutor().execute(new UnlockExclusiveJobCmd(job)); } } catch (ActivitiOptimisticLockingException optimisticLockingException) { if (log.isDebugEnabled()) { log.debug("Optimistic locking exception while unlocking the job. If you have multiple async executors running against the same database, " + "this exception means that this thread tried to acquire an exclusive job, which already was changed by another async executor thread." + "This is expected behavior in a clustered environment. " + "You can ignore this message if you indeed have multiple job executor acquisition threads running against the same database. " + "Exception message: {}", optimisticLockingException.getMessage()); } } catch (Throwable t) { log.error("Error while unlocking exclusive job " + job.getId(), t); } }
@Override public void closeFailure(CommandContext commandContext) { if (commandContext.getEventDispatcher().isEnabled()) { commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityExceptionEvent( ActivitiEventType.JOB_EXECUTION_FAILURE, job, commandContext.getException())); } CommandConfig commandConfig = commandExecutor.getDefaultConfig().transactionRequiresNew(); FailedJobCommandFactory failedJobCommandFactory = commandContext.getFailedJobCommandFactory(); Command<Object> cmd = failedJobCommandFactory.getCommand(job.getId(), commandContext.getException()); log.trace("Using FailedJobCommandFactory '" + failedJobCommandFactory.getClass() + "' and command of type '" + cmd.getClass() + "'"); commandExecutor.execute(commandConfig, cmd); }
@Override public Void execute(CommandContext commandContext) { CommandConfig commandConfig = processEngineConfiguration.getCommandExecutor().getDefaultConfig().transactionRequiresNew(); FailedJobCommandFactory failedJobCommandFactory = commandContext.getFailedJobCommandFactory(); Command<Object> cmd = failedJobCommandFactory.getCommand(job.getId(), exception); log.trace("Using FailedJobCommandFactory '" + failedJobCommandFactory.getClass() + "' and command of type '" + cmd.getClass() + "'"); processEngineConfiguration.getCommandExecutor().execute(commandConfig, cmd); // Dispatch an event, indicating job execution failed in a // try-catch block, to prevent the original exception to be swallowed if (commandContext.getEventDispatcher().isEnabled()) { try { commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityExceptionEvent(ActivitiEventType.JOB_EXECUTION_FAILURE, job, exception)); } catch (Throwable ignore) { log.warn("Exception occurred while dispatching job failure event, ignoring.", ignore); } } return null; }
public Object execute(CommandContext commandContext) { if (job == null) { throw new ActivitiIllegalArgumentException("job is null"); } if (log.isDebugEnabled()) { log.debug("Unlocking exclusive job {}", job.getId()); } if (job.isExclusive()) { if (job.getProcessInstanceId() != null) { ExecutionEntity execution = commandContext.getExecutionEntityManager().findById(job.getProcessInstanceId()); if (execution != null) { commandContext.getExecutionEntityManager().clearProcessInstanceLockTime(execution.getId()); } } } return null; } }
public Object execute(CommandContext commandContext) { if (job == null) { throw new ActivitiIllegalArgumentException("job is null"); } if (log.isDebugEnabled()) { log.debug("Executing lock exclusive job {} {}", job.getId(), job.getExecutionId()); } if (job.isExclusive()) { if (job.getExecutionId() != null) { ExecutionEntity execution = commandContext.getExecutionEntityManager().findById(job.getExecutionId()); if (execution != null) { commandContext.getExecutionEntityManager().updateProcessInstanceLockTime(execution.getProcessInstanceId()); } } } return null; } }
log.debug("Executing async job {}", job.getId());
public Object execute(CommandContext commandContext) { if (jobId == null) { throw new ActivitiIllegalArgumentException("jobId and job is null"); } Job job = commandContext.getJobEntityManager().findById(jobId); if (job == null) { throw new JobNotFoundException(jobId); } if (log.isDebugEnabled()) { log.debug("Executing job {}", job.getId()); } commandContext.addCloseListener(new FailedJobListener(commandContext.getProcessEngineConfiguration().getCommandExecutor(), job)); try { commandContext.getJobManager().execute(job); } catch (Throwable exception) { // Finally, Throw the exception to indicate the ExecuteJobCmd failed throw new ActivitiException("Job " + jobId + " failed", exception); } return null; }
@Override public void unacquire(Job job) { // Deleting the old job and inserting it again with another id, // will avoid that the job is immediately is picked up again (for example // when doing lots of exclusive jobs for the same process instance) if (job instanceof JobEntity) { JobEntity jobEntity = (JobEntity) job; processEngineConfiguration.getJobEntityManager().delete(jobEntity.getId()); JobEntity newJobEntity = processEngineConfiguration.getJobEntityManager().create(); copyJobInfo(newJobEntity, jobEntity); newJobEntity.setId(null); // We want a new id to be assigned to this job newJobEntity.setLockExpirationTime(null); newJobEntity.setLockOwner(null); processEngineConfiguration.getJobEntityManager().insert(newJobEntity); // We're not calling triggerExecutorIfNeeded here after the inser. The unacquire happened // for a reason (eg queue full or exclusive lock failure). No need to try it immediately again, // as the chance of failure will be high. } else { // It could be a v5 job, so simply unlock it. processEngineConfiguration.getJobEntityManager().resetExpiredJob(job.getId()); } }
public ExecuteAsyncRunnable(Job job, ProcessEngineConfigurationImpl processEngineConfiguration) { this.job = job; this.jobId = job.getId(); this.processEngineConfiguration = processEngineConfiguration; }
public class JobResponseWriter extends FileWriter{ private final File myFile; public JobResponseWriter(Job job) throws IOException { this(File.createTempFile("JobResponse" + job.getId() ,"tmp")); } public JobResponseWriter(File f) throws IOException { super(f); myFile = f; } /* your code here */ }
protected String getJobLabel(Job theJob) { // Try figuring out the type if(theJob instanceof TimerEntity) { return i18nManager.getMessage(Messages.JOB_TIMER, theJob.getId()); } else if (theJob instanceof MessageEntity) { return i18nManager.getMessage(Messages.JOB_MESSAGE, theJob.getId()); } else { return i18nManager.getMessage(Messages.JOB_DEFAULT_NAME, theJob.getId()); } }
public void buttonClick(ClickEvent event) { managementService.deleteJob(job.getId()); notificationManager.showInformationNotification(Messages.JOB_DELETED); jobPage.refreshSelectNext(); } });
public void buttonClick(ClickEvent event) { try { managementService.executeJob(job.getId()); jobPage.refreshSelectNext(); } catch (ActivitiException ae) { String errorMessage = ae.getMessage() + (ae.getCause() != null ? " (" + ae.getCause().getClass().getName() + ")" : ""); notificationManager.showErrorNotification(Messages.JOB_ERROR, errorMessage); // Refresh the current job jobPage.refreshCurrentJobDetails(); } } });
@Override public void closeFailure(CommandContext commandContext) { if (commandContext.getEventDispatcher().isEnabled()) { commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityExceptionEvent( ActivitiEventType.JOB_EXECUTION_FAILURE, job, commandContext.getException())); } CommandConfig commandConfig = commandExecutor.getDefaultConfig().transactionRequiresNew(); FailedJobCommandFactory failedJobCommandFactory = commandContext.getFailedJobCommandFactory(); Command<Object> cmd = failedJobCommandFactory.getCommand(job.getId(), commandContext.getException()); log.trace("Using FailedJobCommandFactory '" + failedJobCommandFactory.getClass() + "' and command of type '" + cmd.getClass() + "'"); commandExecutor.execute(commandConfig, cmd); }
protected void removeObsoleteTimers(ProcessDefinitionEntity processDefinition) { List<Job> jobsToDelete = Context .getCommandContext() .getJobEntityManager() .findJobsByConfiguration(TimerStartEventJobHandler.TYPE, processDefinition.getKey()); for (Job job :jobsToDelete) { new DeleteJobsCmd(job.getId()).execute(Context.getCommandContext()); } }
public JobListItem(Job job) { addItemProperty("id", new ObjectProperty<String>(job.getId(), String.class)); addItemProperty("dueDate", new ObjectProperty<Date>(job.getDuedate(), Date.class)); addItemProperty("name", new ObjectProperty<String>(getName(job), String.class)); }
public void executeJob(String userId, String processInstanceId) { Job job = getJob(processInstanceId); if (job != null) { try { engine.getIdentityService().setAuthenticatedUserId(userId); setStatusVariable(processInstanceId, job); engine.getManagementService().executeJob(job.getId()); } finally { engine.getIdentityService().setAuthenticatedUserId(null); } } }