# Scope of the global object for rules execution

**URL:** <https://community.auth0.com/t/scope-of-the-global-object-for-rules-execution/18970>\
**Category:** Get Help\
**Tags:** rules, webtask\
**Created:** [December 12, 2018, 2:03am UTC](https://community.auth0.com/t/scope-of-the-global-object-for-rules-execution/18970 "2018-12-12T02:03:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![roshan.lobo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/roshan.lobo/32/9049_2.png) [@roshan.lobo](https://community.auth0.com/u/roshan.lobo)\
**Post date:** [December 12, 2018, 2:03am UTC](https://community.auth0.com/t/scope-of-the-global-object-for-rules-execution/18970/1 "2018-12-12T02:03:08Z")

</div>

Hi,

I have a sequence of 5 rules that are executed for every login flow. As a part of refactoring the rules we are planning to move the common functions to a global variable so that they are defined only once. We plan on using the webtask containers global object to do the same. We know that the global object may be recycled anytime and we should not use it for long persistent storage. We had the below questions in relation to this:

1. Will all the 5 rules run in the same webtask container per execution context? Can 2 rules run in one container and 3 others in another per login flow.
2. If we define the function to the global object in the first rule, is it guaranteed that the same global object is available for all 5 rules. i.e the global object is not refreshed after executing 2 rules, making our common functions unavailable in the 3rd rule.

---

<div class="post-metadata">

**Author:** ![nicolas\_sabena](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nicolas_sabena/32/6064_2.png) [@nicolas\_sabena](https://community.auth0.com/u/nicolas_sabena)\
**Post date:** [December 12, 2018, 12:06pm UTC](https://community.auth0.com/t/scope-of-the-global-object-for-rules-execution/18970/2 "2018-12-12T12:06:19Z")

</div>

Hi!

> [@roshan.lobo](#):
>
> Will all the 5 rules run in the same webtask container per execution context? Can 2 rules run in one container and 3 others in another per login flow.

All rules will run in the same container. The server packages all the rules together to be run as a single webtask.

> [@roshan.lobo](#):
>
> If we define the function to the global object in the first rule, is it guaranteed that the same global object is available for all 5 rules. i.e the global object is not refreshed after executing 2 rules, making our common functions unavailable in the 3rd rule.

That is correct, the same global object will be available for all 5 rules (as a consequence of all rules being treated as a single Webtask run).

---

<div class="post-metadata">

**Author:** ![roshan.lobo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/roshan.lobo/32/9049_2.png) [@roshan.lobo](https://community.auth0.com/u/roshan.lobo)\
**Post date:** [December 13, 2018, 3:56am UTC](https://community.auth0.com/t/scope-of-the-global-object-for-rules-execution/18970/3 "2018-12-13T03:56:50Z")

</div>

Awesome,

Thanks for the confirmation.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 12, 2019, 3:56am UTC](https://community.auth0.com/t/scope-of-the-global-object-for-rules-execution/18970/4 "2019-01-12T03:56:51Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
