Hello all,
I need to create a timer to go off a certain time monthly. Anyone have sample code to do this?
Thanks,
Tim
Hello all,
I need to create a timer to go off a certain time monthly. Anyone have sample code to do this?
Thanks,
Tim
Did you search the docs for web timer?
Hello Brian,
I know how to create and use a timer. What I am having brain difficulty with is to know when the new month/day and time are up.
what you are looking for is Linux Cron schedules?
Or equivalent in the different OS? Windows would be a Schedule, not sure of the Mac equivalent
Could you please expand upon your question on exactly what you are trying to achieve?
On the the first day of the next month at around 1AM I need to have my app do some work. The day and time may change but essentially that is what I am looking for.
Conceptually, I have had a huge brain fart where I cannot think of how to get this to happen using either a Data or DateTime object. I know about cron jobs, but have not used them before. I would rather the app deal with the specifics to get to the date & time.
Hope this helps explain a bit more.
Tim
Also, I need this to happen on the server side, not the client…
Tim
To have your app do this one it’s own, you’d need some way to save the target date and time, read that in your App.Opening event and store it in a variable, then setup a timer to run, say, once every hour to see if DateTime.Now is greater than the target. If it is, perform the action, set the new target date to the variable, then write the new target out so you can load on subsequent launches in case your app crashes or needs to be restarted.
Alternatively, you could create a cron job to call a console app or wget
to your web app that has HandleURL code to perform the action if the request contains some data you specify.
Personally, I’d go with a cron job.
Thanks Anthony.
I have a db where the dates are stored, so that is not a problem. I’ll continue to look into this but I do appreciate Brian and Your suggestions!
Tim
Then it’s just a question of setting up that timer in your App object.
I’d still encourage you to use cron for things like this, though, as it’s a scheduler meant for this sort of thing and is the most reliable solution.
I also encourage cron jobs for such things as this.
Using Cron would me that the app is not running all of the time - correct?
Tim
If you use a console app to perform the functions, yes, it could be done that way. Or, as I said earlier, you could have the cron job use wget
to send a request to your web app that you intercept in the App.HandleURL event .
basically u have a scheduled date/time and a current date/time DateTime.Now
if you need the 1 day, use DateInterval class to add a month and see the many Constructors of the DateTime class.
if (now is greater than scheduled) then you have something to execute and call your method.
if not then have a look few minutes later if the condition is true.
if you use a database table for scheduling i would set a status and return result of execution,
it would make it easy that you can start/repeat this job again if there was a problem.
plus you can add a monitoring.
Anthony’s idea to use wget to make a HTTP request to your Web App is actually very clever and I like it. This way you can implement functionality in the Web App project while having the reliability of a cron job. I personally am not a fan of extremely-long-period Timers.
I have also done a similar technique passing command line parameters to tell the Web App to do something different during App.Opening. At the end of the procedure, the app Quits when done. This results in the effect using a separate Console app but keeping the functionality all in one Web App project.
You can use Lifeboat to edit your cron job and if you need to change the schedule, I wrote up instructions in another thread. I’ve just reworked those into my user guide for the future.
Thanks Tim,
I am looking into that suggestion and appreciate your endorsement.
Lifeboat is a really GREAT tool! Use it very often.
Thanks,
Tim
Hello Tim,
I wrote this crontab-compatible scheduler quite some time ago. From memory it’s an adaptation of something written in Java but not sure. I’ve just had a look and it seems to work with the latest version of Xojo. It was originally for a console application running on Raspberry but I think it should be adaptable to a web application. No documentation, sorry but simple enough to understand and use. Mixing comma and dash for an item is not implemented. Share with the community any improvements that could be made and I’m sure there’s room for that.
CrON4Xojo Test.xojo_binary_project.zip (21.2 KB)
Thanks Pierre!
I will take a look at this, much appreciate the project code.
Tim