@Override public void onCommand(TypedRecord<JobRecord> command, CommandControl<JobRecord> commandControl) { final long key = command.getKey(); final int retries = command.getValue().getRetries(); if (retries > 0) { final JobRecord updatedJob = state.updateJobRetries(key, retries); if (updatedJob != null) { commandControl.accept(JobIntent.RETRIES_UPDATED, updatedJob); } else { commandControl.reject(RejectionType.NOT_FOUND, String.format(NO_JOB_FOUND_MESSAGE, key)); } } else { commandControl.reject( RejectionType.INVALID_ARGUMENT, String.format(NEGATIVE_RETRIES_MESSAGE, key, retries)); } } }
@Override public void onCommand(TypedRecord<JobRecord> command, CommandControl<JobRecord> commandControl) { final long key = command.getKey(); final int retries = command.getValue().getRetries(); if (retries > 0) { final JobRecord updatedJob = state.updateJobRetries(key, retries); if (updatedJob != null) { commandControl.accept(JobIntent.RETRIES_UPDATED, updatedJob); } else { commandControl.reject(RejectionType.NOT_FOUND, String.format(NO_JOB_FOUND_MESSAGE, key)); } } else { commandControl.reject( RejectionType.INVALID_ARGUMENT, String.format(NEGATIVE_RETRIES_MESSAGE, key, retries)); } } }
private void assertJobRecordIsEqualTo(final JobRecord jobRecord, final JobRecord expected) { assertThat(jobRecord.getDeadline()).isEqualTo(expected.getDeadline()); assertThat(jobRecord.getWorker()).isEqualTo(expected.getWorker()); assertThat(jobRecord.getRetries()).isEqualTo(expected.getRetries()); assertThat(jobRecord.getType()).isEqualTo(expected.getType()); assertThat(jobRecord.getCustomHeaders()).isEqualTo(expected.getCustomHeaders()); assertThat(jobRecord.getPayload()).isEqualTo(expected.getPayload()); }
private void assertJobRecordIsEqualTo(final JobRecord jobRecord, final JobRecord expected) { assertThat(jobRecord.getDeadline()).isEqualTo(expected.getDeadline()); assertThat(jobRecord.getWorker()).isEqualTo(expected.getWorker()); assertThat(jobRecord.getRetries()).isEqualTo(expected.getRetries()); assertThat(jobRecord.getType()).isEqualTo(expected.getType()); assertThat(jobRecord.getCustomHeaders()).isEqualTo(expected.getCustomHeaders()); assertThat(jobRecord.getPayload()).isEqualTo(expected.getPayload()); }
@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")); } } }
public void fail(long key, JobRecord updatedValue) { final DirectBuffer type = updatedValue.getType(); final long deadline = updatedValue.getDeadline(); validateParameters(type, deadline); zeebeDb.batch( () -> { updateJobRecord(key, updatedValue); final State newState = updatedValue.getRetries() > 0 ? State.ACTIVATABLE : State.FAILED; updateJobState(newState); if (newState == State.ACTIVATABLE) { makeJobActivatable(type); } removeJobDeadline(deadline); }); }
public void fail(long key, JobRecord updatedValue) { final DirectBuffer type = updatedValue.getType(); final long deadline = updatedValue.getDeadline(); validateParameters(type, deadline); zeebeDb.batch( () -> { updateJobRecord(key, updatedValue); final State newState = updatedValue.getRetries() > 0 ? State.ACTIVATABLE : State.FAILED; updateJobState(newState); if (newState == State.ACTIVATABLE) { makeJobActivatable(type); } removeJobDeadline(deadline); }); }
public static ActivateJobsResponse toActivateJobsResponse( long key, JobBatchRecord brokerResponse) { final ActivateJobsResponse.Builder responseBuilder = ActivateJobsResponse.newBuilder(); final Iterator<LongValue> jobKeys = brokerResponse.jobKeys().iterator(); final Iterator<JobRecord> jobs = brokerResponse.jobs().iterator(); while (jobKeys.hasNext() && jobs.hasNext()) { final LongValue jobKey = jobKeys.next(); final JobRecord job = jobs.next(); final ActivatedJob activatedJob = ActivatedJob.newBuilder() .setKey(jobKey.getValue()) .setType(bufferAsString(job.getType())) .setJobHeaders(fromBrokerJobHeaders(job.getHeaders())) .setCustomHeaders(bufferAsJson(job.getCustomHeaders())) .setWorker(bufferAsString(job.getWorker())) .setRetries(job.getRetries()) .setDeadline(job.getDeadline()) .setPayload(bufferAsJson(job.getPayload())) .build(); responseBuilder.addJobs(activatedJob); } return responseBuilder.build(); }
private JobRecordValue ofJobRecord(JobRecord record) { final JobHeaders jobHeaders = record.getHeaders(); final HeadersImpl headers = new HeadersImpl( asString(jobHeaders.getBpmnProcessId()), asString(jobHeaders.getElementId()), jobHeaders.getElementInstanceKey(), jobHeaders.getWorkflowInstanceKey(), jobHeaders.getWorkflowKey(), jobHeaders.getWorkflowDefinitionVersion()); final Instant deadline; if (record.getDeadline() != Protocol.INSTANT_NULL_VALUE) { deadline = Instant.ofEpochMilli(record.getDeadline()); } else { deadline = null; } return new JobRecordValueImpl( objectMapper, asJson(record.getPayload()), asString(record.getType()), asString(record.getWorker()), deadline, headers, asMsgPackMap(record.getCustomHeaders()), record.getRetries(), asString(record.getErrorMessage())); }
private JobRecordValue ofJobRecord(JobRecord record) { final JobHeaders jobHeaders = record.getHeaders(); final HeadersImpl headers = new HeadersImpl( asString(jobHeaders.getBpmnProcessId()), asString(jobHeaders.getElementId()), jobHeaders.getElementInstanceKey(), jobHeaders.getWorkflowInstanceKey(), jobHeaders.getWorkflowKey(), jobHeaders.getWorkflowDefinitionVersion()); final Instant deadline; if (record.getDeadline() != Protocol.INSTANT_NULL_VALUE) { deadline = Instant.ofEpochMilli(record.getDeadline()); } else { deadline = null; } return new JobRecordValueImpl( objectMapper, asJson(record.getPayload()), asString(record.getType()), asString(record.getWorker()), deadline, headers, asMsgPackMap(record.getCustomHeaders()), record.getRetries(), asString(record.getErrorMessage())); }
@Override public void processRecord( TypedRecord<JobRecord> event, TypedResponseWriter responseWriter, TypedStreamWriter streamWriter) { final JobRecord value = event.getValue(); if (value.getRetries() <= 0) { final JobHeaders jobHeaders = value.getHeaders(); final DirectBuffer jobErrorMessage = value.getErrorMessage(); DirectBuffer incidentErrorMessage = DEFAULT_ERROR_MESSAGE; if (jobErrorMessage.capacity() > 0) { incidentErrorMessage = jobErrorMessage; } incidentEvent.reset(); incidentEvent .setErrorType(ErrorType.JOB_NO_RETRIES) .setErrorMessage(incidentErrorMessage) .setBpmnProcessId(jobHeaders.getBpmnProcessId()) .setWorkflowInstanceKey(jobHeaders.getWorkflowInstanceKey()) .setElementId(jobHeaders.getElementId()) .setElementInstanceKey(jobHeaders.getElementInstanceKey()) .setJobKey(event.getKey()); streamWriter.appendNewCommand(IncidentIntent.CREATE, incidentEvent); } } }
final JobRecord value = event.getValue(); if (value.getRetries() <= 0) { final JobHeaders jobHeaders = value.getHeaders();