1s routine task is being executed. Routine and background tasks

When working in 1C, there are many routine operations that must be launched or formed according to a schedule to perform one or another action, for example: posting documents or loading data into 1C from a website.

I recently posted an article: It's time to automate this:

Routine and background tasks

The job engine is designed to perform any application or functionality on a schedule or asynchronously.

The task mechanism solves the following problems:

  • Ability to define regulatory procedures at the system configuration stage;
  • Execution of specified actions according to schedule;
  • Making a call to a given procedure or function asynchronously, i.e. without waiting for its completion;
  • Tracking the progress of a specific task and obtaining its completion status (a value indicating whether it was successful or not);
  • Obtaining a list of current tasks;
  • Ability to wait for one or more tasks to complete;
  • Job management (possibility of cancellation, blocking of execution, etc.).

The job mechanism consists of the following components:

  • Metadata of routine tasks;
  • Regular tasks;
  • Background jobs;
  • Task Scheduler.

Background jobs & are designed to perform application tasks asynchronously. Background tasks are implemented using the built-in language.

Scheduled tasks & are designed to perform application tasks on a schedule. Routine tasks are stored in the information base and are created based on metadata defined in the configuration. Metadata of a regulatory task contains information such as name, method, use, etc.

A routine task has a schedule that determines at what times the method associated with the routine task must be executed. The schedule, as a rule, is specified in the information base, but can also be specified at the configuration stage (for example, for predefined routine tasks).

The task scheduler is used to schedule the execution of routine tasks. For each scheduled job, the scheduler periodically checks whether the current date and time matches the schedule of the scheduled job. If it matches, the scheduler assigns that task to execution. To do this, for this scheduled task, the scheduler creates a background task, which performs the actual processing.

I think that’s enough with the description - let’s get down to implementation:

Creating a routine task

Method name– path to the procedure that will be executed in a background job according to a given schedule. The procedure must be in a common module. It is recommended not to use standard common modules, but to create your own. Don't forget that background jobs run on the server!

Usage– sign of using a routine task.

Predetermined– indicates whether the routine task is predetermined.

If you want the routine task to work immediately after being placed in the database, specify the attribute Predetermined. Otherwise, you will need to use the “Job Console” processing or trigger the task to run programmatically.

Number of retries when a job terminates abnormally– how many times the background job was restarted if it was executed with an error.

Retry interval when job terminates abnormally– how often the background job will be restarted if it was completed with an error.

Setting up a schedule

Schedule completing the task:

Every hour, just one dayRepeatDays Period = 0, RepeatDays Period = 3600
Every day once a dayRepeatDays Period = 1, RepeatDays Period = 0
One day, one timePeriodRepeatDays = 0
Every other day once a dayPeriodRepeatDays = 2
Every hour from 01.00 to 07.00 every dayPeriodRepeatDays = 1RepeatPeriodDuringDay = 3600StartTime = 01.00

End Time = 07.00

Every Saturday and Sunday at 09.00RepeatDays Period = 1WeekDays = 6, 7StartTime = 09.00
Every day for one week, skip a weekPeriodRepeatDays = 1PeriodWeeks = 2
At 01.00 onceStart Time = 01.00
Last day of every month at 9:00.PeriodRepeatDays = 1DayInMonth = -1StartTime = 09.00
Fifth day of every month at 9:00PeriodRepeatDays = 1DayInMonth = 5StartTime = 09.00
Second Wednesday of every month at 9:00PeriodRepeatDays = 1DayWeekMonth = 2DaysWeek = 3

Start Time = 09.00

Features of executing background jobs in file and client-server variants

The mechanisms for executing background jobs in the file and client-server versions are different.

In file version you need to create a dedicated client process that will perform background jobs. To do this, the client process must periodically call the global context function ExecuteJobProcessing. Only one client process per infobase should process background jobs (and, accordingly, call this function). If a client process has not been created to process background jobs, then when programmatically accessing the job engine, the error “Job Manager is not active” will be displayed. It is not recommended to use a client process that processes background jobs for other functions.

Once the client process processing background jobs is started, other client processes are able to programmatically access the background job engine, i.e. can run and manage background jobs.

In client-server version To execute background jobs, a task scheduler is used, which is physically located in the cluster manager. For all queued background jobs, the scheduler gets the least loaded worker process and uses it to run the corresponding background job. The worker process executes the job and notifies the scheduler of the execution results.

In the client-server version, it is possible to block the execution of routine tasks. The execution of routine tasks is blocked in the following cases:

  • An explicit blocking of routine tasks has been installed on the information base. The lock can be set via the cluster console;
  • There is a connection block on the infobase. The lock can be set via the cluster console;
  • The SetExclusiveMode() method with the True parameter was called from the built-in language;
  • In some other cases (for example, when updating the database configuration).

Processing the launch and viewing of scheduled tasks you can download here.

When working in 1C, there are many routine operations that must be launched or formed according to a schedule to perform one or another action, for example: posting documents or loading data into 1C from a website.

I recently posted an article: It's time to automate this:

Routine and background tasks

The job engine is designed to perform any application or functionality on a schedule or asynchronously.

The task mechanism solves the following problems:

  • Ability to define regulatory procedures at the system configuration stage;
  • Execution of specified actions according to schedule;
  • Making a call to a given procedure or function asynchronously, i.e. without waiting for its completion;
  • Tracking the progress of a specific task and obtaining its completion status (a value indicating whether it was successful or not);
  • Obtaining a list of current tasks;
  • Ability to wait for one or more tasks to complete;
  • Job management (possibility of cancellation, blocking of execution, etc.).

The job mechanism consists of the following components:

  • Metadata of routine tasks;
  • Regular tasks;
  • Background jobs;
  • Task Scheduler.

Background jobs & are designed to perform application tasks asynchronously. Background tasks are implemented using the built-in language.

Scheduled tasks & are designed to perform application tasks on a schedule. Routine tasks are stored in the information base and are created based on metadata defined in the configuration. Metadata of a regulatory task contains information such as name, method, use, etc.

A routine task has a schedule that determines at what times the method associated with the routine task must be executed. The schedule, as a rule, is specified in the information base, but can also be specified at the configuration stage (for example, for predefined routine tasks).

The task scheduler is used to schedule the execution of routine tasks. For each scheduled job, the scheduler periodically checks whether the current date and time matches the schedule of the scheduled job. If it matches, the scheduler assigns that task to execution. To do this, for this scheduled task, the scheduler creates a background task, which performs the actual processing.

I think that’s enough with the description - let’s get down to implementation:

Creating a routine task

Method name– path to the procedure that will be executed in a background job according to a given schedule. The procedure must be in a common module. It is recommended not to use standard common modules, but to create your own. Don't forget that background jobs run on the server!

Usage– sign of using a routine task.

Predetermined– indicates whether the routine task is predetermined.

If you want the routine task to work immediately after being placed in the database, specify the attribute Predetermined. Otherwise, you will need to use the “Job Console” processing or trigger the task to run programmatically.

Number of retries when a job terminates abnormally– how many times the background job was restarted if it was executed with an error.

Retry interval when job terminates abnormally– how often the background job will be restarted if it was completed with an error.

Setting up a schedule

Schedule completing the task:

Every hour, just one dayRepeatDays Period = 0, RepeatDays Period = 3600
Every day once a dayRepeatDays Period = 1, RepeatDays Period = 0
One day, one timePeriodRepeatDays = 0
Every other day once a dayPeriodRepeatDays = 2
Every hour from 01.00 to 07.00 every dayPeriodRepeatDays = 1RepeatPeriodDuringDay = 3600StartTime = 01.00

End Time = 07.00

Every Saturday and Sunday at 09.00RepeatDays Period = 1WeekDays = 6, 7StartTime = 09.00
Every day for one week, skip a weekPeriodRepeatDays = 1PeriodWeeks = 2
At 01.00 onceStart Time = 01.00
Last day of every month at 9:00.PeriodRepeatDays = 1DayInMonth = -1StartTime = 09.00
Fifth day of every month at 9:00PeriodRepeatDays = 1DayInMonth = 5StartTime = 09.00
Second Wednesday of every month at 9:00PeriodRepeatDays = 1DayWeekMonth = 2DaysWeek = 3

Start Time = 09.00

Features of executing background jobs in file and client-server variants

The mechanisms for executing background jobs in the file and client-server versions are different.

In file version you need to create a dedicated client process that will perform background jobs. To do this, the client process must periodically call the global context function ExecuteJobProcessing. Only one client process per infobase should process background jobs (and, accordingly, call this function). If a client process has not been created to process background jobs, then when programmatically accessing the job engine, the error “Job Manager is not active” will be displayed. It is not recommended to use a client process that processes background jobs for other functions.

Once the client process processing background jobs is started, other client processes are able to programmatically access the background job engine, i.e. can run and manage background jobs.

In client-server version To execute background jobs, a task scheduler is used, which is physically located in the cluster manager. For all queued background jobs, the scheduler gets the least loaded worker process and uses it to run the corresponding background job. The worker process executes the job and notifies the scheduler of the execution results.

In the client-server version, it is possible to block the execution of routine tasks. The execution of routine tasks is blocked in the following cases:

  • An explicit blocking of routine tasks has been installed on the information base. The lock can be set via the cluster console;
  • There is a connection block on the infobase. The lock can be set via the cluster console;
  • The SetExclusiveMode() method with the True parameter was called from the built-in language;
  • In some other cases (for example, when updating the database configuration).

Processing the launch and viewing of scheduled tasks you can download here.

Often, when maintaining records, there is a need to periodically perform certain actions without user intervention. Routine and background tasks in 1C are those mechanisms that are provided for this purpose in the eighth version of the program and allow:

  • Set up timely delivery of documents;
  • Calculate balances and totals;
  • Ensure frequency of mailing;
  • Check and delete irrelevant data.

Background and scheduled task - what is it and where is it configured?

A routine task is a mechanism built into 1C that allows you to configure and, in accordance with the established schedule and frequency, perform a certain sequence of actions.

A background job is an action generated by a routine operation and does not require direct user participation.

A routine task is created in the configurator mode:

  • In the configuration tree window we find the corresponding branch (Fig. 1);
  • Click the add button;
  • In the window that opens, you must specify a name that allows you to identify the object in the configuration;

Fig.2

  • Opposite the inscription “Schedule” (Fig. 2) there is an inscription “Open”, clicking on which opens a window for setting the time and frequency of execution of the handler (Fig. 3);

Fig.3

  • It is also necessary to fill in the “Method name” (the name of the procedure called from the general module and describing the behavior algorithm of the program will be entered here);
  • The “Name” and “Key” fields allow you to group objects;
  • The checked “Use” checkbox indicates the activity of the scheduled operation;
  • “Predefined” should be set if the handler should be launched immediately after it is added to the database, otherwise the launch can be done from the corresponding processing (more about it below);
  • The “Number of retries” and “Retry interval” parameters describe the program’s behavior if an exception occurs while executing a background job.

So, using the mechanism of routine operations, you can set the schedule and main actions of background jobs. Let's now look at their features.

Features of background jobs

The main feature of this mechanism is that the background process runs asynchronously.

What does this mean? The fact is that with a synchronous work model, if any algorithm is executed, the user interface is blocked. In our case, the user can continue to enter and edit data even if the procedure is running. The asynchronous programming model involves separation of computational threads.

Thus, background jobs in 1C can spawn their own processes, distributing calculations across various servers included in the same cluster.

Features of working in client-server mode

  • Execution planning and control is carried out by a scheduler from a server cluster;
  • If a request for execution appears, the scheduler looks for cluster worker processes with minimal load and distributes tasks to them for execution;
  • Each process can perform multiple parallel computations;
  • After a task arrives, the process connects to the database and executes the algorithm in it;
  • The process reports the results to the scheduler.

Background jobs in file mode

Before platform version 8.3.3.641, working with background jobs in the file version presented some difficulties:

  1. It was necessary to launch a separate session that would work around the clock, replacing the scheduler;
  2. This session should have periodically executed the RunJobProcessing() method.

After the update, each start of the thick and thin clients, if the AllowExecuteScheduledJobs key is specified in the launch settings (Fig. 4) in the “Additional” field, initiates an additional thread connecting to the database, which does not affect the user’s work in any way, but only performs background tasks. operations.

Fig.4

It should be taken into account that even in the file version of work, background processes do not allow interactive work with the user (service messages, warnings, and questions will not be displayed). That is, they must be coded as if they would be executed on the server side.

How to disable scheduled tasks

Unused tasks can be disabled by simply unchecking the “Use” checkbox in the object properties.

In the case when the administrator needs to prohibit the use of routine and background operations for the entire database as a whole (for example, several databases are stored on the server, of which only one is the main one, and the rest are used only for development), it is necessary to use the database administration utility. You can also check the “Set blocking of routine tasks” checkbox in the database created on the server.

In addition, the ITS disks have a special processing “Task Console”, which allows you to edit the schedule of background processes and change their activity.

Users often complain that “1C 8.3 is slow”: document forms open slowly, documents take a long time to process, the program starts, reports take a long time to generate, and so on.

Moreover, such “glitches” can occur in different programs:

The reasons may be different. This is not restored documents, a weak computer or server, the 1C server is incorrectly configured.

In this article I want to look at one of the simplest and most common reasons for a slow program - . This instruction will be relevant for users of file databases for 1-2 users, where there is no competition for resources.

If you are interested in more serious optimization of client-server options for system operation, visit the section of the site.

Where are the scheduled tasks in 1C 8.3?

Before I had time to load the program, many background tasks were completed in 1C. You can view them by going to the “Administration” menu, then “Support and Maintenance”:

Get 267 video lessons on 1C for free:

This is what the window with completed tasks looks like:

And here is a complete list of all scheduled tasks that are launched:

Among these tasks you can see such as ““, loading various classifiers, checking the relevance of the program version, and so on. For example, I have no use for almost all of these tasks. I don’t keep currency records, I control the versions myself, and load classifiers as needed.

Accordingly, it is in my (and in most cases in your) interests to disable unnecessary tasks.

Disabling routine and background tasks in 1C 8.3

Probably, not a single serious configuration on 1C 8.3 or 8.2 can do without the use of routine and background tasks. They are very convenient, since they will be executed according to a clearly defined schedule without user or programmer intervention.

For example, you need to exchange data with another program once a day. Using routine and background tasks, 1C will be able to perform these actions independently, for example, during non-working hours. This method will not affect the user experience in any way and will help save time.

First, let's figure out what they mean and what is their difference:

  • Scheduled task allows you to launch any specific actions according to a pre-configured schedule.
  • Background job is an object that contains the actions to be performed.

Let's assume that our company sells something and has its own website on which prices are located. We want to upload them once a day to maintain relevance.

Open the configuration and add a scheduled task.

Setting properties

Let's look at the most important parameters that need to be filled in its properties.

  • In field " Method name» selects the procedure of a specific general module that will be directly executed. It will indicate all the steps for uploading prices to our website. Please note that execution will take place on the server. This is logical, because routine operations are performed without user participation.
  • The scheduled task can be disabled or enabled as needed. There is no need to edit his schedule every time. To do this, in the properties palette, set or clear the flag " Usage».
  • Another important thing is to set whether this routine task will be predetermined, or not. Predefined scheduled tasks are launched automatically. If this feature is not installed, then you will need to launch them programmatically, or use the “Task Console” processing with ITS.
  • You can also specify number of repetitions and interval between them in case of abnormal termination. Abnormal termination refers to those situations when jobs were not completed due to an error.

Setting up a schedule

The final step is to set up a schedule for our upload to the site using the corresponding hyperlink in the properties palette.

You will see a typical schedule setting in 1C 8.3. There is nothing complicated here. In this example, we set up the launch of our uploading of prices to the site every day from five to seven in the morning. In the event that the scheduled task does not have time to be completed before 7:00, it will be completed the very next day.

Blocking scheduled tasks

Run the standard utility “Administering 1C Enterprise Servers” and open the properties of the infobase where you created the routine task (for client-server versions of 1C).

In the window that opens (after entering your login and password to access the information security), check that the checkbox “Blocking of routine tasks is enabled” is not selected. If you encounter a situation where the task does not work, check this setting first.

In the same way, you can completely disable routine tasks in 1C 8.3. To disable specific background jobs, you can use the “Background Job Console” processing built into the latest releases.

Background and scheduled tasks in file mode

In this mode, setting up and launching these tasks is much more difficult to organize. Most often, an additional account is created, the session of which will always be open.

In this case, routine tasks are activated using the “RunTaskProcessing()” method.

You can also use the following construction:

As the procedure name, you must specify the name of the client procedure that will be executed. The interval shows how many seconds later the execution will take place. The “One time” parameter is not required. It reflects whether this procedure will be performed once or several times.

Tracking errors in background jobs

You can view the progress of background jobs, as well as the presence of possible errors, in the log. In the filter, set the selection to the “Background job” application and, if necessary, select the importance of interest, for example, only “Errors”.

The log will show all entries that match your selection, along with a comment that will help you understand the reason for the error.