public Optional<Workflow> store(Workflow workflow, Consumer<Optional<Workflow>> guard) throws WorkflowInitializationException { try { return storage.runInTransaction(tx -> store(tx, workflow, guard)); } catch (IOException e) { LOG.warn("failed to write workflow {} to storage", workflow.id(), e); throw new RuntimeException(e); } }
private static void initShardRange(Storage storage, String counterId, int startIndex, int endIndex) { try { storage.runInTransaction(tx -> { for (int index = startIndex; index < endIndex; index++) { final Optional<Shard> shard = tx.shard(counterId, index); if (!shard.isPresent()) { tx.store(Shard.create(counterId, index, 0)); } } return null; }); } catch (IOException e) { LOG.warn("Error when trying to create a group of shards in Datastore: ", e); } } }
storage.runInTransaction(tx -> { final Optional<Workflow> workflow = tx.workflow(workflowInstance.workflowId()); if (!workflow.isPresent()) {
private Tuple2<SequenceEvent, RunState> transition(Event event, long expectedCounter) { queuedEvents.decrement(); try { return storage.runInTransaction(tx -> {
while (true) { try { if (!storage.runInTransaction(tx -> triggerNextPartitionAndProgress(tx, backfill.id(), workflow, initialNextTrigger, remainingCapacity, backfill.reverse()))) {
private Response<Backfill> updateBackfill(AuthContext ac, String id, EditableBackfillInput backfillInput) { if (!backfillInput.id().equals(id)) { return Response.forStatus( Status.BAD_REQUEST.withReasonPhrase("ID of payload does not match ID in uri.")); } final Backfill backfill; try { backfill = storage.runInTransaction(tx -> { final Backfill oldBackfill = tx.backfill(id) .orElseThrow(() -> new ResourceNotFoundException(String.format("Backfill %s not found.", id))); workflowActionAuthorizer.authorizeWorkflowAction(ac, oldBackfill.workflowId()); final BackfillBuilder backfillBuilder = oldBackfill.builder(); backfillInput.concurrency().ifPresent(backfillBuilder::concurrency); backfillInput.description().ifPresent(backfillBuilder::description); return tx.store(backfillBuilder.build()); }); } catch (ResourceNotFoundException e) { return Response.forStatus(Status.NOT_FOUND.withReasonPhrase(e.getMessage())); } catch (IOException e) { return Response.forStatus( Status.INTERNAL_SERVER_ERROR.withReasonPhrase("Failed to store backfill.")); } return Response.forStatus(Status.OK).withPayload(backfill); }