|
|
|
|
|
- Overview
- Scheduled tasks in the HFSQL Control Center
- Creating a scheduled task
- Deleting a scheduled task
- Modifying a scheduled task
- Scheduled tasks programmatically
- Creating a scheduled task
- Scheduled task execution history
- Manipulating scheduled tasks in WLanguage
- Usage example of HDeclareExternal in a stored procedure
- Example for running the test of a stored procedure
HFSQL Client/Server: Scheduled tasks
Available only with this kind of connection
Scheduled tasks are used to schedule automated processes. You have the ability to define scheduled tasks on the HFSQL server. These scheduled tasks call a stored procedure. By calling a stored procedure, you can execute the code of your choice, e.g. custom maintenance, editing statistics, etc. The scheduled tasks can be managed: Successive execution of multiple scheduled tasks: If the previous scheduled task is not completed, the new scheduled task is not executed, and the server sends a notification.
Scheduled tasks in the HFSQL Control Center Creating a scheduled task In the HFSQL Control Center, scheduled tasks can be defined at server or database level. To create a scheduled task: - If necessary, connect to an HFSQL server and open the description of the server or one of its databases (double-click the server or database name in the tree structure).
- Click the "Scheduled elements" tab.
- In the ribbon, in the "Scheduled elements" group, expand "New scheduling" and select "Schedule a task". The wizard for creating a scheduled task starts.
- Select the task execution mode. The task can be executed:
- Periodically. Then wizard allows you to define how often the task is executed.
- and/or whenever starting the HFSQL server. If this option is selected, you must specify whether:
- the task blocks other tasks. In this case, the HFSQL server will be inaccessible while the task is running.
- the task should be run in the background. In this case, the HFSQL server can be used as soon as it starts up.
- Select:
- the database containing the stored procedure to run.
- the set containing the stored procedure to run.
- the stored procedure to run.
Note: To grant data access to a stored procedure launched from a scheduled task, you must use the HDeclareExternal function. This function is used to declare the data sources that will be used in the processes of the stored procedure. When a stored procedure is launched from the HFSQL Control Center, there is no current analysis and HFSQL Client/Server data is not accessible. If HDeclareExternal is not used in the code of the stored procedure, the procedure will trigger a fatal error, notified in the log of system events. Note: When a stored procedure is started with HExecuteProcedure from a WINDEV, WEBDEV or WINDEV Mobile application, it uses the analysis of the application and can directly use the HFSQL Client/Server data.
- Define the task frequency: month, day, hour.
- Give your scheduled task a description and confirm.
- The scheduled task appears in the "Scheduled elements" tab of the HFSQL Control Center.
Deleting a scheduled task To delete a scheduled task: - If necessary, connect to an HFSQL server and open the corresponding server or database tab.
- Click the "Scheduled elements" tab.
- Select the scheduled task to delete.
- In the ribbon, in the "Scheduled elements" group, click "Delete".
You also have the ability to use the context menu of the scheduled element ("Delete" option).
Modifying a scheduled task To modify a scheduled task: - If necessary, connect to an HFSQL server and open the corresponding server or database tab.
- Click the "Scheduled elements" tab.
- Select the scheduled task to modify.
- In the ribbon, in the "Scheduled elements" group, click "Edit".
You also have the ability to use the context menu of the scheduled element ("Edit" option). - A description window of the scheduled element is displayed. All the characteristics typed in the wizard are grouped in several tabs:
- "General" tab: Defines the task type (backup or stored procedure) and its status (active or inactive).
- "Schedule" tab: Sets the execution options for the scheduled task (month, day, time, number of executions, execution at startup).
New in version 2025"Run history" tab: This tab appears once the scheduled task has been executed automatically. This tab lists the different executions of the scheduled task, indicating: - task start date,
- task status: completed, in progress, failed,
- running time,
- user who launched the task,
- if it was launched manually (with HExecuteScheduling).
- Validate.
Scheduled tasks programmatically Creating a scheduled task Scheduled tasks are managed programmatically using variables of type hScheduledTask and several WLanguage functions. To programmatically create a scheduled task: - Create a variable of type hScheduledTask and define the various characteristics of the scheduled task.
- Add the scheduled task HAddScheduling (or HAddTask).
Remarks: - To add a scheduled task, you must have:
- the rights to manage the tasks (hRightsManageTask constant).
- the rights to run the command linked to the scheduled task.
- The task will be executed with the user credentials defined by the connection.
- For compatibility reasons, it is also possible to create a scheduled task for backing up the database. However, it is recommended to create a scheduled backup. For more details, see How to backup HFSQL Client/Server databases?.
New in version 2025Scheduled task execution history A history is created when the scheduled task is executed automatically (or with HExecuteScheduling). This history can be manipulated programmatically, using a variable of type hSchedulingHistory and the following functions:
| | | Clears the execution history of scheduled jobs on an HFSQL server. | | Deletes the executions of a scheduled job on an HFSQL server. This job can be a scheduled task (stored procedure), backup, optimization or a materialized view refresh. | | Lists the executions of a scheduled job on an HFSQL server. This job can be a scheduled task (stored procedure), backup, optimization or a materialized view refresh. |
Manipulating scheduled tasks in WLanguage Scheduled tasks can be manipulated using: - scheduled task functions:
| | HAddTask | Adds a scheduled task on the server defined by the connection. | HDeleteTask | Deletes a scheduled task from an HFSQL Client/Server server. | HInfoTask | Returns the characteristics of a scheduled task in a hScheduledTask variable]. | HListTask | Lists the scheduled tasks of an HFSQL Client/Server server for a given connection. | HManageTask | Enables or disables a scheduled task on an HFSQL Client/Server server. | HModifyTask | Modifies a scheduled task on the HFSQL server defined by the connection. |
- scheduled element functions (recommended):
| | HAddScheduling | Adds a new scheduled item to an HFSQL server: scheduled task (stored procedure), backup, optimization or refresh of a materialized view. | HDeleteScheduling | Delete a scheduled item on an HFSQL server: scheduled task (stored procedure), backup, optimization, refresh of a materialized view. | HExecuteScheduling | Immediately executes a scheduled item regardless of its scheduling: scheduled task (stored procedure), backup, optimization, refresh of a materialized view. | HListScheduling | Lists scheduled elements defined on an HFSQL server: scheduled tasks (stored procedure), backup, optimization, refresh of a materialized view. | HModifyScheduling | Modify a scheduled item on an HFSQL server: scheduled task (stored procedure), backup, optimization, refresh of a materialized view. |
Usage example of HDeclareExternal in a stored procedure The following procedure declares a data file with HDeclareExternal in order to be able to use it in a scheduled task: PROCEDURE NameOfStoredProcedure()
IF NOT HFileExist(MyConnection, ZIPCODES) THEN
IF NOT HDeclareExternal("ZIPCODES.FIC", "ZIPCODES") THEN
RETURN HErrorInfo()
END
END
RETURN ""
Example for running the test of a stored procedure The following code is used to run the test of a stored procedure in conditions similar to the ones of its execution in a schedules task:
HCloseAnalysis()
cntStockedHFSQLProcedure is Connection
cntStockedHFSQLProcedure.Provider = hAccessHFClientServer
cntStockedHFSQLProcedure.User = "ADMIN"
cntStockedHFSQLProcedure.Password = ""
cntStockedHFSQLProcedure.Server = "ServerName:4900"
cntStockedHFSQLProcedure.Database = "DatabaseName"
HOpenConnection(cntStockedHFSQLProcedure)
IF ErrorOccurred = True THEN
Error("Failure establishing the connection to the HFSQL database", HErrorInfo())
RETURN
END
sRes is string
sRes = HExecuteProcedure(cntStockedHFSQLProcedure, "StoredProcedureName")
...
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|