How To Run More Than 2 Scheduled Jobs

Discussion in 'Hosting Services / Control Panel' started by PeteB, Jan 8, 2010.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hello Group

    I currently have 2 quite light-weight scheduled tasks setup in my control panel. One takes about 5 sec and runs once a week, and the other takes about 2 seconds and runs once a day.

    I'd really like to be able to run a 3rd daily job - really a slight variation on the 2nd job described above.

    I can't readily see a way to do it from the DAP control panel, with 2 jobs per account being the maximum.

    I tried doing a 'redirect' at the end of one of the other jobs (so they are kind of daisy-chained), and although it seems to work if I manually click the link in the control panel (or hit the 'primary' page in a web browser), it doesn't seem to work when the 'primary' scheduled job automatically triggers.

    Is there any way of getting a third job to run out of the scheduler, or daisy-chain one scheduled page to another?

    Thanks for any clues.

    PeteB
     
  2. Do you have control of the page code of the pages being requested by the scheduler? If you do, you can do pretty much whatever you want in those pages with server side code. E.g. A web page is requested by the scheduler and the page behind code includes a number of methods that are each executed in serial sequence.
     
  3. I do have control of the pages being requested (and the additional one that I want to run, but can't quite figure out how to schedule yet), and all pages live in the web site being serviced by the scheduler.

    I don't quite understand what you mean, but like I said in the original post, putting a redirect at the end of page 1, to launch page 2 doesn't seem to work when page 1 is launched via the scheduler - page 1 lads and runs as expected, but it's like the redirect is ignored.
     
  4. mjp

    mjp

    What method are you using to redirect? Generally speaking, the scheduled task will not follow a redirect. It requests the document and moves on to the next task, like a spider or a text browser (like lynx on a *nix box) would. It doesn't behave the way a desktop web browser does.
     
  5. It is currently a response.redirect(http://www...) right at the end of the 1st page.

    Are there any other options that WOULD work?
     
  6. I'm sorry I should have been clearer; here's an example that might help:
    • You create an aspx page that will be requested by the scheduler
    • Your aspx page has code behind
    • When the page is requested by the scheduler, the page OnLoad protected override / Page_Load event executes.
    • At page load time, you can call your page methods sequentially to act as the 'tasks' you would like to be executed at that particular point in time.
    You could even write logic within code behind to execute parts of the script only within certain hours of the day or perhaps on specific days of the week - the possibilities are flexible. Here's one general suggested pattern (obviously the real world code style would vary depending on your application):

    Code:
    using System;
    
    public partial class ScheduledPage : System.Web.UI.Page 
    {
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            bool result = this.ExecuteScheduledTasks();
        }
    
        /// <summary>
        /// Executes the scheduled tasks.
        /// </summary>
        bool ExecuteScheduledTasks()
        {
            bool executeSuccess = false;
            executeSuccess = this.ExecuteTask1();
            if (executeSuccess)
                executeSuccess = this.ExecuteTask2();
            if (executeSuccess)
                executeSuccess = this.ExecuteTask3();
            //etc..
    
            return executeSuccess;
        }
    
        /// <summary>
        /// Executes the task1.
        /// </summary>
        bool ExecuteTask1()
        {
            //TODO:implement task 1 implementation
            throw new NotImplementedException();
        }
    
        /// <summary>
        /// Executes the task2.
        /// </summary>
        bool ExecuteTask2()
        {
            //TODO:implement task 2 implementation
            throw new NotImplementedException();
        }
    
        /// <summary>
        /// Executes the task3.
        /// </summary>
        bool ExecuteTask3()
        {
            //TODO:implement task 3 implementation
            throw new NotImplementedException();
        }            
    }
    
    
     
  7. Thanks, Joe

    I'm a classic ASP kind of guy, rather than a .net one, but I think I see where you're coming from.

    I have taken a similar approach with one of my other scheduled jobs; I have a 'shell' asp page which is the one that gets run on the weekly schedule, and I put all of my 'sub-job' code in separate .inc files and just include the .inc files in the shell as required.

    This seems to work well, and I can expand the amount of work the shell asp job does by adding or removing include files as required.

    The only problem with this approach is that I have to be careful about introducing conflicts between the includes (e.g. variable names, duplicate definitions etc), but maybe it's the way to go.

    In this case it would have been easier for me to just run the separate jobs as 2 separate schedule tasks as they both already exist as separate asp pages, but if I can't run more than 2 scheduled jobs, or can't 'daisy-chain' the asp pages then I can't see another way unless some has a brilliant idea.

    Thanks again for your insight.

    PeteB
     
  8. Ok now I understand better. Mjp has already advised that the scheduler cannot be redirected in the same way as a browser because it will not follow a redirection header in the response..but I don't think all is lost here. Personally I have very little classic ASP experience, but I think your options do still include the classic ASP Server.Transfer and Server.Execute server side methods.

    I think this is certainly worth a try since it will allow you to keep your page code modular (sort of ;-)) and daisy chain the page tasks together. What do you think about this idea? Do you think it could work in this environment?
     
  9. I will give both of those approaches a try over the next few days and see if either work.

    I'll post the results here.

    Thanks a million for the leads.
     
  10. Woo-Hoo! It Works!

    Woo-Hoo!

    Based on your suggestion, Joe, I created a 'shell' asp page and just put a couple of server.executes in; each one pointing to one of the child ASP pages that I wanted to run.

    On scheduling that shell job it seems to work OK.

    I could see that it wouldn't always be a workable solution for joining up pre-existing pages, but for my case it works just fine - and I can still run the jobs separately if I want as they still exist as asp pages in their own right.

    Thanks a heap for the idea.
     
  11. Great news I'm glad it worked out. I thought it would because I expected both Execute and Transfer would work independently to the caller's architecture :)
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page