Search in sources :

Example 1 with JobRecord

use of io.camunda.zeebe.protocol.impl.record.value.job.JobRecord in project zeebe by zeebe-io.

the class BpmnJobBehavior method writeJobCancelCommand.

private void writeJobCancelCommand(final long jobKey) {
    final State state = jobState.getState(jobKey);
    if (state == State.ACTIVATABLE || state == State.ACTIVATED || state == State.FAILED) {
        final JobRecord job = jobState.getJob(jobKey);
        commandWriter.appendFollowUpCommand(jobKey, JobIntent.CANCEL, job);
    }
}
Also used : JobState(io.camunda.zeebe.engine.state.immutable.JobState) State(io.camunda.zeebe.engine.state.immutable.JobState.State) JobRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobRecord)

Example 2 with JobRecord

use of io.camunda.zeebe.protocol.impl.record.value.job.JobRecord in project zeebe-process-test by camunda.

the class GrpcToLogStreamGateway method throwError.

@Override
public void throwError(final ThrowErrorRequest request, final StreamObserver<ThrowErrorResponse> responseObserver) {
    executor.submit(() -> {
        final Long requestId = registerNewRequest(responseObserver);
        prepareRecordMetadata().requestId(requestId).valueType(ValueType.JOB).intent(JobIntent.THROW_ERROR);
        final JobRecord jobRecord = new JobRecord();
        jobRecord.setErrorCode(BufferUtil.wrapString(request.getErrorCode()));
        jobRecord.setErrorMessage(request.getErrorMessage());
        writeCommandWithKey(request.getJobKey(), recordMetadata, jobRecord);
    });
}
Also used : JobRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobRecord) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 3 with JobRecord

use of io.camunda.zeebe.protocol.impl.record.value.job.JobRecord in project zeebe-process-test by camunda.

the class GrpcToLogStreamGateway method updateJobRetries.

@Override
public void updateJobRetries(final UpdateJobRetriesRequest request, final StreamObserver<UpdateJobRetriesResponse> responseObserver) {
    executor.submit(() -> {
        final Long requestId = registerNewRequest(responseObserver);
        prepareRecordMetadata().requestId(requestId).valueType(ValueType.JOB).intent(JobIntent.UPDATE_RETRIES);
        final JobRecord jobRecord = new JobRecord();
        jobRecord.setRetries(request.getRetries());
        writeCommandWithKey(request.getJobKey(), recordMetadata, jobRecord);
    });
}
Also used : JobRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobRecord) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 4 with JobRecord

use of io.camunda.zeebe.protocol.impl.record.value.job.JobRecord in project zeebe by camunda.

the class JobFailProcessor method acceptCommand.

private void acceptCommand(final TypedRecord<JobRecord> command, final CommandControl<JobRecord> commandControl, final Consumer<SideEffectProducer> sideEffect) {
    final long key = command.getKey();
    final JobRecord failedJob = jobState.getJob(key);
    final var retries = command.getValue().getRetries();
    final var retryBackOff = command.getValue().getRetryBackoff();
    failedJob.setRetries(retries);
    failedJob.setErrorMessage(command.getValue().getErrorMessageBuffer());
    failedJob.setRetryBackoff(retryBackOff);
    if (retries > 0 && retryBackOff > 0) {
        final long receivedTime = command.getTimestamp();
        failedJob.setRecurringTime(receivedTime + retryBackOff);
        sideEffect.accept(() -> {
            jobBackoffChecker.scheduleBackOff(retryBackOff + receivedTime);
            return true;
        });
    }
    commandControl.accept(JobIntent.FAILED, failedJob);
    jobMetrics.jobFailed(failedJob.getType());
}
Also used : JobRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobRecord)

Example 5 with JobRecord

use of io.camunda.zeebe.protocol.impl.record.value.job.JobRecord in project zeebe by camunda.

the class JobUpdateRetriesProcessor method onCommand.

@Override
public boolean onCommand(final TypedRecord<JobRecord> command, final CommandControl<JobRecord> commandControl) {
    final long key = command.getKey();
    final int retries = command.getValue().getRetries();
    if (retries > 0) {
        final JobRecord job = jobState.getJob(key);
        if (job != null) {
            // update retries for response sent to client
            job.setRetries(retries);
            commandControl.accept(JobIntent.RETRIES_UPDATED, job);
        } 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));
    }
    return true;
}
Also used : JobRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobRecord)

Aggregations

JobRecord (io.camunda.zeebe.protocol.impl.record.value.job.JobRecord)183 Test (org.junit.Test)96 GatewayTest (io.camunda.zeebe.gateway.api.util.GatewayTest)15 BrokerResponse (io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse)9 LongValue (io.camunda.zeebe.msgpack.value.LongValue)9 CompleteJobResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.CompleteJobResponse)8 IncidentRecord (io.camunda.zeebe.protocol.impl.record.value.incident.IncidentRecord)8 DirectBuffer (org.agrona.DirectBuffer)8 RecordMetadata (io.camunda.zeebe.protocol.impl.record.RecordMetadata)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 BrokerCompleteJobRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerCompleteJobRequest)6 CompleteJobRequest (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.CompleteJobRequest)6 JobState (io.camunda.zeebe.engine.state.immutable.JobState)5 State (io.camunda.zeebe.engine.state.immutable.JobState.State)5 ActivateJobsResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsResponse)5 ActivatedJob (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivatedJob)5 FailJobResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.FailJobResponse)5 UpdateJobRetriesResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.UpdateJobRetriesResponse)5 DeploymentRecord (io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)5 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)5