Batch environment variables changes

Hey guys,

I’m curious if there is any known way to batch multiple environment variables changes, via the API/node-sdk, to avoid multiple device restarts.

Thanks very much!

Hi, the API does do some batching, it doesn’t apply the changes right away, but after every update, it waits for a couple of seconds to see if there’s anything new coming in, and only after things stopped coming in it restarts the application. :clock:

I’ve tested it out by creating 10x new environment variables with 1s delay between them in the node SDK, and I only got a single application restart, a few seconds after the last environment variable creation call. So it’s definitely workable in this simple case.

How are you trying to update the env vars, can you tell us more about your situation and the issue you run into?

Thanks for your answer!
It sounds like a cool feature! In the app I’m working on, users can manage(add/update/remove) env vars for a device/application so I can’t be sure how much time will be between operations, because it’s at user’s will. This is what I’m facing :slight_smile: The simplest solution we could think of is to send all promises at once.

Yeah, it sounds like if it’s based on user actions, you might want to do some caching on your side. It’s really a trade off between being timely and being efficient. :runner:

:thinking: Or maybe it can be that on your side you have a different user experience for env vars: in the dashboard when one var is saved it is immediately applied. IN your case, I think it could be cool to have users adding env vars, but then explicitly “commit” or “save” those changes, and then you’d submit them as one series… Just a thought :slight_smile:

Thanks for suggestions :slight_smile:

I am working with a similar problem at the moment and the batching sounds promising for our use case. Are the answers given above still valid or do you have anything to add that have changed in the past two years @imrehg?

Hi there @mhe_lorenz,

I’ve just tested this again, and if you are using a parallelized request (via the SDK) you most likely will have the update applied in batch, though there are no guarantees to that batching behavior. For example, running parallelized requests like a Promise.map() from the node SDK limited the number of container restarts to a single restart, but a bash loop using a sleep 1 and the balenaCLI caused three separate container restarts. I have opened an internal issue to discuss this behavior further, and we will update you if we decide to change that!