⚠️ This page has been archived

✅ New page with updated info: ssw.com.au

Home > Archive > SSW Standards > Developer General > SSW Creating Scheduled Jobs on a Server

Standard for Creating Scheduled Jobs on a Server

There are many methods of creating a scheduled job on a server. These include:

  1. SQL Server Jobs
  2. Creating a service (ie an Exe) for the task that will run based on a timer, or put the exe into a schedule.
  3. Creating a web page that will run, called by a windows scheduled task (Start->Programs->Accessories->Scheduled Tasks. The scheduled task command line will be iexplore.exe http://myserver/mypage.asp?action=send or something similar.

Of these choices, the preferred method is by using a web page (or web service if the page would not return any useful data). This is because it is simpler, can be called remotely with no installation, and it is easy to pass query strings to the page to elicit different responses (especially for debugging/testing purposes)

The basic scheduled page should have the following features:

  1. A description/view mode . The page that should display if the page is requested without an additional querystring. For example, if the scheduled job is to send out a batch of emails, the data should be dumped into a datagrid so that the user can preview the data or list of potential recipients. See figure 1 below. This shows the recipients that are about to be sent a reminder email.

    Auto Email Send - Testing Page

    FollowupID

    ReportID

    Email

    6

    1007

    David Klein

    13

    1038

    nhanley@n*tsafe2000.com (Note: Please change "*" in "n*t" to a "e")

    15

    1037

    David Klein

    17

    1046

    ddksup@s*w.com.au

    18

    1046

    ddksup@s*w.com.au

    19

    1046

    ddksup@s*w.com.au

    20

    1046

    ddksup@s*w.com.au

    7

    1007

    ddksup@s*w.com.au

    9

    1016

    David Klein

  2. An action. The querystring should have an action parameter (e.g. sendemail.asp?action=send). This will carry out the action (in this case send) with the data as displayed in the description page (point 1).

One very important point to note is that the page (ie iexplore.exe) will sit in the Windows Scheduled Tasks until manually interrupted. There are two ways around this:

  1. In the setup of the scheduled tasks, set it to terminate a process that runs for longer than XX minutes or hours.

  2. Use JavaScript in the page which automatically closes the window when the action is performed e.g. when action=send is requested (be careful not to close the display page)

    <!--CLOSE THE WINDOW - Otherwise it will just sit there in scheduler. -->
    <script language = javascript>
    window.opener = window;
    window.close();

Here are some other important points:

  1. You do not need to have a display page when you are using a web service for pure maintenance. You can simply call the web service from the schedule, with the appropriate parameters.
  2. You should do at least one test run on the scheduled task before leaving it (ie use the Run feature in the scheduled tasks list.
  3. The scheduled task should be named with the ClientID as a prefix. E.g. SSWTaskShowOrphanedConnections.
  4. You should also put in the %systemroot%/ScheduledTasks/readme.txt file, a description of your task, the frequency of its run, and the reason for its existence.

Acknowledgements

David Klein