|
9 | 9 | import software.amazon.lambda.durable.config.WaitForCallbackConfig; |
10 | 10 | import software.amazon.lambda.durable.examples.types.ApprovalRequest; |
11 | 11 | import software.amazon.lambda.durable.exception.SerDesException; |
| 12 | +import software.amazon.lambda.durable.execution.SuspendExecutionException; |
12 | 13 | import software.amazon.lambda.durable.serde.JacksonSerDes; |
13 | 14 |
|
14 | | -<span class="fc" id="L14">public class WaitForCallbackFailedExample extends DurableHandler<ApprovalRequest, String> {</span> |
| 15 | +<span class="fc" id="L15">public class WaitForCallbackFailedExample extends DurableHandler<ApprovalRequest, String> {</span> |
15 | 16 |
|
16 | 17 | @Override |
17 | 18 | public String handleRequest(ApprovalRequest input, DurableContext context) { |
18 | 19 |
|
19 | 20 | String approvalResult; |
20 | 21 |
|
21 | 22 | try { |
22 | | -<span class="pc" id="L22"> approvalResult = context.waitForCallback(</span> |
| 23 | +<span class="pc" id="L23"> approvalResult = context.waitForCallback(</span> |
23 | 24 | "preapproval", |
24 | 25 | String.class, |
25 | 26 | (callbackId, ctx) -> { |
26 | | -<span class="fc" id="L26"> ctx.getLogger().info("Sending callback {} to preapproval system", callbackId);</span> |
27 | | -<span class="fc" id="L27"> throw new RuntimeException("Submitter failed with an exception");</span> |
| 27 | +<span class="fc" id="L27"> ctx.getLogger().info("Sending callback {} to preapproval system", callbackId);</span> |
| 28 | +<span class="fc" id="L28"> throw new RuntimeException("Submitter failed with an exception");</span> |
28 | 29 | }, |
29 | | -<span class="fc" id="L29"> WaitForCallbackConfig.builder()</span> |
30 | | -<span class="fc" id="L30"> .stepConfig(StepConfig.builder()</span> |
31 | | -<span class="fc" id="L31"> .serDes(new FailedSerDes())</span> |
32 | | -<span class="fc" id="L32"> .build())</span> |
33 | | -<span class="fc" id="L33"> .build());</span> |
34 | | -<span class="fc" id="L34"> } catch (Exception ex) {</span> |
35 | | -<span class="fc" id="L35"> return ex.getClass().getSimpleName() + ":" + ex.getMessage();</span> |
36 | | -<span class="nc" id="L36"> }</span> |
| 30 | +<span class="fc" id="L30"> WaitForCallbackConfig.builder()</span> |
| 31 | +<span class="fc" id="L31"> .stepConfig(StepConfig.builder()</span> |
| 32 | +<span class="fc" id="L32"> .serDes(new FailedSerDes())</span> |
| 33 | +<span class="fc" id="L33"> .build())</span> |
| 34 | +<span class="fc" id="L34"> .build());</span> |
| 35 | +<span class="fc" id="L35"> } catch (SuspendExecutionException e) {</span> |
| 36 | + // not to swallow the SuspendExecutionException |
| 37 | +<span class="fc" id="L37"> throw e;</span> |
| 38 | +<span class="fc" id="L38"> } catch (Exception ex) {</span> |
| 39 | +<span class="fc" id="L39"> return ex.getClass().getSimpleName() + ":" + ex.getMessage();</span> |
| 40 | +<span class="nc" id="L40"> }</span> |
37 | 41 |
|
38 | | -<span class="nc" id="L38"> return approvalResult;</span> |
| 42 | +<span class="nc" id="L42"> return approvalResult;</span> |
39 | 43 | } |
40 | 44 |
|
41 | 45 | private static class FailedSerDes extends JacksonSerDes { |
42 | 46 | @Override |
43 | 47 | public <T> T deserialize(String json, TypeToken<T> typeToken) { |
44 | | -<span class="fc" id="L44"> T result = super.deserialize(json, typeToken);</span> |
45 | | -<span class="pc bpc" id="L45" title="1 of 2 branches missed."> if (result instanceof RuntimeException ex) {</span> |
46 | | -<span class="fc" id="L46"> throw new SerDesException("Deserialization failed", ex);</span> |
| 48 | +<span class="fc" id="L48"> T result = super.deserialize(json, typeToken);</span> |
| 49 | +<span class="pc bpc" id="L49" title="1 of 2 branches missed."> if (result instanceof RuntimeException ex) {</span> |
| 50 | +<span class="fc" id="L50"> throw new SerDesException("Deserialization failed", ex);</span> |
47 | 51 | } |
48 | | -<span class="nc" id="L48"> return result;</span> |
| 52 | +<span class="nc" id="L52"> return result;</span> |
49 | 53 | } |
50 | 54 | } |
51 | 55 | } |
|
0 commit comments