# Script timing out before all entities in a batch are processed

**URL:** <https://community.fibery.io/t/script-timing-out-before-all-entities-in-a-batch-are-processed/7506>\
**Category:** Get Help\
**Created:** [October 8, 2024, 6:35pm UTC](https://community.fibery.io/t/script-timing-out-before-all-entities-in-a-batch-are-processed/7506 "2024-10-08T18:35:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![interr0bangr](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/interr0bangr/32/8089_2.png) [@interr0bangr](https://community.fibery.io/u/interr0bangr)\
**Post date:** [October 8, 2024, 6:35pm UTC](https://community.fibery.io/t/script-timing-out-before-all-entities-in-a-batch-are-processed/7506/1 "2024-10-08T18:35:36Z")

</div>

We’re having an issue with a script timing out before it can finish running for all entities in the batch.

 ![Client-Fibery (3)](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/4/4d3e5b2a3308bd67e26ff9d43b6a203b0feb7002.jpeg)

The goal for this script is that every day at midnight, all want all the active ad campaigns we’re running in Google Ads to be created (or updated if they already exist) in Fibery.

Is there a way to force the timer to reset for each entity in the batch, or to force the script to run separately & sequentially for each entity in the batch?

It runs fine if we trigger it as a button on an individual entity, but we want to run automatically once a day.

---

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [October 8, 2024, 8:18pm UTC](https://community.fibery.io/t/script-timing-out-before-all-entities-in-a-batch-are-processed/7506/2 "2024-10-08T20:18:35Z")

</div>

My recommendation would be to segment your entities into different batches that get processed separately by different Rules (all of which do the exact same thing, but only to a subset of entities).

E.g. assuming you’re going to segment your entities into 4 batches:

- create a “Batch number” field that is assigned by a script on entity creation, to a value like `parseInt(entity['Public Id']) % 4` (javascript) - i.e. giving a value between [0, 3].
- make four separate processing Rules, each of which filters for entities with a specific Batch number, but otherwise performs the exact same processing as the other Rules
- offset the Rule trigger times so they won’t run simultaneously

The downside is that you now need to maintain four Rules instead of one.

---

<div class="post-metadata">

**Author:** ![interr0bangr](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/interr0bangr/32/8089_2.png) [@interr0bangr](https://community.fibery.io/u/interr0bangr)\
**Post date:** [October 8, 2024, 8:52pm UTC](https://community.fibery.io/t/script-timing-out-before-all-entities-in-a-batch-are-processed/7506/3 "2024-10-08T20:52:00Z")

</div>

> [@Matt\_Blais](#):
>
> The downside is that you now need to maintain four Rules instead of one.

Yeah that’s super annoying!

---

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [October 8, 2024, 8:56pm UTC](https://community.fibery.io/t/script-timing-out-before-all-entities-in-a-batch-are-processed/7506/4 "2024-10-08T20:56:10Z")

</div>

This was actually one of the reasons I wrote the [Fibery Script Management tool](https://community.fibery.io/t/beta-testers-wanted-for-fibery-script-management-tool/5466) – so I could write and maintain a single script that could be automatically pushed to multiple Rules (that’s what the tool’s “include” feature is for).
