Forums

Always-on tasks : how to terminate the code execution

Hello,

I have a script that checks product price on a website every 8 hours and sends notification email once there is promo price instead of a standard price. I want this script running 24/7 and once email is sent I want exit the script. Initially I just entered the file and I pushed the button ">>>Run this file", however I've noticed that console was working for around 2 days and then stopped. I found a feature called "Always-on tasks" which is great, but the problem is that I do not know how to stop the code execution after sending a notification email. The "Always-on tasks" just restarts the code and I do receive email after email which is not great.

Any piece of advice would be highly appreciated. PS. I am quite new in world of py.

I removed exit() from my code so it won't crash. If it doesn't crash, it doesn't restart.

Always-on task is designed to run... always, so restarting is a feature here. It depends on what you actually want to do (e.g. are you interested in only one product and when you find a good price you don't need the task anymore?), but the solution while using Always-on tasks would be to store the product found (which was mailed about) in a database (or a file), so when the code finds it again it compares it against the records of the database and sends the email only when one was not sent for this product. Again, depending on what you actually want to do, you should probably add some logic and timeouts, so the process would not go forever burning your CPU seconds when it's not needed.