Link to home
Start Free TrialLog in
Avatar of Bob Schneider
Bob SchneiderFlag for United States of America

asked on

Using a Timer on a Classic ASP/Bootstrap 4 Page

This is a follow-up to a question I posted earlier.  I would like to execute some classic asp code at regular intervals without human interaction (beyond starting a "timer").  The page works very well (sending individual results emails to race finishers and their "followers") but, currently, our staff have to send them manually.  I would like to send them regularly so that our staff can focus on timing the race itself.  


Here is a demo of the page: https://gsetiming.com/ccmeet_admin/manage_meet/results/indiv_rslts_send_test.asp


The goal is to have our staff login, set the frequency that they want the timer to run, and then "Start Timer".  The timer could either "click" the Send Manually button or execute the asp code that clicking that button executes.


Any help would be much appreciated.

Avatar of Scott Bennett
Scott Bennett
Flag of United States of America image

I usually set these kinds of scheduled jobs up using crontab on linux or as a windows scheduled task to hit the url of the job script at regular intervals.. 

If for some reason you don’t have server access (like you’re on a shared hosting environment) you could use JavaScript to run regular ajax requests.


https://makitweb.com/how-to-fire-ajax-request-on-regular-interval/amp/

Avatar of Bob Schneider

ASKER

Thank you but this is is not a task that is best done using windows utilities, etc.  Is will usually be started as runners are finishing a race, and then turned off until the next race in the event is getting finishers.  It will be used sporadically based on our race schedule.  I was looking for an ajax/jquery/json/javascript  web solution (BTW, this is classic asp not asp.net).


Thanks!  (Just got a new response.  I will read it now.  If this is covered in that, please forgive.) 

Scott, your last post looks like what I am looking for.  I will try to piece that together and see what I end up with.  I am not real strong in this area so...

you can probably do someting similar to this to create a form that starts/stops the interval you want to hit the ajax in:

https://jsfiddle.net/mq3buyna/

(I tweaked another jsfiddle example I found to be close to what you need.  you will just have to modify the ppTickk function so that it hits the url via ajax, and tweak the addlog function to log what you want in your table.)

Is the frequencey in seconds or minutes?

Why is the e-mail send code in ASP? Running this in IIS has some problems. Here I would always prefer a Windows service or a scheduled task. Or when it's hosted on Azure/AWS a lambed/serverless function doing this,

@sta5an, he covers most of your question a couple comments ago... doesn't want it running all the time and it looks like they might want the intervals to change unpredictably.

This is incredibly helpful: https://jsfiddle.net/mq3buyna/   Thank you.

I have a question that is the result of my inexperience with ajax and/or connecting ajax to an asp page script execution.  How do I get the button to re-open the page itself (https://gsetiming.com/ccmeet_admin/manage_meet/results/indiv_rslts_send.asp?meet_id=%3C%=lMeetID%%3E&timer_status=on) to initiate the asp or, how can I get it to call the asp sub on that page that contains the script.  

I would not rely on a browsable page to set a timer. What I have done in the past when something needs to be done in an interval is create my asp page that does what I want.  And lets say something has to be done at a variable interval so you can't just set a scheduled task every 1 minute and make it work. 


But what you can do is set your schedule task to run every minute and have it run a vb script on the server. The vb script can check your database for tasks that should be run including what date/time they should be run.


This would mean you have a database table of tasks to run. If somebody schedules the thing to run every 20, then you add a row or rows to the database table with the start/end date/time and a field to note when it was completed that starts out as null.  The scheduled windows task will repeat and as it does, hits your vbs code that checks the database for what needs to run. As it finds the item to run, it marks the completed field with a date.


I hope this makes sense. I have scheduled out variable emails this way where I just ran a scheduled task every 5 minutes and checked if something met the criteria for a one off variable email to be sent or checking if there is new content to download from remote server. 


If you rely on an open browser, it is likely to fail or time out.




personally I would make the code that that you want to execute at regular intervals it's own module/script file that can be run separately from the rest of your page and then returns a json object to whatever calls it. you could include it/call it into your original page so when that page loads, it executes the module. then you could have your ajax hit the module and use the json to write your logs.

I agree and what I was getting at.

@scott Fell... I was writing my last comment at the same time you were writing yours ;)

So include it into the original page as an include (so I can run it manually) and then be able to call it with my ajax?


Bob,

I think that the best practice for this kind of thing is a scheduled job (like I suggested and Scott Fell was describing) that runs every minute, checks for active races and sends the emails when needed based on what races are in progress at the time and log those messages to a db table. Then you can set his screen to just pull from that log table and display the messages that were sent. You could even set up an interval on the screen to auto-refresh the table from the database.
JavaScript based timers are not as reliable and your system could miss sending emails at the appropriate times if the page doesn't load or the user has connectivity issues, etc.

in response to your last comment: yes, separate that code that sends the emails into a re-usable module that can be run by different processes as needed.

SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

I am sure that what you and Scott are suggesting is the best way.  My concern is that I will have people with differing levels of experience running a scheduled job while at a race site, stopping and starting it, etc.  I just don't think that is feasible.  There is not a degree of precision necessary in terms of time, and if the page crashes, we can just re-start it.  We tell people they will get their results within a minute or so of finishing.


I just saw some more comments come in so I will look those over.  If they negate anything I've said here, I apologize.  Please know how much I appreciate this help!!!

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

If no races are running, and there is nothing for the job to do, it will still run every minute (or however often you schedule it) it just won't do anything when nothing needs to be done.

Ok, lets work in that direction.  Here is the scenario.

-We often have multiple events happening simultaneously so the server would have to be able to handle between 1 and 5 events happening at once with different start times.


-Each event typically has several races.  The script is independent of the race being run at a specific time but it does dictate when the timer can be stopped and re-started.


-I would have to pass an event id (querystring/form submission) to the script to tell it which meet's results to send.


-It would be nice, but it is not necessary, to change the interval that the results are sent at.  This is not a hill to die on.


I currently have a classic asp script that manages all that and does it well, but only on command via a form submission on a password protected web site.  At this point, my timers open that page on their phone and manage it accordingly while they go through their other race timing duties.


Thoughts?


I don't have a lot of details on your database, but I would suggest that you a wreite job script that looks for events that are running today. (I'm assuming you have event start/end dates in the event records in your database), Loop through those active event ids and check for races that have results, then send the appropriate emails and mark them as sent in your database.

I'm beginning to like this approach.  


1) So it runs 24/7 or do I have to start it on meet day and stop it when done?  


2) How do I accommodate multiple event simultaneously?

1) yes it would run 24/7 every minute (or however often you want)


2) just sent a comment to answer that, but find active events based on event dates and loop through those event ids to check them all

Since I have a little background in running scheduled tasks, I think I will leave my current web page up for my staff.  It gives them the option to run it manually if they wish but, more importantly, they can see the log of sends to ensure things are going well.


Thank you allfor steering me in this direction!!

once you have the schedule task running, I would modify this status screen to just pull from the database what has been sent by the schedule job, and set this screen to auto refresh the results table screen every minute or so. This way they can see everything is running and things are being sent but the actual sending doesn't rely on javascript in the web browser or users performing any action.

I agree, run it 24/7.


Your database for tasks can be something like


RaceID, Scheduled, Completed

1, 2022-10-04 11:47:00.000, 2022-10-04 11:47:00.000

1, 2022-10-04 11:48:00.000, 2022-10-04 11:48:00.000

1, 2022-10-04 11:49:00.000, NULL

1, 2022-10-04 11:50:00.000, NULL

2, 2022-10-04 11:47:00.000, 2022-10-04 11:47:00.000

2, 2022-10-04 11:48:00.000, 2022-10-04 11:48:00.000

3, 2022-10-04 12:15:00.000, NULL

3, 2022-10-04 12:16:00.000, NULL

3, 2022-10-04 12:17:00.000, NULL



Then your vbs will have an SQL SELECT tasks WHERE Completed IS NULL AND Scheduled <= GETDATE()


Now the results are going to send the Race ID to whatever function needs to be run. If the task is set to 11:49 that would send a "1" based on the data above. When the script is run, you will then run an update SQL to add the current timestamp to the completed.