Managing Scripts

From QPR ProcessAnalyzer Wiki
Jump to navigation Jump to search

In QPR ProcessAnalyzer, scripts can be used for ETL tasks and to automate routines. Scripts are managed as part of the Project Workspace.

When a script is running, it's not possible to start another run of the same script, but the first run needs to end before starting another. Still, multiple scripts can run at the same time. Scripts can call other scripts and a called scripts can run multiple times simultaneously. In the stack of called scripts, the script log is generated to the top level script. Also the top level script shows that it's running and the called scripts do not.

Scripts List

When selecting a project and opening the Scripts tab, all scripts in the project can be seen. Scripts list shows following information:

  • Name: Name of the script.
  • Status: Status of the script, which is one of following: Ready, Running or Stopping. For more information about script statuses, see below.
  • Last run duration: Duration of the last ended run of the script (the last run result can be any).
  • Last run date: Date and time when the last run was started.
  • Last run result: Result of the last run of the script. Either of following: Completed, Failed or Aborted. For more information about last run results, see below.
  • Id: Id of the script.

Scrips are in either of following statuses:

  • Ready: Script is currently not running, and can be started anytime.
  • Running: Script is currently running, and the script can be stopped. Another run of the same script cannot be started.
  • Stopping: Script is currently being stopped, but it's still running. When a script is in this status, the script cannot be started nor stopped, so you need to wait for the script to stop. There may be a delay in stopping a script, depending on the operation currently performed by the script.

The last script run result can be either of the following:

  • Completed: The last run ended successfully, i.e. without any errors or exceptions. Note that despite of the technically successful run, the script might still not work as intended.
  • Failed: The last run ended to an error or exception. To see more information about the reason of the failure, see the last run log.
  • Aborted: The last run was stopped by a user, so the script did not run till the end.

Editing Script

Open the scripts editor as follows:

  1. On the left side projects hierarchy, select the project where the script is located.
  2. Open the Scripts tab.
  3. Select the script and in the right-click context menu select Edit. Alternatively, you can hover the script and click the Edit button in the end of the row.

The script editor can show multiple scripts in the tabs, allowing to easily switch between the scrips. The editor remembers all scripts that have been opened during the session.

In the script editor, you can:

  • Run the script by clicking the Run button.
  • Stop the running script by clicking the Stop button.
  • Save the script having unsaved changes by clicking the Save button.
  • To run a script having unsaved changes, click the Save and Run button. Note that the script can only be run after saved.
  • To get the up-to-date script status, click the Refresh button.
  • To go back to the list of scripts, click the Go back button. If there are unsaved changes in any of the opened scripts, you need to either save or cancel the changes.
  • To close a script, click the Close button for the tab showing the script. If there are unsaved changes, you need to either save or cancel changes.

Running Script

  1. On the left side projects hierarchy, select the project where the script is located.
  2. Open the Scripts tab.
  3. Select the script and in the right-click context menu select Run. Alternatively, you can hover the script and click the Run button in the end of the row.

Stopping Script

  1. On the left side projects hierarchy, select the project where the script is located.
  2. Open the Scripts tab.
  3. Select the script and from the right-click context menu select Stop. Alternatively, you can hover the script and click the Stop button in the end of the row.
  4. Click the Refresh button to see whether the script run as been stopped.

Viewing Script Log

It's possible to see a script log for the last completed run and also for the current run (if the script is running) as follows:

  1. On the left side projects hierarchy, select the project where the script is located.
  2. Open the Scripts tab.
  3. Select the script and in the right-click context menu select either View last run log or View current run log. The script needs to be running to see the current run log.
  4. If viewing the current run log, you can click the Refresh button to get the latest log entries.

Script logs contain following information:

  • All errors occurring during the script run (script run also stops when an error occurs).
  • All log writing commands in the script code (for SQL scripts --#WriteLog and PRINT commands, and for expression scripts WriteLog function calls).
  • For SQL scripts, all executing scripting commands (commands starting with --#).

Creating Script

  1. On the left side projects hierarchy, select the project where you want to create a script.
  2. Open the Scripts tab.
  3. Click the New button and click Script. Define a name for the script, the scripting Language (either Expression or SQL) and click Create. Note that script names must be unique within a project.

Note that the scripting language cannot be changed after creation, so a new script needs to be recreated to change the language.

Deleting Script

  1. Select the project where the script(s) to be deleted are located.
  2. Open the Scripts tab.
  3. Select one or several scripts to be deleted.
  4. Click the Delete button and click Delete to the confirmation message.

Renaming Script

  1. Select the project where the script to be renamed is located.
  2. Open the Scripts tab.
  3. Select the script to be renamed.
  4. Click the Rename button.
  5. Change the script name in the opening dialog and click OK.

Moving Script

Scripts can be moved by dragging them with the left mouse button from the right side list to the target project in the left side hierarchy. Alternatively, you can first select the scripts, then from the right-click context menu select Move to and finally select the target project.

Duplicating Script

  1. Select the project where the script to be duplicated is located.
  2. Open the Scripts tab.
  3. Select the script to be duplicated.
  4. Click the Duplicate button. A duplicate of the script is created.