What I’m trying to do:
Fully understand Anvil Docs | Scripts. It seems to be a fairly recent addition.
Looks like a great way to to slim down the loaded set of Server Modules, by factoring out the occasional background task, or other code-heavy (and less-used) application features. I might try it out some time soon.
What I’ve read and what’s not clear:
Scripts execute in the trusted server environment
Well, yes, but which one? In many Apps I have Dev, Test, and Prod, plus the IDE-only Debug environments. Some apps may have customer-specific environments, as well.
A reasonable guess would be as follows:
- If the script is invoked from the IDE, then it runs in the Debug Environment. Otherwise,
- If the script is invoked from a Server Module, then it runs in that Server Module’s Environment. Otherwise,
- If the script is invoked from a Client Module, then it runs in that Client’s Server Module Environment.
What difference does this make? Well, if you’re going to
return rich data including … database records.
then it may be very important to know which Table(s) (i.e., from which database) those database records are coming from!
Not listed, and I’m guessing here, too:
- If the script is invoked as a Scheduled Task, then it runs in each of the Scheduled-Task-Enabled Environments, in turn.
- If the script is invoked by another script, then it runs in the parent script’s Environment.
It’s not clear whether this second script gets its own five-minute run-time, or is running on its parent’s clock.
My assumptions above are based on the principle of least surprise. That is, the script will use the same environment as the code that invoked it, or if no code invoked it, the Debug environment.