# Reliable task duration in workflow

**URL:** <https://community.temporal.io/t/reliable-task-duration-in-workflow/1850>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [April 1, 2021, 1:10am UTC](https://community.temporal.io/t/reliable-task-duration-in-workflow/1850 "2021-04-01T01:10:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zzz](https://avatars.discourse-cdn.com/v4/letter/z/cc9497/32.png) [@zzz](https://community.temporal.io/u/zzz)\
**Post date:** [April 1, 2021, 1:10am UTC](https://community.temporal.io/t/reliable-task-duration-in-workflow/1850/1 "2021-04-01T01:10:42Z")

</div>

We want to log how long each step would take:

```
long start = Workflow.currentTimeMillis();
operation1();
long duration = Workflow.currentTimeMillis() - start;

```

My question is if the worker died when it runs operation1(), and temporal restores the workflow. What would happen to the `start`?  
Will the `start` restored to the start timestamp on the first run? Or it will become actual timestamp on the second run (when restoring)?

I am asking this because in former case, the calculated `duration` would be too large: `Duration(end of run 2 - start of run 1)`  
In the latter case, the `duration` would be too small, because in my understanding, all recorded activities will use the recorded results, so the time spent on run 2 will be shorter.

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [April 1, 2021, 1:26am UTC](https://community.temporal.io/t/reliable-task-duration-in-workflow/1850/2 "2021-04-01T01:26:31Z")

</div>

On restore, the `start` will contain the time of the first execution. So duration will be the actual duration of the `operation`.

---

<div class="post-metadata">

**Author:** ![zzz](https://avatars.discourse-cdn.com/v4/letter/z/cc9497/32.png) [@zzz](https://community.temporal.io/u/zzz)\
**Post date:** [April 1, 2021, 6:26pm UTC](https://community.temporal.io/t/reliable-task-duration-in-workflow/1850/3 "2021-04-01T18:26:04Z")

</div>

So if the restoring happens after one day, then the final duration will be one day + actual time spent in operation?

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [April 1, 2021, 7:01pm UTC](https://community.temporal.io/t/reliable-task-duration-in-workflow/1850/4 "2021-04-01T19:01:08Z")

</div>

Correct. But it assumes that the workflow worker has been down for a day. In a normal situation, the recovery will happen immediately after the operation’s completion.

---

<div class="post-metadata">

**Author:** ![zzz](https://avatars.discourse-cdn.com/v4/letter/z/cc9497/32.png) [@zzz](https://community.temporal.io/u/zzz)\
**Post date:** [April 1, 2021, 7:54pm UTC](https://community.temporal.io/t/reliable-task-duration-in-workflow/1850/5 "2021-04-01T19:54:31Z")

</div>

I see. Thanks for confirming this. Do we have a way to know whether there was a recovery? e.g., an API in SDK to get current retry times

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [April 1, 2021, 8:13pm UTC](https://community.temporal.io/t/reliable-task-duration-in-workflow/1850/6 "2021-04-01T20:13:45Z")

</div>

You can watch the workflow task queue _schedule to start_ latency metric. If it starts growing then the workflow workers cannot keep up with the workflow update reate or down.
