I’m working on a web app where there could be multiple users who need a recurring process - such as an email sent to them - and the customer’s data files will be in separate folders. The best way that I can see to handle this is to create a console app that is running all the time with a timer that will continually check to see if it is time to send the email. Since the data files are in separate client folders and they could each have different settings for the email, it would have to be a controller app that would periodically check each one and determine if the email should be sent.
Is a console web app that is running all the time the best way to handle this? Our plan is to deploy this app on xojocloud.
As already mentioned, you could just setup Timer in the App.Opening event that will be executed periodically.
As Timers will be executed on the Main Thread, any heavy operation could block processing new browser requests, so move anything that could be blocking them into a Thread. Also, when working with processes that aren’t tied to web sessions, you want to use a Timer instead of a WebTimer and a Thread instead of a WebThread.
Alternatively, if you prefer the helper Console application, the Timer in the sample project would be calling a Shell that executes your helper process, instead of the Thread.
I add the email data into a host database then contact the WebApp with a HandleURL eg https://www.MyCompany.com/SendAllEmails
which sends out all outstanding emails, then updates the database that the email has been sent (or any errors) so they aren’t sent again. No need for a Timer!
If you are running on Xojo cloud and you have the medium server, since every application is running on each server, how do you prevent all three instances of the application from running the timer to check to see if emails should be sent?
I would take a different approach, a single helper app that sends the emails. You could set it up to run in a cronjob every 1m, 5m or whatever your duration is.
If you must do it from your web app, you could store a small data file in the user’s data folder with a timestamp of the most recent email sent. Then at the top of your “send email” routine you check for this file and see if an email has been sent recently, and if so, return.