Scheduled tasks
Scheduled tasks
Can anyone point me in the right direction as to the best way to automate tasks in .Net? For instance, if I needed to run a page that performs some type of maintenance once every 24 hours, what would be the best way to accomplish this?
Thanks for the help.
Scott
Thanks for the help.
Scott
Re: Scheduled tasks
If your site is hosted, many hosting companies provide a scheduled task option where it will activate a given page x number of times per time period. It can also include a user name and password. If that route is available to you, just build a maintenance page that executes the required logic on page load and configure your hosting account to activate it as necessary.
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: Scheduled tasks
I'll be watching this thread because I asked the same a short time ago and the suggestions were to make a script and run a Windows task, like ZLA has suggested.
I know Able must have the code triggered for their maintenance routine somewhere,but I haven't been able to find it. In Able 5, it was in the sessionheader.aspx.
I ended up putting script on my Scriplet.master page to do it. I know that won't work unless someone has accessed the site, but I figured that was the page that would get called the most. Then I put conditional code on there that if the DateTime.Now.Hour == 1 || DateTime.Now.Hour ==13 , wrapped the code to run inside a Try block to try 5 times. It isn't foolproof and I have buttons in the admin to run the routine manually, but I'm still hoping for a better solution. It will run more times than is necessary, but it is a quick routine that won't take many resources.
I know Able must have the code triggered for their maintenance routine somewhere,but I haven't been able to find it. In Able 5, it was in the sessionheader.aspx.
I ended up putting script on my Scriplet.master page to do it. I know that won't work unless someone has accessed the site, but I figured that was the page that would get called the most. Then I put conditional code on there that if the DateTime.Now.Hour == 1 || DateTime.Now.Hour ==13 , wrapped the code to run inside a Try block to try 5 times. It isn't foolproof and I have buttons in the admin to run the routine manually, but I'm still hoping for a better solution. It will run more times than is necessary, but it is a quick routine that won't take many resources.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Re: Scheduled tasks
A friend of mine suggested running a console app and using task scheduler to perform it at intervals. Of course, this would require using the CommerBuilder dlls in the console ap, but, he assures me that its not too difficult. I just didn't know if, like Judy says, there's a way to use existing AC structure to do the same thing.
Scott
Scott
Re: Scheduled tasks
If you go the scheduled task route, you really just need something that opens a particular page. A console app ensures you don't have browser windows opening on your server but you don't need to call the CommerceBuilder dlls directly. Just call them from a web page that the console app hits. You could then use the same maintenance routines and set it up so you can call them manually or remotely.
Now if I only knew how to create such a console app...
Now if I only knew how to create such a console app...

Re: Scheduled tasks
In the beginning, I wrote a page that did all the necessary work in page_load().
Then I just used windows scheduler to launch IE with the page URL on the command line. The task auto-closed the window after 5 minutes so the desktop didn't fill up with pages.
I've been working off-and-on for several months on a job scheduler for AC7 but the project has stalled a number of times for various reasons.
Here's the basis for my job scheduler project: http://www.codeproject.com/KB/aspnet/ASPNETService.aspx
All I can tell you from my experience is that it does work. But it's not completely stable. IIS worker threads get forcibly restarted every so often per the IIS website settings. When that happens, your server-side code thread is gonna get killed along with all the others.
Doing this, in combination with SQL triggers, and your opportunities for automation are practically limitless.
Then I just used windows scheduler to launch IE with the page URL on the command line. The task auto-closed the window after 5 minutes so the desktop didn't fill up with pages.
I've been working off-and-on for several months on a job scheduler for AC7 but the project has stalled a number of times for various reasons.
Here's the basis for my job scheduler project: http://www.codeproject.com/KB/aspnet/ASPNETService.aspx
All I can tell you from my experience is that it does work. But it's not completely stable. IIS worker threads get forcibly restarted every so often per the IIS website settings. When that happens, your server-side code thread is gonna get killed along with all the others.
Doing this, in combination with SQL triggers, and your opportunities for automation are practically limitless.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
Re: Scheduled tasks
When I looked into this in the past, I bookmarked the following links. I make no guarantees about which are any good but let us know if you find one that works:
- http://msdn.microsoft.com/en-us/magazine/cc163821.aspx
- http://www.codeproject.com/KB/dotnet/AB ... ticle.aspx
- http://discuss.joelonsoftware.com/defau ... .333083.16
- http://pubs.logicalexpressions.com/Pub0 ... asp?ID=442
- http://forums.asp.net/p/952567/1164613.aspx#1164613
- http://forums.asp.net/p/743143/743143.aspx#743143
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: Scheduled tasks
I had seen a couple of those .net posts, but thought they might have been overkill for what I wanted and something that I would really have to spend some time developing. I also need a solution that would be easy to implement on any Able site at any hoster.
Here is what Able 5 had in the sessionfooter.aspx:
Maybe that will help us. I don't have a need that the routine run at a specific time, just a few times during one day. I know there has to be something that triggers Able's maintenance routine, or there wouldn't be a setting for the interval in the ablecommerce.config file, but I guess I'm not searching for the correct terms in the source code.
There is a MaintenanceWorker.cs that has all routines to run, but I can't figure out what triggers it.
Here is what Able 5 had in the sessionfooter.aspx:
Code: Select all
'RUN MAINTENANCE ONCE PER HOUR
If (Cache.Item("SGID" & objToken.StoreGroup_ID & "_LastMaintDT") Is Nothing) Then
Dim objStoreCustomFields As ListDictionary = objToken.Store.GetCustomFields()
Dim intAnonLifespan as Integer = FCast.FInt(objStoreCustomFields("AnonLifespan"))
'lifespan must be at least 1, if less then set to default (2 days)
if intAnonLifespan < 1 then intAnonLifespan = 2
cbMaintenance.ClearAnonymousUsers(objToken, intAnonLifespan)
Dim intPaymentLifespan as Integer = FCast.FInt(objStoreCustomFields("PaymentLifespan"))
cbMaintenance.ClearPaymentDetails(objToken, intPaymentLifespan)
objStoreCustomFields = Nothing
cbMaintenance.ArchiveLogs(objToken)
'CACHE LAST MAINTENANCE RUN TIME FOR ONE HOUR
Cache.Add("SGID" & objToken.StoreGroup_ID & "_LastMaintDT", Now(), Nothing, Now.AddHours(1), TimeSpan.Zero, Caching.CacheItemPriority.Normal, Nothing)
end if
There is a MaintenanceWorker.cs that has all routines to run, but I can't figure out what triggers it.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Re: Scheduled tasks
From all those articles, and your experience, Joe, it seems like (since I have access to a dedicated server) the best way to go is with the console ap. One question though... is it possible to write a console ap that you can hit from a webpage? At least that way we wouldn't have to have people logging onto the server in order to change/create scheduled events. Anybody have any experience with this?
Scott
Scott
Re: Scheduled tasks
Hmmm no idea. You're asking a web-based application to execute a server-based application. I'm thinking Microsoft won't be real cooperative on that one 
I'd do the reverse. I'd use Windows Scheduler to launch web pages with .net code that execute your particular functionality.

I'd do the reverse. I'd use Windows Scheduler to launch web pages with .net code that execute your particular functionality.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com