|
| 1 | +/* |
| 2 | + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved |
| 3 | + * |
| 4 | + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 5 | + * |
| 6 | + * Modifications copyright (C) 2017 Uber Technologies, Inc. |
| 7 | + * |
| 8 | + * Licensed under the Apache License, Version 2.0 (the "License"). You may not |
| 9 | + * use this file except in compliance with the License. A copy of the License is |
| 10 | + * located at |
| 11 | + * |
| 12 | + * http://aws.amazon.com/apache2.0 |
| 13 | + * |
| 14 | + * or in the "license" file accompanying this file. This file is distributed on |
| 15 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 16 | + * express or implied. See the License for the specific language governing |
| 17 | + * permissions and limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package io.temporal.samples.updatabletimer; |
| 21 | + |
| 22 | +import static io.temporal.samples.updatabletimer.DynamicSleepWorkflowWorker.DYNAMIC_SLEEP_WORKFLOW_ID; |
| 23 | +import static io.temporal.samples.updatabletimer.DynamicSleepWorkflowWorker.TASK_LIST; |
| 24 | + |
| 25 | +import io.temporal.client.DuplicateWorkflowException; |
| 26 | +import io.temporal.client.WorkflowClient; |
| 27 | +import io.temporal.client.WorkflowOptions; |
| 28 | +import io.temporal.proto.common.WorkflowExecution; |
| 29 | +import io.temporal.proto.common.WorkflowIdReusePolicy; |
| 30 | +import io.temporal.serviceclient.WorkflowServiceStubs; |
| 31 | +import org.slf4j.Logger; |
| 32 | +import org.slf4j.LoggerFactory; |
| 33 | + |
| 34 | +public class DynamicSleepWorkflowStarter { |
| 35 | + |
| 36 | + private static final Logger logger = LoggerFactory.getLogger(DynamicSleepWorkflowStarter.class); |
| 37 | + |
| 38 | + public static void main(String[] args) { |
| 39 | + WorkflowServiceStubs service = WorkflowServiceStubs.newInstance(); |
| 40 | + WorkflowClient client = WorkflowClient.newInstance(service); |
| 41 | + |
| 42 | + DynamicSleepWorkflow workflow = |
| 43 | + client.newWorkflowStub( |
| 44 | + DynamicSleepWorkflow.class, |
| 45 | + WorkflowOptions.newBuilder() |
| 46 | + .setTaskList(TASK_LIST) |
| 47 | + .setWorkflowId(DYNAMIC_SLEEP_WORKFLOW_ID) |
| 48 | + .setWorkflowIdReusePolicy(WorkflowIdReusePolicy.AllowDuplicate) |
| 49 | + .build()); |
| 50 | + |
| 51 | + try { |
| 52 | + // Start asynchronously |
| 53 | + WorkflowExecution execution = |
| 54 | + WorkflowClient.start(workflow::execute, System.currentTimeMillis() + 60000); |
| 55 | + logger.info("Workflow started: " + execution); |
| 56 | + } catch (DuplicateWorkflowException e) { |
| 57 | + logger.info("Workflow already running: " + e.getExecution()); |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments