Search in sources :

Example 1 with PollForActivityTaskResponse

use of com.uber.cadence.PollForActivityTaskResponse in project cadence-client by uber-java.

the class TestWorkflowStoreImpl method save.

@Override
public long save(RequestContext ctx) throws InternalServiceError, EntityNotExistsError {
    long result;
    lock.lock();
    boolean historiesEmpty = histories.isEmpty();
    try {
        ExecutionId executionId = ctx.getExecutionId();
        HistoryStore history = histories.get(executionId);
        List<HistoryEvent> events = ctx.getEvents();
        if (history == null) {
            if (events.isEmpty() || events.get(0).getEventType() != EventType.WorkflowExecutionStarted) {
                throw new IllegalStateException("No history found for " + executionId);
            }
            history = new HistoryStore(executionId, lock);
            histories.put(executionId, history);
        }
        history.checkNextEventId(ctx.getInitialEventId());
        history.addAllLocked(events, ctx.currentTimeInNanoseconds());
        result = history.getNextEventIdLocked();
        timerService.updateLocks(ctx.getTimerLocks());
        ctx.fireCallbacks(history.getEventsLocked().size());
    } finally {
        if (historiesEmpty && !histories.isEmpty()) {
            // Initially locked in the constructor
            timerService.unlockTimeSkipping();
        }
        lock.unlock();
    }
    // Push tasks to the queues out of locks
    DecisionTask decisionTask = ctx.getDecisionTask();
    if (decisionTask != null) {
        BlockingQueue<PollForDecisionTaskResponse> decisionsQueue = getDecisionTaskListQueue(decisionTask.getTaskListId());
        decisionsQueue.add(decisionTask.getTask());
    }
    List<ActivityTask> activityTasks = ctx.getActivityTasks();
    if (activityTasks != null) {
        for (ActivityTask activityTask : activityTasks) {
            BlockingQueue<PollForActivityTaskResponse> activitiesQueue = getActivityTaskListQueue(activityTask.getTaskListId());
            activitiesQueue.add(activityTask.getTask());
        }
    }
    List<Timer> timers = ctx.getTimers();
    if (timers != null) {
        for (Timer t : timers) {
            timerService.schedule(Duration.ofSeconds(t.getDelaySeconds()), t.getCallback());
        }
    }
    return result;
}
Also used : PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) HistoryEvent(com.uber.cadence.HistoryEvent) Timer(com.uber.cadence.internal.testservice.RequestContext.Timer) PollForActivityTaskResponse(com.uber.cadence.PollForActivityTaskResponse)

Example 2 with PollForActivityTaskResponse

use of com.uber.cadence.PollForActivityTaskResponse in project cadence-client by uber-java.

the class TestWorkflowService method PollForActivityTask.

@Override
public PollForActivityTaskResponse PollForActivityTask(PollForActivityTaskRequest pollRequest) throws BadRequestError, InternalServiceError, ServiceBusyError, TException {
    PollForActivityTaskResponse task;
    while (true) {
        try {
            task = store.pollForActivityTask(pollRequest);
        } catch (InterruptedException e) {
            return new PollForActivityTaskResponse();
        }
        ExecutionId executionId = new ExecutionId(pollRequest.getDomain(), task.getWorkflowExecution());
        TestWorkflowMutableState mutableState = getMutableState(executionId);
        try {
            mutableState.startActivityTask(task, pollRequest);
            return task;
        } catch (EntityNotExistsError e) {
            if (log.isDebugEnabled()) {
                log.debug("Skipping outdated activity task for " + executionId, e);
            }
        }
    }
}
Also used : PollForActivityTaskResponse(com.uber.cadence.PollForActivityTaskResponse) EntityNotExistsError(com.uber.cadence.EntityNotExistsError)

Example 3 with PollForActivityTaskResponse

use of com.uber.cadence.PollForActivityTaskResponse in project cadence-client by uber-java.

the class StateMachines method scheduleActivityTask.

private static void scheduleActivityTask(RequestContext ctx, ActivityTaskData data, ScheduleActivityTaskDecisionAttributes d, long decisionTaskCompletedEventId) {
    ActivityTaskScheduledEventAttributes a = new ActivityTaskScheduledEventAttributes().setInput(d.getInput()).setActivityId(d.getActivityId()).setActivityType(d.getActivityType()).setDomain(d.getDomain() == null ? ctx.getDomain() : d.getDomain()).setHeartbeatTimeoutSeconds(d.getHeartbeatTimeoutSeconds()).setScheduleToCloseTimeoutSeconds(d.getScheduleToCloseTimeoutSeconds()).setScheduleToStartTimeoutSeconds(d.getScheduleToStartTimeoutSeconds()).setStartToCloseTimeoutSeconds(d.getStartToCloseTimeoutSeconds()).setTaskList(d.getTaskList()).setDecisionTaskCompletedEventId(decisionTaskCompletedEventId);
    HistoryEvent event = new HistoryEvent().setEventType(EventType.ActivityTaskScheduled).setActivityTaskScheduledEventAttributes(a);
    long scheduledEventId = ctx.addEvent(event);
    PollForActivityTaskResponse taskResponse = new PollForActivityTaskResponse().setActivityType(d.getActivityType()).setWorkflowExecution(ctx.getExecution()).setActivityId(d.getActivityId()).setInput(d.getInput()).setHeartbeatTimeoutSeconds(d.getHeartbeatTimeoutSeconds()).setScheduleToCloseTimeoutSeconds(d.getScheduleToCloseTimeoutSeconds()).setStartToCloseTimeoutSeconds(d.getStartToCloseTimeoutSeconds()).setScheduledTimestamp(ctx.currentTimeInNanoseconds());
    TaskListId taskListId = new TaskListId(ctx.getDomain(), d.getTaskList().getName());
    ActivityTask activityTask = new ActivityTask(taskListId, taskResponse);
    ctx.addActivityTask(activityTask);
    ctx.onCommit((historySize) -> {
        data.scheduledEvent = a;
        data.scheduledEventId = scheduledEventId;
        data.activityTask = taskResponse;
    });
}
Also used : ActivityTaskScheduledEventAttributes(com.uber.cadence.ActivityTaskScheduledEventAttributes) ActivityTask(com.uber.cadence.internal.testservice.TestWorkflowStore.ActivityTask) PollForActivityTaskResponse(com.uber.cadence.PollForActivityTaskResponse) TaskListId(com.uber.cadence.internal.testservice.TestWorkflowStore.TaskListId) HistoryEvent(com.uber.cadence.HistoryEvent)

Aggregations

PollForActivityTaskResponse (com.uber.cadence.PollForActivityTaskResponse)3 HistoryEvent (com.uber.cadence.HistoryEvent)2 ActivityTaskScheduledEventAttributes (com.uber.cadence.ActivityTaskScheduledEventAttributes)1 EntityNotExistsError (com.uber.cadence.EntityNotExistsError)1 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)1 Timer (com.uber.cadence.internal.testservice.RequestContext.Timer)1 ActivityTask (com.uber.cadence.internal.testservice.TestWorkflowStore.ActivityTask)1 TaskListId (com.uber.cadence.internal.testservice.TestWorkflowStore.TaskListId)1