banner



How To Create Scheduled Task With Batch File

Available with Data Reviewer license.

  • Exercise 3a: Creating a geoprocessing model
  • Exercise 3b: Exporting the model to a script
  • Exercise 3c: Updating the model parameters
  • Exercise 3d: Create a Windows scheduled task
Complexity:
Beginner
Data Requirement:
ArcGIS Tutorial Data for Desktop
Data Path:
C:\ArcGIS\ArcTutor\DataReviewer
Goal:
To create a model and set it up to run weekly as a Windows scheduled task

Geoprocessing models can be scheduled to run on a regular basis using the Windows Task Scheduler. Similar to running a batch job using the Reviewer Batch Validate tool, the Task Scheduler runs batch jobs and writes the results to the Reviewer table in a specified Reviewer session. Batch jobs can be scheduled to run once at a specific date and time or to run repeatedly at regular intervals.

In this exercise, you will create a model, export it as a script, and use it to create a Windows task that will run the batch job on a daily basis and write the results to a new Reviewer session.

Exercise 3a: Creating a geoprocessing model

The Create Reviewer Session and Execute Reviewer Batch Job geoprocessing tools can be combined in a model. This allows you to model the process so it can be validated before it is converted to a script that will be run as a Windows scheduled task.

  1. Start ArcMap.
  2. Click the ModelBuilder button ModelBuilder on the Standard toolbar.

    The Model window appears.

  3. In the Catalog window, expand Data Reviewer Tools.
  4. Drag the Create Reviewer Session and Execute Batch Job geoprocessing tools to the Model window.
  5. Double-click the Create Reviewer Session tool.

    The Create Reviewer Session dialog box appears.

  6. Click the browse button next to the Reviewer Workspace text box.

    The Reviewer Workspace dialog box appears.

  7. Browse to the Reviewer.gdb file and click Add.

    The Reviewer.gdb file is located at C:\ArcGIS\ArcTutor\DataReviewer.

  8. Type Exercise 3 in the Session Name text box.

    Create Reviewer Session with parameters populated

  9. Click OK.

    The Model window appears. The Create Reviewer Session tool is not ready to run in the model.

    Model window with Create Reviewer Session configured

  10. Double-click the Execute Reviewer Batch Job tool.
  11. Click the Reviewer Workspace drop-down arrow and choose Reviewer.gdb.
  12. Click the Session drop-down arrow and choose Session.

    The session name is incomplete because it has not been created yet. You will fix this later in the exercise.

  13. Click the browse button next to the Batch Job File text box.

    The Open dialog box appears.

  14. Browse to the batch job you created in Exercise 2c and click Open.

    Execute Batch Job dialog box with parameter values

  15. Click the Production Workspace (optional) drop-down arrow and choose California.gdb.
  16. Click OK.

    The Model window appears. The Execute Reviewer Batch Job tool is now ready to run in the model.

    Model with both tools configured to run

  17. Click Model and click Validate Entire Model.

    There are no messages, which means the model is valid.

Exercise 3b: Exporting the model to a script

After the tools are ready to run in a model and the model has been validated, it can be exported to a Python script. In this part of the exercise, you are going to export the model you created to a script that will be used to create a Windows scheduled task.

  1. Click Model > Export > To Python Script.

    The Save As dialog box appears.

  2. Type a name for the script in the File name text box, such as Exercise 3.
  3. Click Save.
  4. Close the Model window.
  5. Click No on the Save Model message.

Exercise 3c: Updating the model parameters

To successfully run, the script needs to be modified to include the Reviewer session name.

  1. Browse to the Exercise 3.py file you created in the previous section.
  2. Right-click the Exercise 3.py file and click Edit with IDLE.

    The Python file opens in the IDLE window.

    Python editor with script

  3. Under # Process: Create Reviewer Session, type Session =.
  4. Under # Local variables, delete Session = " ".

    The final script will resemble the following.

    Revised Python script

  5. Click File > Save to save the changes.
  6. Close the Python editor.

Exercise 3d: Create a Windows scheduled task

The Task Scheduler in Microsoft Windows allows you to schedule a script or application to run at regular intervals. In this exercise, you are going to use the Python script from Exercise 3c to create a scheduled task.

  1. Start the Task Scheduler by doing one of the following.
    • Windows 7: Click the Start menu, type Task Scheduler in the search bar, and press Enter.
    • Windows 8: Open the Control Panel and click System and Security. Under Administrative Tools, click Schedule tasks.

    The Task Scheduler window appears.

  2. Click Create Task.

    Create Task action on the Task Scheduler window

  3. Click the General tab.
  4. Type Execute Batch Job in the Name text box.
  5. Type Run a batch job at regular intervals in the Description text box.

    General tab with Name and Description populated

  6. Click the Triggers tab.
  7. Click New.

    The New Trigger dialog box appears.

  8. In the Settings area, choose Daily.

    New Trigger dialog box with Daily selected

  9. Set the current date and time for Start using the calendar drop-down arrow and time.
  10. Click OK.
  11. Click the Actions tab.
  12. Click New.

    The New Action dialog box appears.

  13. Click Browse next to the Program/script field.

    The Open dialog box appears.

  14. Browse to the script created in Exercise 3c and click Open.

    The New Action dialog box appears with the path to the script.

    New Action dialog box with the path to the script

  15. Click OK.

    The Create Task dialog box appears.

  16. Click OK.

    The Task Scheduler window appears.

  17. Click the Task Scheduler Library node and verify that the Execute Batch Job task appears in the list in the center.

    Task Scheduler with the Execute Batch Job task

In this exercise you created a model and exported it as a Python script. After that, you customized the script and set it up to run as a scheduled task using the Task Scheduler.

How To Create Scheduled Task With Batch File

Source: https://desktop.arcgis.com/en/arcmap/10.5/extensions/data-reviewer/exercise-3-running-batch-jobs-as-a-scheduled-task.htm

Posted by: knighthattlem.blogspot.com

0 Response to "How To Create Scheduled Task With Batch File"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel