Scheduled and background tasks (creation, configuration, launch). Scheduled and background tasks (creation, configuration, launch) 1c 8.3 Scheduled task console managed forms

Probably, not a single serious configuration on 1C 8.3 or 8.2 can do without the use of scheduled and background tasks. They are very convenient, as they will be executed according to a clearly defined schedule without user and 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, in non-working hours. This method will not affect the work of users in any way and will save time.

First, let's figure out what they mean and how they differ:

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

Suppose that our company sells something and has its own website with prices. Once a day, we want to unload them to maintain relevance.

Open the configuration and add a scheduled task.

Setting properties

Consider the most important parameters that must be filled in its properties.

  • In field " Method name» the procedure of some specific general module is selected, which will be directly executed. It will indicate all the actions for uploading prices to our website. Note that the execution will take place on the server. This is logical, because routine operations are performed without user intervention.
  • Scheduled task can be disabled or enabled as needed. No need to change his schedule every time. To do this, in the properties palette, check or uncheck the " Usage».
  • Another important setting is whether this scheduled task will be predetermined, or not. Predefined scheduled jobs run automatically. If this flag is not set, then you will need to run them programmatically, or use the "Job Console" processing with ITS.
  • You can also specify the number of repetitions and the interval between them upon crash. Abnormal completion refers to those situations when tasks did not complete due to an error.

Schedule setting

The final step is to set up a schedule for our upload to the site using the appropriate 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 upload of prices to the site daily from five to seven in the morning. In the event that the scheduled task does not have time to work out before 7:00, it will be completed the next day.

Blocking scheduled tasks

Run the standard utility "Administration of 1C Enterprise Servers" and open the properties of the infobase where you created the scheduled task (for client-server versions of 1C).

In the window that opens (after entering the login and password for accessing the IB), check that the flag is not set on the “Lock routine tasks enabled." If you encounter a situation where the task does not work, check this setting first.

In the same way, you can completely disable scheduled tasks in 1C 8.3. To disable specific background jobs, you can use the "Background Jobs Console" processing built into recent releases.

Background and scheduled jobs in file mode

In this mode, setting up and running these jobs is much more difficult to organize. Most often, an additional Account, whose session will always be open.

Activation of scheduled tasks in this case is performed using the method "PerformProcessingTasks()".

You can also use the following construct:

The procedure name must be the name of the client procedure to be executed. The interval shows how many seconds the execution will take. The "Once" parameter is optional. It reflects whether the given procedure will be performed once or several times.

Tracking errors in background jobs

View the progress of background jobs, as well as the availability possible errors can be in the register. In the filter, set the selection to the "Background task" application and, if necessary, select the importance of interest, for example, only "Errors".

The log will show all entries that match your selection with a comment that you can use to understand the cause of the error.

Platforms: 1C:Enterprise 8.3, 1C:Enterprise 8.2, 1C:Enterprise 8.1
Configurations: All configurations

2012-11-13
53852

In the workflow, there are tasks that require periodic execution - for example, on the twentieth, or daily. As a rule, in companies specifically for this, certain rules are created that indicate when and how the necessary task should be performed, and who should control the process. Such tasks are performed according to the regulations and are called regulated.

Quite often, IT follows the rules for monitoring. This method is well known to administrators, since for this there are special programs used to periodically check the health of the network infrastructure and servers. They notify the administrator about detected problems via SMS or e-mail.

A similar system is valid for webmasters, while the availability of the site is checked within 24 hours. With the help of the "Regular tasks" mechanism in 1C, monitoring tasks are carried out, as well as periodic tasks that are performed according to a schedule in automatic mode in 1C. Let's consider this topic in more detail.

Scheduled tasks 1C

Object 1C, which is called "Regular tasks" - makes it possible to process information not after a problem occurs, but according to a schedule. In the configurator, a scheduled job is a way to set up settings and set a schedule. In addition, it is possible to subsequently change the schedule in the 1C Enterprise mode.

When using a file database, jobs are not automatically executed. In order to start the process, you need to start a 1C session in 1C Enterprise mode and start the execution of a scheduled task in it.

All typical configurations have a user setting that allows you to clarify that when 1C is running, routine tasks will be performed automatically.

Using the client-server version of 1C makes it possible to automatically perform tasks on the server. At the scheduled time - a background task is launched, which performs necessary actions. For parallel computing on the server, a background task can be created from the program text using the 1C language, without using a scheduled 1C task. The action of a scheduled task can be temporarily disabled using the 1C server management console for this.

Adding a Scheduled Job

Scheduled tasks are located in — Configurator — General — Scheduled tasks. Add a new "task" and provide a name. Next, you need to go to the properties of the "Tasks". And choose Method name. Here, you need to specify the handler function, just as it happens in the event subscription. This function will be located in the general module and marked with a "bird" Server in the properties. This means that the required module must be added in advance.

The name of the task in the Properties of the scheduled task allows you to define its name, which will later appear in the task management tools. The Scheduled job properties function is a key that allows you to group several different scheduled jobs. In this case, only one task with the same key value can be launched at the same time. Here, the value can be arbitrary, but it is mandatory to fill it in, since the empty value is not taken into account by the system.

In Accounting 2.0 edition, which is a typical configuration, scheduled tasks such as: "Recalculation of totals" and "Configuration update" are predefined, and such as, for example, "Delayed movements" and "Data exchange" are not predefined.

Crash Retry - Restarts a running job. Provided for a launch that was not successfully completed the first time. Here, it is indicated how many times you can restart and how long after the crash.

Monitoring and management tools for the scheduled task 1C

The standard processing "Job Console", which can be found on the ITS disks, is responsible for managing the scheduled task. This processing is a universal external standard processing 1C. As a rule, it is not included in the configuration, but is purchased separately.

With its help, you can perform the following actions:

Turn on and off the scheduled task;

Assign and change the schedule;

Indicate the name of the user with which the scheduled task will be performed;

See completed tasks (when and with what result), as well as task errors;

Scheduled task and database copies

When using server 1C, the following moment may arise:

For programming, you need to make a copy of the working database;

The need to work in copies of the database (testing);

For some reason, the scheduled task is not enabled in the test database.

If one of these situations arose during the execution of tasks by a scheduled task that is associated only with its own database, then this does not entail negative consequences. But, often, a scheduled task can save files or other data, send emails to exchange. In this case, there may be confusion between the results of the "job" and copies. To prevent this from happening, you need to disable "tasks" in the server management console.

Completed and not completed routine tasks

When creating scheduled tasks, it is important to check if the task can be executed as a scheduled task. It's important to know that the server module doesn't provide many of the things that are possible on the client. Next, a task dealing with something that is outside the base − important role at the same time, the rights of the Windows user under which the task is being executed play.

The last factor is especially important, since if the module is not executed on the server, then the task cannot be executed in principle. To check, you need to run one task and evaluate the result.

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

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

Scheduled and background jobs

The job mechanism is designed to execute any application or functionality on a schedule or asynchronously.

The job mechanism performs the following tasks:

  • Ability to determine routine procedures at the stage of system configuration;
  • Execution of specified actions according to the schedule;
  • The execution of a call to a given procedure or function is asynchronous, i.e. without waiting for its completion;
  • Tracking the progress of a specific job and getting its completion status (a value indicating the success or failure of its execution);
  • Getting a list of current tasks;
  • Ability to wait for the completion of one or more tasks;
  • Job management (possibility of cancellation, blocking of execution, etc.).

The job engine consists of the following components:

  • Metadata of scheduled tasks;
  • Scheduled assignments;
  • Background jobs;
  • Task Scheduler.

Background jobs & are meant to be executed applied tasks asynchronously. Background jobs are implemented using the built-in language.

Scheduled tasks & are designed to perform scheduled tasks. Scheduled tasks are stored in the infobase and are created based on the metadata defined in the configuration. Scheduled job metadata contains information such as name, method, usage, and so on.

A scheduled job has a schedule that determines at what times the method associated with the scheduled job should be executed. The schedule, as a rule, is set in the infobase, but it can also be set at the configuration stage (for example, for predefined scheduled tasks).

The task scheduler is used to schedule the execution of scheduled 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 schedules that job to run. To do this, according to this scheduled task, the scheduler creates a background task that performs the actual processing.

With the description, I think that's enough - let's proceed to the implementation:

Creating a Scheduled Job

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

Usage- a sign of the use of a scheduled task.

predetermined– indicates whether the scheduled job is predefined.

If you want the scheduled task to work immediately after being placed in the database, specify the sign predetermined. Otherwise, you will need to use the “Job Console” processing or call the job to run programmatically.

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

Job abort retry interval– how often the background task will be restarted if it was executed with an error.

Schedule setting

Schedule task execution:

Every hour, just one dayRetry PeriodDays = 0, Retry PeriodDuringDay = 3600
Every day once a dayRetry PeriodDays = 1, Retry PeriodDuringDay = 0
One day, one timeRetry Period Days = 0
Every other day once a dayRetry Period Days = 2
Every hour from 01.00 to 07.00 every dayRetryPeriodDays = 1RepeatPeriodDay = 3600StartTime = 01.00

End Time = 07.00

Every Saturday and Sunday at 09.00Repeat Period of Days = 1Days of the Week = 6, 7StartTime = 09.00
Every day one week, week passRepeat Period of Days = 1 Period of Weeks = 2
At 01.00 one timeStartTime = 01.00
Last day of each month at 9:00.Repeat Period of Days = 1DayInMonth = -1StartTime = 09.00
Fifth of every month at 9:00Repeat Period of Days = 1DayInMonth = 5StartTime = 09.00
Second Wednesday of every month at 9:00 amRepeat PeriodDays = 1DayWeekInMonth = 2DaysWeek = 3

Start Time = 09.00

Peculiarities of performing background tasks in file and client-server versions

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

AT file version you need to create a dedicated client process that will perform background tasks. To do this, the global context function ExecuteJobProcessing must be called periodically in the client process. Only one client process per infobase should process background jobs (and therefore call this function). If no client process has been created to process background jobs, then when programmatically accessing the job engine, the error "Job manager is not active" will be generated. It is not recommended to use the client process that processes background jobs for other functions.

After the client process processing background jobs is started, other client processes get the opportunity to programmatically access the background job mechanism, i.e. can run and manage background jobs.

In client-server version To execute background jobs, the task scheduler is used, which is physically located in the cluster manager. The scheduler for all queued background jobs 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 scheduled tasks. Blocking the execution of scheduled tasks occurs in the following cases:

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

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

Probably, every 1C 8.3 programmer sooner or later had to set up the execution of certain tasks on a schedule. Below I will give detailed description of these mechanisms, I hope this will be useful information for novice 1C programmers. This is very convenient, because it does not require human actions, the scheduled task is configured once and works according to your schedule.

Detailed instructions with an example can be found below.

What are scheduled and background tasks in 1C

  • Scheduled assignments- this is special mechanism 1C enterprise 8.3, designed to perform certain action according to the given schedule.
  • Background job- objects generated by a scheduled task that directly performs the inherent action without the participation of the user or programmer 1C 8.2.

The mechanism of scheduled and background jobs works in the client-server mode of operation (SQL), thanks to the functionality of the DBMS. If you have a file database, then the task can also be configured, but in a slightly different way.

Setting up background tasks in the client-server mode of operation 1C

To begin with, let's create a new metadata object - a scheduled task. I will name my task "LoadingCurrency Rates". Consider the properties palette of this configuration object:

Get 267 1C video lessons for free:

  • Method name— path to the procedure that will be executed in the background task according to the specified schedule. The procedure must be in a shared module. It is recommended not to use standard ones, but to create your own. Don't forget that background jobs run on the server!
  • Usage- a sign of the use of a scheduled task.
  • predetermined Indicates whether the scheduled job is predefined. If you want the scheduled task to work immediately after being placed in the database, specify this flag. Otherwise, you will need to use the "Job Console" processing or call the job to run programmatically.
  • Number of retries when a job crashes— how many times the background job was restarted if it was executed with an error.
  • Job abort retry interval- how often the background task will be restarted if it was completed with an error.

And the most interesting setting - Schedule:

Here you can set the interval for starting the procedure specified in the "Method name" field. Let me set up

Attention! Don't forget to disable the blocking of scheduled and background jobs at the DBMS level!

This can be done in the administration utility of the client-server version or when creating a new database:

Setting up scheduled tasks in the file mode of operation 1C

In file mode, setting up such tasks is somewhat more difficult. For such a task, a separate session of the 1C program must be launched. Often this is solved by the institution of the "technical" user, whose session is always running.

In the file mode, the initialization of the scheduled job occurs when the "ExecuteJobProcessing()" method is launched.

For a specific user, it is possible to configure this method to run using another method −

ConnectWaitingHandler( <ИмяПроцедуры>, <Интервал>, <Однократно>).

  • Procedure name— the name of the procedure connected as a wait handler. The name of the exported procedure for a managed application module (regular application module) or global shared module. The procedure must be located on the client.
  • Interval— period between executions of operations in seconds.
  • once- how to complete the task, once or not.

ConnectWaitingHandler, 3600 ) ;

A two-minute video showing how to set up a scheduled task in the 1C configurator:

 

It might be useful to read: