Hey everyone! I'm curious if anyone has experience with scripts that need to run for long periods of time, like weeks. I'm not talking about scripts that take ages to process a job; I'm looking for ones that remain active and process quick jobs that only take a few seconds.
If you have such scripts, do you manage memory at all? I've set up a polling script in the past to check for jobs, but it just keeps eating memory. How do you handle this?
5 Answers
Stream processing is the way to go! It lets you fire off scripts based on event triggers, which is much more efficient. If something goes wrong, you won’t miss triggers and it scales better. Check out Windmill for seamless integration with event streams.
I’ve seen success with scripts that run on schedule. A task scheduler can trigger a script every few minutes to check if it needs to run instead of letting something run continuously.
Instead of running a script that loops for days, it’s often better to set up a quick listener that checks for jobs every few minutes. This way, there’s less risk of memory build-up and it’s easier to monitor.
I built a bot that listens for commands via WebSocket. It was solid with memory usage even after days of running. You might want to check your variables—maybe something is growing too large and causing the memory issues.
I had a similar setup that ran for a while. I always keep an extra instance running for resilience, just in case.
If you’re monitoring services, consider using a WMI sink to fire custom events from the event log. This approach is often more effective than a script that runs indefinitely.
That’s a good point! It’s usually more reliable to use a service that can respond to events in real-time rather than risking a script running endlessly.