# Run clean-up logic in between each Activity retry

**URL:** <https://community.temporal.io/t/run-clean-up-logic-in-between-each-activity-retry/13775>\
**Category:** Community Support\
**Tags:** activity, typescript-sdk\
**Created:** [October 3, 2024, 10:34pm UTC](https://community.temporal.io/t/run-clean-up-logic-in-between-each-activity-retry/13775 "2024-10-03T22:34:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brianluong](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/brianluong/32/5941_2.png) [@brianluong](https://community.temporal.io/u/brianluong)\
**Post date:** [October 3, 2024, 10:34pm UTC](https://community.temporal.io/t/run-clean-up-logic-in-between-each-activity-retry/13775/1 "2024-10-03T22:34:47Z")

</div>

How do you get cleanup logic in between every Activity retry (the Activity failed and is retrying).

I could this by surrounding my Activity in a while loop with try catch in it, but that seems redundant to do with Temporal. Is there a better way?

---

<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:** [October 3, 2024, 11:02pm UTC](https://community.temporal.io/t/run-clean-up-logic-in-between-each-activity-retry/13775/2 "2024-10-03T23:02:54Z")

</div>

You can make it part of the activity. You can use the `Attempt` field in the activity to determine if the cleanup is needed. Retrying from the workflow is the way to go if you need another activity to perform cleanup.
