public JobExecution(Job job, Configuration configuration, WorkflowInstanceImpl workflowInstance) { this.job = job; this.workflowInstance = workflowInstance; this.time = Time.now(); this.configuration = configuration; }
public ScopeInstanceImpl(ScopeInstanceImpl parent, ScopeImpl scope) { super(parent); this.scope = scope; this.start = Time.now(); }
public boolean isDue() { return dueDate ==null || dueDate.compareTo(Time.now())<=0; }
public void cancel() { if (this.end==null) { this.setEnd(Time.now()); this.endState = ScopeInstance.ENDSTATE_CANCELED; if (activityInstances!=null) { for (ActivityInstanceImpl activityInstance: activityInstances) { activityInstance.cancel(); } } } } }
public LocalDateTime resolve(ActivityInstanceImpl activityInstance) { LocalDateTime baseTime = null; if (activityInstance!=null && base!=null) { baseTime = activityInstance.getValue(base); } if (baseTime==null) { baseTime = Time.now(); } LocalDateTime time = relativeTime.resolve(baseTime); return time; } }
/** * Instructs the engine to propagate execution forwards after ending the current activity instance. */ public void endAndPropagateToParent() { if (this.end == null) { if (hasOpenActivityInstances()) { throw new RuntimeException("Can't end this process instance. There are open activity instances: " + this); } setEnd(Time.now()); if (log.isDebugEnabled()) { log.debug("Ends " + this); } workflowInstanceEnded(); } }
protected BasicDBObjectBuilder buildLockNextJobQuery() { Date now = Time.now().toDate(); return BasicDBObjectBuilder.start() .append("$or", new DBObject[]{ new BasicDBObject(DUE_DATE, new BasicDBObject("$exists", false)), new BasicDBObject(DUE_DATE, new BasicDBObject("$lte", now)) }) .push(DONE).append("$exists", false).pop(); }
protected BasicDBObjectBuilder buildLockNextJobQuery() { Date now = Time.now().toDate(); return BasicDBObjectBuilder.start() .append("$or", new DBObject[]{ new BasicDBObject(DUE_DATE, new BasicDBObject("$exists", false)), new BasicDBObject(DUE_DATE, new BasicDBObject("$lte", now)) }) .push(DONE).append("$exists", false).pop(); }
public void rescheduleFromNow(int delayInMillis) { rescheduleFor(Time.now().plusMillis((int)delayInMillis)); }
public synchronized void lockWorkflowInstance(WorkflowInstanceImpl workflowInstance) { WorkflowInstanceId workflowInstanceId = workflowInstance.getId(); if (lockedWorkflowInstanceIds.contains(workflowInstanceId)) { throw new RuntimeException("Process instance "+workflowInstanceId+" is already locked"); } lockedWorkflowInstanceIds.add(workflowInstanceId); LockImpl lock = new LockImpl(); lock.setTime(Time.now()); lock.setOwner(workflowEngineId); workflowInstance.setLock(lock); if (log.isDebugEnabled()) { log.debug("Locked process instance "+workflowInstanceId); } }
public void end() { if (end==null) { if (hasOpenActivityInstances()) { throw new RuntimeException("Can't end this activity instance. There are open activity instances: " +this); } setEnd(Time.now()); workflow.workflowEngine.notifyActivityInstanceEnded(this); destroyScopeInstance(); setWorkState(null); } }
@Override public WorkflowInstanceImpl lockWorkflowInstanceWithJobsDue() { DBObject query = createLockQuery(); query.put(JobFields.DONE, new BasicDBObject("$exists", false)); query.put(JOBS + "." + JobFields.DUE_DATE, new BasicDBObject("$lte", Time.now().toDate())); DBObject update = createLockUpdate(); DBObject retrieveFields = new BasicDBObject() .append(ARCHIVED_ACTIVITY_INSTANCES, false); BasicDBObject dbWorkflowInstance = workflowInstancesCollection.findAndModify("lock-workflow-instance", query, update, retrieveFields, new BasicDBObject(START, 1), false, true, false); if (dbWorkflowInstance==null) { return null; } WorkflowInstanceImpl workflowInstance = readWorkflowInstanceImpl(dbWorkflowInstance); workflowInstance.trackUpdates(false); return workflowInstance; }
@Override public WorkflowInstanceImpl lockWorkflowInstanceWithJobsDue() { DBObject query = createLockQuery(); query.put(JobFields.DONE, new BasicDBObject("$exists", false)); query.put(JOBS + "." + JobFields.DUE_DATE, new BasicDBObject("$lte", Time.now().toDate())); DBObject update = createLockUpdate(); DBObject retrieveFields = new BasicDBObject() .append(ARCHIVED_ACTIVITY_INSTANCES, false); BasicDBObject dbWorkflowInstance = workflowInstancesCollection.findAndModify("lock-workflow-instance", query, update, retrieveFields, new BasicDBObject(START, 1), false, true, false); if (dbWorkflowInstance==null) { return null; } WorkflowInstanceImpl workflowInstance = readWorkflowInstanceImpl(dbWorkflowInstance); workflowInstance.trackUpdates(false); return workflowInstance; }
public WorkflowInstanceImpl(Configuration configuration, WorkflowImpl workflow, WorkflowInstanceId workflowInstanceId, TriggerInstance triggerInstance, LockImpl lock, Map<String, Object> transientProperties) { this.id = workflowInstanceId; this.configuration = configuration; this.workflow = workflow; this.scope = workflow; this.workflowInstance = this; this.start = Time.now(); this.nextActivityInstanceId = 1l; this.nextVariableInstanceId = 1l; this.nextTimerInstanceId = 1l; this.businessKey = triggerInstance.getBusinessKey(); this.callingWorkflowInstanceId = triggerInstance.getCallingWorkflowInstanceId(); this.callingActivityInstanceId = triggerInstance.getCallingActivityInstanceId(); this.startActivityIds = triggerInstance.getStartActivityIds(); this.lock = lock; this.transientProperties = transientProperties; this.initializeVariableInstances(); }
public DBObject createLockUpdate() { return BasicDBObjectBuilder.start() .push("$set") .push(LOCK) .add(Lock.TIME, Time.now().toDate()) .add(Lock.OWNER, workflowEngine.getId()) .pop() .pop() .get(); }
public DBObject createLockUpdate() { return BasicDBObjectBuilder.start() .push("$set") .push(LOCK) .add(Lock.TIME, Time.now().toDate()) .add(Lock.OWNER, workflowEngine.getId()) .pop() .pop() .get(); }
public Job lockNextJob(DBObject query) { DBObject dbLock = BasicDBObjectBuilder.start() .append(TIME, Time.now().toDate()) .append(OWNER, lockOwner) .get(); DBObject update = BasicDBObjectBuilder.start() .push("$set").append(LOCK, dbLock).pop() .get(); BasicDBObject dbJob = jobsCollection.findAndModify("lock-next-job", query, update); if (dbJob!=null) { return readJob(dbJob); } return null; }
@Test public void testJobOK() throws Exception { jobService.saveJob(new Job() .jobType(new TestJob()) .dueDate(Time.now())); checkWorkflowInstanceJobs(); assertEquals(0, TestJob.jobExecutions.size()); checkJobs(); // only this one should execute the job assertEquals(1, TestJob.jobExecutions.size()); checkJobs(); assertEquals(1, TestJob.jobExecutions.size()); checkWorkflowInstanceJobs(); assertEquals(1, TestJob.jobExecutions.size()); JobExecution jobExecution = TestJob.jobExecutions.get(0); assertNull(jobExecution.error); }
public Job lockNextJob(DBObject query) { DBObject dbLock = BasicDBObjectBuilder.start() .append(TIME, Time.now().toDate()) .append(OWNER, lockOwner) .get(); DBObject update = BasicDBObjectBuilder.start() .push("$set").append(LOCK, dbLock).pop() .get(); BasicDBObject dbJob = jobsCollection.findAndModify("lock-next-job", query, update); if (dbJob!=null) { return readJob(dbJob); } return null; }
@Test public void testUniqueJob() throws Exception { jobService.saveJob(new Job() .key("uniqueid") .jobType(new TestJob()) .dueDate(Time.now())); jobService.saveJob(new Job() .key("uniqueid") .jobType(new TestJob()) .dueDate(Time.now())); checkJobs(); assertEquals(1, TestJob.jobExecutions.size()); } }