Páginas filhas
  • Schedule - How to schedule the execution of routines

Using the schedule tool to automate routine execution

Product:

Microsiga Protheus

Versions:

11 and 12

Step by step:

Concepts


Schedule Protheus allows system routines to be scheduled to be run later, within a period set by the user. You can define when (day, time and number of executions) and in which Group of Companies and Branches the process will be executed. Schedule Protheus does not perform any processing. Its job is to call the scheduled routine at the set time or keep this routine running constantly, when scheduling is set as always active. Memory consumption, performance, and processing are attributes associated with the schedule routine, not the Schedule Protheus itself.
The Schedule Protheus consists of three main components:

  • Manager: Component responsible for managing the tasks, such as task generation control (Task Manager) and queue control of tasks to be executed (Queue Manager).
  • Agent: This is the component that manages executions and distributes the tasks to the set Executes that are currently available. Agents can be found on different servers, allowing the load balancing of executions;
  • Execute: Components responsible for calling the scheduled routines. This is the only entity that consumes license in Schedule Protheus, and it occurs in the execution of the scheduled routine.

Important

Schedule Protheus must always be configured on a single appserver. The Schedule configuration generates control information in the appserver.ini file accessed by the station. In this way, it should always be accessed by the same appserver that configured the service. Preferably the Schedule should be configured in an isolated appserver, and never within a balance.


Monitoring Schedule Protheus services

There are two services configured in the Schedule Protheus.

  • Task Manager: Scheduling verification service. This service is responsible for monitoring the schedules and generating the tasks for execution.
  • Queue Manager: Queue management service. This is the service that distributes the tasks between the configured Agents.

To view these services go to the Configurator module (Sigacfg) and in the menu go to Environment / Schedule / Schedule (CFGA010):




Figure 1 - Schedule Protheus Task Manager and Queue Manager. Services responsible for generating and managing the task queue.


You can manage the services in this interface. The first button allows you to start all services at once. The second one starts the service where it is placed.
The third button stops all services at once and the fourth interrupts the service where it is placed.
Due to the complexity of manipulating the services, there is a fifth button to update this interface. For the Schedule Protheus to work these two services must be started.

Agent Monitoring

This view displays information about the status of Agents and also about the events of each.

Figure 2 - Agent Monitor Here are the status and the date and time of their last update


Registered Agents management is carried out as follows:
The first top button starts all registered Agents. The second button starts only the Agent where it is placed.
The third button interrupts the service of all Agents and the fourth interrupts only the Agent where it is placed.
To execute the tasks, there must be at least one Agent registered with the company equivalent to the task, and the task must be started.
Registering Agents is very simple. Click Agent/Registration to display the registration screen. 


Figure 3- Protheus Schedule Agents Registration Screen
Use the button in the top bar to automatically add an Agent for each of the company groups registered in the system. Each Agent is already set with two Threads to execute the routines.
You can manually add Agents. To do this, at the bottom, under Details, click Add to include the Agent. You have to set a code for the Agent, its name, the IP, communication port and company to which this Agent will connect and the number of Threads available to execute the scheduled routines. You can also disable the Agent, if necessary, or delete it.VERY IMPORTANT: It is recommended to always use the machine's IP address, not the network Alias.
Example: Use 172.16.32.111 instead of Machine_001. 

Within Agent/Monitor it is possible to monitor the positioned Agent.


Figure 4 - Monitoring of registered Agents


You can check whether the Agent is running or not through the Status column.

As of LIB 20180615, Agent Threads are no longer displayed on the Monitor screen, due to a change in the Monitor mechanism. The assignment of Threads to Agents becomes automatic.


Scheduling routines in Schedule Protheus

Registering the routines in Schedule Protheus is very simple. Go to Environment/Schedule/Schedule (CFGA010). Click Schedules to check which routines are scheduled to run. 



Figure 5- View of routines scheduled for execution.


To schedule a new routine, simply go to Registration and add the routine you want to schedule. 


Figure 6 - Interface for handling the routines to be scheduled.

At the bottom, in Detail you can include a new routine by clicking Add. You must include data in the following fields:
Code - The scheduling code is automatically included;

User - The user associated with the execution of the routine has to be linked;

Routine - Routine that will be scheduled. There is a facilitator to find the desired routine (a standard query, or F3). For the query to find the routine:

  • This routine must be in one of the system menus.
  • The associated user must have permission to run the routine to be scheduled.
  • The routine to be scheduled must have the static function Scheddef (see details about the creation of Scheddef in TDN).

The Parameters button will bring up the parameters of the routine, if it has Scheddef defined. For routines that have Scheddef, it is not possible to pass parameters directly in the routine.
Assuming that the TestSched routine has Scheddefdefined. In this case, it must be registered in the Routine field as 'TESTESCHED'. If the routine does not have Scheddef defined, it is possible to pass parameters through the routine itself, in which case the routine can be registered as 'TESTESCHED (parametro1, parametro2, parametroN)'. You can see more details of the difference between routines with and without Scheddef (special process routines) in the topic Preparing a routine to be scheduled in Schedule Protheus.
Date - Set the start date for routine scheduling;

Time - Set the start time of the routine schedule;

Environment - Define in which environment this routine will be executed;

Company/Branch - Define for which company/branch pair the routine will be executed.

Important - Improvement available on label 13102015

From this label, you can make schedules for all branches of the group in a single process, as for routines in which the scheduling branch can be selected and more than one branch can be selected (the EAI Protheus and TOTVS POS do not meet this requirement)

See the example of the following routine. When registering ROTNAX, clicking Company/Branch displays the wizard:

Click Next to display the company group screen:

Select one or all groups of companies here.

Select group 18 and click Next to display the branch screen:

You can either select the branches for which you want to schedule the routine, not select any branch at all or select all of them.

When selecting a branch: A schedule will be generated for that group/branch

When you do not select any branch: A schedule will be generated for the group of companies

When you select all branches: Schedules will be generated for all branches of the system separately.

As each scheduling is formed by the scheduled routine plus the group/branch pair, if no branch is selected, the routine will run in all the system branches in a single process (a single agent thread). This means that the process will continue in a queue, and it will run in one branch at a time, regardless of the number of threads available. If a branch is selected, the processes can run in parallel, since each schedule (routine + group + branch) will be executed on a different agent thread.





Module - Define the module associated with the scheduled routine.
When created like this, the routine will run only on the date and time entered. If it is necessary to repeat the process, you can register a Recurrence as well. 
Click to open the recurrence registration screen. 


Figure 7 - Recurrence register for the scheduled routine.

You can set the routine execution rule. You can set the recurrence pattern (daily, weekly, monthly, annually, and always active, the number of executions, and the end date of this schedule).
You cannot select the number of executions and the end date when the Recurrence pattern is registered as always active. In this type of pattern, the routine is executed in a loop, that is, at the end of its execution it starts again, as long as there are Agent Threads available.
After confirming the inclusion and with the active Manager and Agents services, the routine is ready to be executed by Schedule Protheus.ClickingProtheus. Click Monitor to check the scheduled executions as well as the tasks generated for the registered routine. The events associated with the execution will only be available for routines prepared for scheduling, that is, for those that have SchedDef set.
It is important to highlight the relationship between a schedule and the tasks generated. A schedule generates a task for each company group/branch registered for this schedule.


Figura 8 - Rotinas agendadas e seus eventos associados.

EAI Queue Monitor

In the Schedule Protheus interface you can check the messages trafficked in the EAI Protheus. In the Schedule, select EAI to display the transaction queue.  

Figure 9 - EAI Protheus Transaction Queue


Here you can see the status of the messages received and sent by the EAI Protheus, as well as manage the messages. In the upper bar, you will find four buttons with the following functions: 


The First button allows messages with Processing Failure or Blocked to return to the status Waiting for Processing. Only Asynchronous messages allow reprocessing. Synchronous messages get a Failed status and are no longer reprocessed. Asynchronous messages undergo four attempts of reprocessing automatically and after this, they are only reprocessed with the intervention of the feature of the first button.
The second button blocks a message, and its processing will not be performed unless the Reprocess feature is used.
The third button (magnifying glass) allows you to view the original messages (those that originated the process) or the response messages (the return of the original messages). The last button updates the message interface.
At the bottom you can check the Processing Statusof the messages. Remember that the EAI Protheus, just like Schedule Protheus, does not process the message. The message is processed by a specific routine, commonly known as the EAI Adapter. The information shown at the bottom reflects the processing of this routine. Use the magnifying glass at the bottom to check more details of the processing.


Figure 10 - Detail of EAI Protheus tasks

Clearing Schedule Protheus tables

Through the Schedule Protheus interface you can delete task records from the EAI Protheus message queue or associated events. To do this, click Clear Tables.

Figure 11 - Clearing Schedule Protheus tables


You can select which type of table you want to clear and also set a filter for this procedure:

Figure 12 - Select the EAI table and carry out the procedure with a filter.


Like the example above, select the EAI table and delete only the records that are blocked. Notice that you can add new filters for the procedure.


Figure 13 - Select the 'blocked' filter to bring only the blocked records from the EAI queue.


Only blocked records will be retrieved. Click the delete button in the upper right corner to delete the records.

Preparing a routine to be scheduled in Schedule Protheus


Scheduled routines considerations

Creating a routine to be scheduled in Schedule Protheus is simple, but have some caution. There are some rules and definitions that must be considered in the process. Memory consumption, service crashes, and performance are concerns related to the routine that has been scheduled, not Schedule Protheus.
Be careful with interface components when preparing a routine to run via Schedule or any job. A routine that will be executed only on the server cannot interact with components that need the client to be created. The misuse of these components will generate a communication error and will consequently stop processing.
Notice that Schedule Protheus only triggers the scheduled routine. The problems mentioned above are not related to it.

Delayed schedules

Schedule Protheus maintains an internal control over schedules that have not been executed yet. Due to this feature, if any schedules have not been executed at the correct time, all schedules that should have are started in sequence until the process is normalized. Check the following example:


Figure 14- Example of routine scheduling in Schedule Protheus


Like in the example above, schedule the TestSch routine and then set a recurrence for this schedule:

Figure 15 - Example of recurring scheduling in Schedule Protheus


As shown in figure 15, the process will run daily, every day of the week, with no end date, with 36 executions per day, and a 30 minute interval between executions, starting on 10/27/14 at 00:00 . Click the executions button and check the executions that will be scheduled. Notice that if you register this process at 10:00 AM, when you save the schedule there will be 21 delayed schedules (one every half hour, from 00:00). Schedule Protheus will then start these processes sequentially until all the delayed schedules are normalized, thus reverting to the configured intervals. This feature also applies to cases where the server has been stopped for any reason and the process cannot be initialized at the correct time.

Creating a Special Process routine in Schedule Protheus

A Special Process routine does not have the static Scheddef routine defined. In these cases the scheduled routine passes its parameters directly. A separate thread is started for processing and in this scenario the environment is not assembled and must be treated internally in the scheduled routine. 

The Schedule controls the scheduled task queue to avoid the simultaneous execution of a same task. A task is a routine schedule for a company and branch pair.



Attention. Libs prior to label 04032016

Routines that do not have Scheddef, on labels prior to 04032016, do not have Schedule Protheus queue control. This means that the routine can be executed more than once at the same time in case of the following: there are two schedules for the same routine at the same time, due to a system shutdown, a setting that allows delayed schedules, the routine has a recurrence set as always active or the presence of free agents


In the example below is a routine that does not have a SchedDef:  


Figure 16 - Registration of a special process routine


In the example above, the TestSch routine is registered, sending three parameters to the routine: TestSch('001',2,'003') - A 001 string, a numeric 2 and a second 003 string. As this is a special process, the environment will not be set up by Schedule Protheus, but information will be sent to the routine, if necessary. Then, an array is sent to the special process with the following characteristics:
aArray[1] – First parameter passed in the routine ('001');
aArray[2] – Second parameter passed in the routine (2);
aArray[3] – Third parameter passed in the routine ('003');
aArray[4] – Company associated with routine scheduling;
aArray[5] – Branch associated with routine scheduling;
aArray[6] – User associated with scheduling;
aArray[7] – Scheduling ID.
This way, the parameters passed in the routine are always sent first, and then the company, branch, user and task information are sent.
Check an example of a special process code:




Figure 17 - Example of special process routine


In the example above, the routine will receive the required parameters and will open the environment.
Notice the result of this processing in the Appserver Protheus console, remembering that all Schedule Protheus services must be active for the schedule to run:

Creating a routine with Scheddef in Schedule Protheus without receiving parameters

You can create a scheduled routine in Schedule Protheus by stating the Static Scheddef function in the routine. For further information about Scheddef, visit TDN.
Here is an example of registering a routine that has Scheddef, but no Question (SX1) for the routine:



Figure 18 - Example of routine with Scheddef and without Question

In the example above, the routine will be called by Schedule Protheus with the environment already open, but will not receive any parameters. The scheduled routine runs on the same Schedule thread, and it must return the environment at the end of the processing (for example, it is not possible to change/open or close the environment). This routine will also be processed as a Process (P). 
Schedule this routine and click in the Parameters button: 


Figure 19 - Example of scheduling a routine with Scheddef and without parameters


In this case, the routine has no parameters to display. Schedule this routine to run in company 19, branch D RJ 01 and check the return in console.log.




Opening the environment was not necessary and in these cases, if there are two processes scheduled for the same routine at the same time, the process is serialized so the second one starts only when the first finishes.

Creating a routine with Scheddef in Schedule Protheus receiving parameters from SX1

You will create a new routine with Scheddef, passing a question (SX1) to the routine.


Figure 20 - Function with Scheddef defined with a group of questions


You will schedule this routine, and click the Parameters button:


Figure 21 - Configuration of Schedule with group of questions


Notice that the informed order (Start Date and End Date) could not be selected because the function type was set as a Process (P) in Scheddef.
Check the result in console.log 

Creating a report routine with Scheddef in Schedule Protheus by receiving parameters from SX1


Do the same as the example above, but now the routine to be scheduled will be type Report (R). In this case, you can set the order.



Figure 22 - Example of report routine with group of questions


Figure 23 - Example of scheduling and report routine. In this example, the 'Device' tab is visible and the order can be configured


You can see the result of the routine in the console.log.


Usable Functions in Schedule Protheus

FWGetRunSchedule

Function that returns whether the execution is in the new Schedule Protheus

FWGetRunSchedule(  )

No input parameter.

Return - lRet - Indicates whether or not it is running on Schedule Protheus.

Notes: