public BrokerUpdateJobRetriesRequest(long jobKey, int retries) { super(ValueType.JOB, JobIntent.UPDATE_RETRIES); request.setKey(jobKey); requestDto.setRetries(retries); }
public BrokerFailJobRequest(long key, int retries) { super(ValueType.JOB, JobIntent.FAIL); request.setKey(key); requestDto.setRetries(retries); }
public JobRecord updateJobRetries(final long jobKey, final int retries) { final JobRecord job = getJob(jobKey); if (job != null) { job.setRetries(retries); updateJobRecord(jobKey, job); } return job; }
public JobRecord updateJobRetries(final long jobKey, final int retries) { final JobRecord job = getJob(jobKey); if (job != null) { job.setRetries(retries); updateJobRecord(jobKey, job); } return job; }
private JobRecord newJobRecord() { final JobRecord jobRecord = new JobRecord(); jobRecord.setRetries(2); jobRecord.setDeadline(256L); jobRecord.setType("test"); return jobRecord; }
private JobRecord newJobRecord() { final JobRecord jobRecord = new JobRecord(); jobRecord.setRetries(2); jobRecord.setDeadline(256L); jobRecord.setType("test"); return jobRecord; }
@Override public void onCommand(TypedRecord<JobRecord> command, CommandControl<JobRecord> commandControl) { final long key = command.getKey(); final JobState.State jobState = state.getState(key); if (jobState == State.ACTIVATED) { final JobRecord failedJob = state.getJob(key); failedJob.setRetries(command.getValue().getRetries()); failedJob.setErrorMessage(command.getValue().getErrorMessage()); state.fail(key, failedJob); commandControl.accept(JobIntent.FAILED, failedJob); } else if (jobState == State.ACTIVATABLE) { commandControl.reject( RejectionType.INVALID_STATE, String.format(NOT_ACTIVATED_JOB_MESSAGE, key, "must be activated first")); } else if (jobState == State.FAILED) { commandControl.reject( RejectionType.INVALID_STATE, String.format(NOT_ACTIVATED_JOB_MESSAGE, key, "is marked as failed")); } else { commandControl.reject( RejectionType.NOT_FOUND, String.format(NOT_ACTIVATED_JOB_MESSAGE, key, "does not exist")); } } }
@Override public void onCommand(TypedRecord<JobRecord> command, CommandControl<JobRecord> commandControl) { final long key = command.getKey(); final JobState.State jobState = state.getState(key); if (jobState == State.ACTIVATED) { final JobRecord failedJob = state.getJob(key); failedJob.setRetries(command.getValue().getRetries()); failedJob.setErrorMessage(command.getValue().getErrorMessage()); state.fail(key, failedJob); commandControl.accept(JobIntent.FAILED, failedJob); } else if (jobState == State.ACTIVATABLE) { commandControl.reject( RejectionType.INVALID_STATE, String.format(NOT_ACTIVATED_JOB_MESSAGE, key, "must be activated first")); } else if (jobState == State.FAILED) { commandControl.reject( RejectionType.INVALID_STATE, String.format(NOT_ACTIVATED_JOB_MESSAGE, key, "is marked as failed")); } else { commandControl.reject( RejectionType.NOT_FOUND, String.format(NOT_ACTIVATED_JOB_MESSAGE, key, "does not exist")); } } }
@Test public void shouldDeleteFailedJob() { // given final long key = 1L; final JobRecord jobRecord = newJobRecord(); // when jobState.create(key, jobRecord); jobState.activate(key, jobRecord); jobState.fail(key, jobRecord.setRetries(0)); jobState.delete(key, jobRecord); // then assertThat(jobState.exists(key)).isFalse(); assertThat(jobState.isInState(key, State.NOT_FOUND)).isTrue(); assertThat(jobState.getJob(key)).isNull(); refuteListedAsActivatable(key, jobRecord.getType()); refuteListedAsTimedOut(key, jobRecord.getDeadline() + 1); }
@Test public void shouldDeleteFailedJob() { // given final long key = 1L; final JobRecord jobRecord = newJobRecord(); // when jobState.create(key, jobRecord); jobState.activate(key, jobRecord); jobState.fail(key, jobRecord.setRetries(0)); jobState.delete(key, jobRecord); // then assertThat(jobState.exists(key)).isFalse(); assertThat(jobState.isInState(key, State.NOT_FOUND)).isTrue(); assertThat(jobState.getJob(key)).isNull(); refuteListedAsActivatable(key, jobRecord.getType()); refuteListedAsTimedOut(key, jobRecord.getDeadline() + 1); }
@Test public void shouldFailJobWithRetriesLeft() { // given final long key = 1L; final JobRecord jobRecord = newJobRecord().setRetries(1); // when jobState.create(key, jobRecord); jobState.activate(key, jobRecord); jobState.fail(key, jobRecord); // then assertThat(jobState.exists(key)).isTrue(); assertJobState(key, State.ACTIVATABLE); assertJobRecordIsEqualTo(jobState.getJob(key), jobRecord); assertListedAsActivatable(key, jobRecord.getType()); refuteListedAsTimedOut(key, jobRecord.getDeadline() + 1); }
@Test public void shouldFailJobWithRetriesLeft() { // given final long key = 1L; final JobRecord jobRecord = newJobRecord().setRetries(1); // when jobState.create(key, jobRecord); jobState.activate(key, jobRecord); jobState.fail(key, jobRecord); // then assertThat(jobState.exists(key)).isTrue(); assertJobState(key, State.ACTIVATABLE); assertJobRecordIsEqualTo(jobState.getJob(key), jobRecord); assertListedAsActivatable(key, jobRecord.getType()); refuteListedAsTimedOut(key, jobRecord.getDeadline() + 1); }
@Test public void shouldFailJobWithNoRetriesLeft() { // given final long key = 1L; final JobRecord jobRecord = newJobRecord().setRetries(0); // when jobState.create(key, jobRecord); jobState.activate(key, jobRecord); jobState.fail(key, jobRecord); // then assertThat(jobState.exists(key)).isTrue(); assertJobState(key, State.FAILED); assertJobRecordIsEqualTo(jobState.getJob(key), jobRecord); refuteListedAsActivatable(key, jobRecord.getType()); refuteListedAsTimedOut(key, jobRecord.getDeadline() + 1); }
@Test public void shouldFailJobWithNoRetriesLeft() { // given final long key = 1L; final JobRecord jobRecord = newJobRecord().setRetries(0); // when jobState.create(key, jobRecord); jobState.activate(key, jobRecord); jobState.fail(key, jobRecord); // then assertThat(jobState.exists(key)).isTrue(); assertJobState(key, State.FAILED); assertJobRecordIsEqualTo(jobState.getJob(key), jobRecord); refuteListedAsActivatable(key, jobRecord.getType()); refuteListedAsTimedOut(key, jobRecord.getDeadline() + 1); }
@Test public void shouldResolveJob() { // given final long key = 1L; final JobRecord jobRecord = newJobRecord(); // when jobState.create(key, jobRecord); jobState.activate(key, jobRecord); jobState.fail(key, jobRecord.setRetries(0)); jobState.resolve(key, jobRecord); // then assertThat(jobState.exists(key)).isTrue(); assertJobState(key, State.ACTIVATABLE); assertJobRecordIsEqualTo(jobState.getJob(key), jobRecord); assertListedAsActivatable(key, jobRecord.getType()); refuteListedAsTimedOut(key, jobRecord.getDeadline() + 1); }
@Test public void shouldResolveJob() { // given final long key = 1L; final JobRecord jobRecord = newJobRecord(); // when jobState.create(key, jobRecord); jobState.activate(key, jobRecord); jobState.fail(key, jobRecord.setRetries(0)); jobState.resolve(key, jobRecord); // then assertThat(jobState.exists(key)).isTrue(); assertJobState(key, State.ACTIVATABLE); assertJobRecordIsEqualTo(jobState.getJob(key), jobRecord); assertListedAsActivatable(key, jobRecord.getType()); refuteListedAsTimedOut(key, jobRecord.getDeadline() + 1); }
private void populateJobFromTask( BpmnStepContext<T> context, WorkflowInstanceRecord value, ExecutableServiceTask serviceTask) { final DirectBuffer headers = serviceTask.getEncodedHeaders(); jobCommand.reset(); jobCommand .setType(serviceTask.getType()) .setRetries(serviceTask.getRetries()) .setPayload(value.getPayload()) .setCustomHeaders(headers) .getHeaders() .setBpmnProcessId(value.getBpmnProcessId()) .setWorkflowDefinitionVersion(value.getVersion()) .setWorkflowKey(value.getWorkflowKey()) .setWorkflowInstanceKey(value.getWorkflowInstanceKey()) .setElementId(serviceTask.getId()) .setElementInstanceKey(context.getRecord().getKey()); } }
@Override public void handle(final BpmnStepContext<ExecutableServiceTask> context) { final WorkflowInstanceRecord value = context.getValue(); final ExecutableServiceTask serviceTask = context.getElement(); jobCommand.reset(); jobCommand .setType(serviceTask.getType()) .setRetries(serviceTask.getRetries()) .setPayload(value.getPayload()) .getHeaders() .setBpmnProcessId(value.getBpmnProcessId()) .setWorkflowDefinitionVersion(value.getVersion()) .setWorkflowKey(value.getWorkflowKey()) .setWorkflowInstanceKey(value.getWorkflowInstanceKey()) .setElementId(serviceTask.getId()) .setElementInstanceKey(context.getRecord().getKey()); final DirectBuffer headers = serviceTask.getEncodedHeaders(); jobCommand.setCustomHeaders(headers); context.getCommandWriter().appendNewCommand(JobIntent.CREATE, jobCommand); } }
.setType(wrapString(type)) .setPayload(PAYLOAD_MSGPACK) .setRetries(retries) .setDeadline(deadline) .setErrorMessage("failed message");
.setType(wrapString(type)) .setPayload(PAYLOAD_MSGPACK) .setRetries(retries) .setDeadline(deadline) .setErrorMessage("failed message");