Scheduled and background tasks (creation, configuration, launch). Scheduled and background tasks (creation, configuration, launch) Scheduled tasks console 1s 8.3

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 downloading data to 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 designed to run application 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 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.

In file format 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 can 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 via the cluster console;
  • A connection block has been set on the infobase. The lock can be set via 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, 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 time. 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. As part of this example we set up the launch of our uploading 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 1C Enterprise Server Administration utility and open the properties of the infobase where you created the scheduled task (for 1C client-server versions).

In the window that opens (after entering the login and password for accessing IB), check that the flag on the item "Blocking scheduled tasks is enabled" is not set. 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 "PerformJobProcessing()".

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 this procedure 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 registration log. 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.

Some tasks in document management and accounting may need to be performed periodically. For example, on the twentieth numbers. Or daily.

Usually, the company tries to create rules about the implementation of such tasks - who, when and how should perform the task, who should control it.

Such tasks are called - regulated, that is, performed according to the regulations.

In IT, monitoring is often routine.

This is well known to the system administrator - there are special programs that periodically check the health of servers and network infrastructure and report SMS or email to the administrator.

Similar things exist for webmasters - to check the availability of the site during the day.

In 1C, monitoring tasks and any other periodic tasks that should be performed automatically on a schedule are performed using the 1C Scheduled Tasks mechanism.

Let's talk about them today.

Scheduled tasks 1C

Scheduled tasks 1C is one that allows you to perform as it does, but on schedule.

The 1C routine task itself in the configurator is a way to specify settings and set a schedule. By the way, the schedule can be changed dynamically later in the 1C Enterprise mode.

Background tasks can be created from the program text in the 1C language arbitrarily without a scheduled task 1C - for parallel computing on the server.

The execution of routine tasks 1C can be temporarily disabled - in.

Adding a scheduled task 1C

Scheduled tasks 1C are in the configuration in the General / Scheduled tasks 1C branch. Let's add a new scheduled task 1C, specify its name.

In the property of the scheduled task 1C, the name of the method is indicated, as well as in. The function will be located in a common module with the Server checkbox checked in the properties, that is, the module must be added beforehand.

The property of the scheduled task 1C - Task name - determines the name under which the task will appear in the task management tools.

The property of the scheduled task 1C - Key - allows you to group several different scheduled tasks 1C. Only one task with the same key value can be run at the same time. The value itself can be arbitrary. An empty value is not taken into account during control (that is, it is considered not filled).

The property of the scheduled task 1C - Predefined - determines that when starting 1C Enterprise, such a task will be created and in a single copy with the schedule specified in the configurator. Non-predefined tasks appear programmatically when the schedule arrives.

In typical configurations, for example, Accounting 2.0, such routine 1C tasks as Configuration Update and Recalculation of Totals are predefined, and such as Data Exchange or Deferred Movements are not predefined.

Usage - includes the task (that is, it will be executed only if the Usage checkbox is checked).

Crash retry - as you can easily guess, means restarting the job if it could not be completed successfully the first time - it is indicated how many times to restart and after how many after the crash.

1C scheduled task management and monitoring

To manage scheduled tasks 1C, there is a special typical processing of the Task Console. It can also be found on .

This processing refers to the so-called universal external typical 1C processing, which is often not included in the configuration, but distributed separately, for example, on ITS disks.

With Job Console Processing, you can:

  • Enable / disable the execution of the scheduled task 1C
  • Assign / change the schedule of the scheduled task 1C (and other parameters)
  • Specify the 1C user on whose behalf the scheduled task 1C will be performed
  • View - what tasks were completed when and with what result, errors in completing 1C tasks
  • Perform a task.

Copies of databases and routine tasks 1C

If server 1C is used, then the following situation occurs:

  • For their own purposes (for example, for programming), a copy of the working database is made
  • In a copy of the database, it is being worked, tested, and so on.
  • It is forgotten to turn off routine 1C tasks in such a test base.

While routine 1C tasks perform tasks related only to their infobase, then there is nothing in this.

However, often 1C routine tasks can save any files data to other databases, exchange, send emails.

In this case, an interesting mixture may turn out between the result of performing routine 1C tasks in the working database and copies.

1C routine tasks for in copies of the working base must be disabled in.

Fulfillment and non-fulfillment of routine tasks 1C

When creating scheduled tasks 1C, you need to remember:

  • Tasks run by themselves - they need to be monitored
  • Tasks run in a module on the server
  • Tasks are executed under a different Windows user, under different rights.

First, you need to check that the task is running and can be performed as a scheduled 1C task.

Secondly, the server module means that many things that are available on the client are not available. For example, sometimes, not all documents can be posted only on the server, since their algorithm may provide that the posting is started manually by the user and non-server functions can be used, for example
Alert("Hi!")

Thirdly, if the task deals with something outside the 1C base, then the rights of the Windows user under which the task is performed become important.

The third point is especially important in the development. If the module cannot be executed on the server, the task will not be executed in principle. To check, you need to run the task at least once and see the result "Task completed" in the processing of the Task Console.

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 the 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 "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 are associated only with its database, then this does not entail negative consequences. But, often, a scheduled 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 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.