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

Probably, no serious configuration on 1C 8.3 or 8.2 can do without the use of scheduled and background jobs. They are very convenient, as 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 scheduled and background tasks, 1C will be able to perform these actions on its own, for example, outside of 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:

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

Suppose our firm sells something and has its own website with prices. We want to unload them once a day to maintain their relevance.

Open the configuration and add a scheduled job.

Setting properties

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

  • In field " Method name»The procedure of a certain general module is selected, which will be directly executed. It will indicate all actions to upload prices to our site. Note that the execution will take place on the server. This is logical, because routine operations are performed without user intervention.
  • The scheduled job can be disabled or enabled as needed. You don't need to change his schedule every time. To do this, set or uncheck the " Using».
  • Another important setting is whether this scheduled task will be predetermined, or not. The predefined scheduled jobs start automatically. If this sign is not set, then you will need to run them programmatically, or use the processing "Console of tasks" from the ITS.
  • You can also specify the number of repetitions and the interval between them on abnormal termination. Abnormal termination refers to those situations when tasks did not work due to an error.

Schedule setup

In the final step, we will set up the 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 difficult here. As part of this example, we set up the launch of our unloading of prices for the site every day from five to seven in the morning. In the event that the scheduled task does not have time to complete before 7:00, it will be completed the next day.

Blocking scheduled jobs

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 access to the IB), check that the flag on the item "Blocking of scheduled tasks is enabled" is not set. If you are faced with a situation where the task does not work out, 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 Job Console" processing built into the latest releases.

Background and scheduled tasks in file mode

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

In this case, scheduled jobs are activated using the "RunJobProcessing ()" method.

You can also use the following construction:

As the name of the procedure, you must specify 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 this procedure will be performed once or several times.

Tracking errors in background jobs

You can view the progress of background tasks, as well as the presence of possible errors in the log. In the filter, set the filter 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, with a comment indicating the reason for the error.

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

2012-11-13
53852

There are tasks in the workflow that require periodic execution - for example, on the twentieth, or daily. As a rule, in companies specifically for this, certain rules are created in which it is indicated when and how the necessary task should be performed, and who should control the process. Such tasks are performed in accordance with the regulations and are called - regulated.

Quite often, in IT, monitoring regulations are followed. This method is very familiar to administrators, since for this there are special programs that are used to periodically check the health of the network infrastructure and servers. They notify the administrator of the detected problems using SMS or e-mail.

A similar system works for webmasters, while the availability of the site is checked during the day. With the help of the "Scheduled 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 "Scheduled Tasks" - makes it possible to process information not after a problem, but on a schedule. In the configurator, a scheduled job is a way to configure settings and set a schedule. In addition, it is possible to subsequently change the schedule in 1C Enterprise mode.

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

All typical configurations have a user setting that allows you to clarify that when 1C is running, scheduled 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 - the background task is launched, which performs the necessary actions. For parallel computing on the server, a background job can be created from the program text using the 1C language, without using the 1C scheduled job. The action of a scheduled task can be temporarily disabled using the 1C server management console.

Adding a scheduled job

Scheduled tasks are located in - Configurator - General - Scheduled tasks. Add a new "job" and provide a name. Next, you need to go to the "Tasks" properties. And select 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 indicated by the Server checkbox in the properties. This means that the required module must be added in advance.

The name of the job in the Properties of a scheduled job allows you to define its name, which will then appear in the job 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 a time. Here, the value can be arbitrary, but it is mandatory to fill it, since the empty value is not taken into account by the system.

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

Retry on abnormal termination - Restart an active job. Provided for launching that was not successful the first time. Here, it is indicated how many times you can restart and how long after an abnormal termination.

Monitoring and management tools for scheduled task 1C

For the management of the scheduled job, the typical processing "Job Console", which can be found on the ITS disks, is responsible. This treatment is a universal external typical treatment of 1C. As a rule, it is not included in the configuration, but is purchased separately.

With its help, you can perform the following actions:

Enable and disable scheduled task;

Assign and change the schedule;

Designate 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;

Schedule job and database copies

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

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

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

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

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

Completed and not completed routine tasks

When creating scheduled tasks, it is important to check whether the task can be performed as a scheduled task. It is important to know that the server module does not provide many things that are possible on the client. Further, a task that deals with something that is outside the base - an important role in this is played by the rights of the Windows user under which the task is being performed.

The last factor is especially important, since if the module is not executed on the server, then the task cannot be completed 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 this or that action, for example: holding documents or downloading data to 1C from the site.

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

Scheduled and background jobs

The job engine is designed to execute some application or functionality on a schedule or asynchronously.

The task mechanism solves the following tasks:

  • Ability to define routine procedures at the stage of system configuration;
  • Execution of specified actions on a schedule;
  • 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 task and getting its completion status (a value indicating the success or failure of its completion);
  • Getting a list of current tasks;
  • The ability to wait for the completion of one or more tasks;
  • Job management (the ability to cancel, block execution, etc.).

The job engine consists of the following components:

  • Metadata of scheduled tasks;
  • Routine tasks;
  • Background jobs;
  • Task Scheduler.

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

Scheduled tasks & are designed to perform application tasks on a schedule. 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, use, etc.

A scheduled job has a schedule that defines at what time points the method associated with the scheduled job should be executed. The schedule, as a rule, is specified in the infobase, but it can also be specified 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 task, the scheduler periodically checks if the current date and time is on the schedule of the scheduled task. If so, the scheduler assigns such a task to be executed. To do this, for this scheduled task, the scheduler creates a background task that performs the real processing.

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

Creating a scheduled job

Method name - the path to the procedure that will be executed in the background job according to the specified schedule. The procedure should be in a common 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!

Using - sign of using 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 invoke the task launch programmatically.

Number of retries in case of abnormal completion of the task - how many times the background job was restarted if it was completed with an error.

Retry interval for abnormal job termination - how often the background job will be restarted if it was executed with an error.

Schedule setup

timetable completing the task:

Every hour, just one dayRepeatDays Period \u003d 0, RepeatPeriodDuring a Day \u003d 3600
Every day, once a dayRepeatPeriodDays \u003d 1, RepeatPeriodOverDay \u003d 0
One day, one timeRepeatDays Period \u003d 0
Every other day, once a dayRepeat PeriodDays \u003d 2
Every hour from 01.00 to 07.00 every dayDayRepeat Period \u003d 1RepeatPeriodDuring the Day \u003d 3600Start Time \u003d 01.00

End Time \u003d 07.00

Every Saturday and Sunday at 09.00RepeatDays Period \u003d 1DaysWeeks \u003d 6, 7Start Time \u003d 09.00
Every day one week, week passRecurrence PeriodDays \u003d 1PeriodWeeks \u003d 2
At 01.00 one timeStart Time \u003d 01.00
Last day of each month at 9:00.RepeatDays Period \u003d 1DayInMonth \u003d -1Start Time \u003d 09.00
Fifth of every month at 9:00RepeatDays Period \u003d 1DayInMonth \u003d 5Start Time \u003d 09.00
Second Wednesday of every month at 9:00Repeat PeriodDays \u003d 1DayWeekInMonth \u003d 2DaysWeeks \u003d 3

Start Time \u003d 09.00

Specifics of executing background jobs in file and client-server versions

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 handle background jobs. To do this, the client process must periodically call the RunProcessingJobs global context function. 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 the error "Job manager is not active" will be displayed when programmatically accessing the job engine. It is not recommended to use the client process that is processing background jobs for other functions.

After the client process performing background job processing has started, other client processes can programmatically access the background job engine, i.e. can run and manage background jobs.

In client-server version to execute background tasks, the task scheduler is used, which is physically located in the cluster manager. The scheduler for all queued background jobs gets the least busy workflow and uses it to execute the corresponding background job. The workflow runs the job and notifies the scheduler of the results of the execution.

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 jobs is installed on the infobase. The lock can be set through the cluster console;
  • A connection blocking is installed on the infobase. The lock can be set through the cluster console;
  • The SetExclusiveMode () method was called from the embedded language with the True parameter;
  • In some other cases (for example, when updating the database configuration).

Processing of launching and viewing scheduled jobs you can download here.

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

You will find detailed instructions on an example below.

What are scheduled and background tasks in 1C

  • Scheduled tasks Is a special 1C Enterprise 8.3 mechanism designed to perform a specific action on a given schedule.
  • Background job - objects generated by a scheduled task that directly performs the assigned action without the participation of the user or programmer 1C 8.2.

The mechanism of scheduled and background jobs operates in a 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 jobs in the 1C client-server mode

First, let's create a new metadata object - a scheduled task. I'll call my task "Currency Currency Loading". Consider the palette of properties of this configuration object:

Get 267 1C video tutorials for free:

  • Method name - the path to the procedure that will be executed in the background job according to the specified schedule. The procedure should be in a common module. It is recommended not to use standard ones, but to create your own. Don't forget that background jobs run on the server!
  • Using - sign of using a scheduled task.
  • Predetermined - indicates whether the scheduled job is predefined. If you want the scheduled task to start working immediately after being placed in the database, indicate this sign. Otherwise, you will need to use Job Console processing or invoke the job launch programmatically.
  • Number of retries in case of abnormal completion of the task - how many times the background job was restarted if it was completed with an error.
  • Retry interval for abnormal job termination - how often the background job will be restarted if it was executed with an error.

And the most interesting setting is Timetable:

Here the interval for starting the procedure specified in the "Method name" field is configured. Let's say I configured

Attention!Do not forget to disable blocking of scheduled and background jobs execution at the DBMS level!

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

Setting up scheduled tasks in the 1C file mode

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

In the file mode, the scheduled job is initialized when the RunJobProcessing () method is started.

For a specific user, you can 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 of a managed application module (regular application module) or a global shared module. The procedure must be located on the client.
  • Interval - the 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: