Creating a routine task in 1s 8.3. Background tasks: features, capabilities, settings. Programmatic creation of a routine task
This article provides an example of working with background jobs, as in 1C background jobs are launched, how can you get a list of tasks using the method "GetBackgroundTasks()". So, this method returns us some array. Let's see what it contains.
Let me make a reservation right away that the example given was developed in the client-server version of the database.
The figure presented above shows the contents of this array.
Pay attention to the field "State". It contains information about whether the running background job has completed successfully or is still running.
It also contains information about the unsuccessful completion of the task. This array also contains information about keys, unique identifiers, and the name of background jobs. Information about running and completed tasks is stored in the infobase, but there is a limit on the number of records stored in the table. This number is about 1000 records. That is, when new elements are added, old ones are removed. Also, a task is deleted from the table if it was completed more than a day ago.
An example of working with a background job 1C - Method "GetBackgroundTasks"
Let's also look at working with background jobs using the method example "GetBackgroundTasks()". In this method, it is possible to set a selection for the received records. That is, we need to pass a structure as a method parameter.
The structure may contain fields: Unique identifier, Key, Status, Start, End, Name, MethodName, ScheduledTask.
For example, if we needed only running jobs, we would apply a selection with the name of the structure element “State” and the value, we would specify the system enumeration “BackgroundTask State” to the active state. So, first you need to ensure that records about the execution of 1C background jobs appear in the demo database.
To implement the example, we will do the following:
1. Let's create a common module "BackgroundTask Handlers" executing on the server.
And add the following code to it:
Procedure ProduceBackgroundCalculation(Parameter) ExportTimeStart = CurrentDate() ;
While CurrentDate() - Start Time Cycle
EndCycle ;
End of Procedure2. Let’s create a processing and place a button on the form "Run the task in the background" and in the procedure for processing the button click event, add the following code:
&On the Client Procedure ExecuteTask(Command) ExecuteBackgroundTaskOnServer() ; End of Procedure
Description of the called procedure:
&OnServer Procedure ExecuteBackgroundTaskOnServer()BackgroundTask Parameters = New Array; BackgroundTask Parameters. Add( "Some parameter" "Test task" ) ; BackgroundTaskParameters = New Array; BackgroundTask Parameters. Add( "Some parameter") ; BackgroundTasks. Run ( "BackgroundTask Handlers. Perform BackgroundCalculation", BackgroundTask Parameters, New UniqueIdentifier, "Test task 2") ; End of Procedure // Execute BackgroundTaskOnServer()
Now let's launch 1C in enterprise mode and start executing a background job.
Ready. By these actions, we ensured that records about the execution of 1C background jobs appeared in our demo database, and now we can demonstrate an example of obtaining their array contained in our database.
Let's add another button to the form "Get background jobs" . Let's write the following code in the click processing procedure:
&On the Client Procedure GetBackgroundJob(Command) GetBackgroundJobOnServer() ; End of Procedure
The text of the procedure on the server:
&OnServer Procedure GetBackgroundTasksOnServer() Selection Parameters = New Structure("Name" , "Test task 2") ; ListBackgroundTasks = BackgroundTasks. GetBackgroundTasks(SelectionOptions) ; For each Task From the List of BackgroundTasks Cycle Report(Task.Name) ; EndCycle ; End of Procedure // GetBackgroundTasksOnServer()
Let's launch 1C for execution and press the button "Get background jobs".
How to speed up work in 1C: Accounting 8.3 (edition 3.0) or disable routine and background tasks
2019-01-15T13:28:19+00:00Those of you who have already switched to the new edition of 1C: Accounting 8.3 (edition 3.0) have noticed that it has become slower than 2. Some strange slowdowns, endless background tasks several times a day, which no one asked her to perform without our knowledge.
My accountants told me immediately after the transition that the new edition of 1C: Accounting 3.0 is downright slow compared to the previous ones! And it’s simply impossible to work.
I started looking into it and very soon found out that the main reason for freezes and subsequent user dissatisfaction are routine and background tasks, many of which are enabled by default, although for the vast majority of accountants there is no need for them.
Well, for example, why do we need to run the “Text Extraction” task a hundred times a day if we do not carry out a full-text (accountants, don’t be alarmed) search across all objects in our database.
Or why constantly download currency rates if we do not have currency transactions or we do them occasionally (and before that we ourselves can click the download rates button).
The same applies to 1C’s constant attempt to connect to the site and check and update bank classifiers. For what? I myself will press the button to update classifiers if I don’t find it the desired bank according to his BIC.
How to do this step by step below.
1. Go to the "Administration" section and select "Maintenance" () in the action panel:
2. In the window that opens, find and select “Routine and background tasks”:
3. Open each task that has "On" in the "On" column. there is a daw.
4. Uncheck "Enabled" and click the "Save and Close" button.
5. Do this with each of the included tasks and enjoy the new edition. Overall, in my opinion, it is much better than two.
At the same time, the platform will still enable some of the scheduled tasks you disabled.
Asynchronous programming concept
The asynchronous programming concept is that the result of a function is not immediately available, but after some time in the form of some asynchronous (violating the normal order of execution) call.
Those. The main idea of asynchronous programming is to issue individual method calls and continue doing other work in parallel without waiting for the calls to finish.
Some methods that minimize the likelihood of exceptions do not require an asynchronous approach, but others require it at the very beginning of development.
As can be seen from the graphs, there is no coefficient of useful interactive user actions with a synchronous programming model, since the system blocks user interface, while with the asynchronous model, the user continues to actively work in the system.
When running synchronously, the application has only one thread. With the asynchronous programming model, you can run multiple threads in parallel and react to new user actions as they run. Once the n-thread is executed, you display the result on the screen.
Background tasks in 1C:Enterprise 8
In 1C:Enterprise 8, background jobs are designed to perform application tasks asynchronously. They can generate child background jobs, for example, to parallelize complex calculations across different working servers of the cluster in a client-server mode of operation.
It is possible to limit the execution of background jobs that have the same methods based on a specific application criterion. Programmatic creation and management of background jobs is possible from any user connection to the system information base. The background job runs on behalf of the user who created it.
The task mechanism functions in both the client-server and file modes of operation, but the capabilities for administering and executing tasks in both versions are somewhat different.
Client-server option
In the client-server version, task scheduling is carried out by the task scheduler, which is physically located in the cluster manager.
The scheduler periodically checks to see if any requests have been received to run background jobs. If there are jobs that need to be executed, the scheduler determines the least loaded worker processes in the cluster and sequentially assigns each of them its own job to execute. Thus, the same worker process can potentially execute multiple jobs in parallel. After a job is received by a worker process, the worker process establishes a connection to the infobase and executes the job within that connection. After the job completes, the worker process notifies the scheduler whether the job completed successfully or unsuccessfully.
File option
Starting with version 8.3.3.641 of the platform, the developers have significantly simplified the work with background jobs in the file version.
Previously for automatic execution tasks required launching a separate, additional 1C:Enterprise session, used as a task scheduler. And in this session it was necessary to periodically execute the built-in language method ExecuteTaskProcessing(). This approach was quite cumbersome, inconvenient and greatly limited the use of background and routine tasks in the file version of work.
Now everything has become much easier. If a thin or thick client starts, and also if the web server has client connections, then in each of these applications another thread is automatically launched with a connection to the database. These threads are engaged in performing background and routine tasks.
Each of the listed applications runs its own background tasks. If an application has initiated several background jobs, they are executed sequentially, in the order they were received.
The obvious disadvantage of 1C background jobs: since they are executed on the server side, there is no possibility of interacting with the user (for example, you cannot display a message or any other information; all this data must be stored within information base and then process it in some way).
It should be noted that background jobs are purely software objects and cannot be stored in the database. That is, we can only create an instance of the class, initialize its properties and launch it for execution.
Example asynchronous execution code in "1C:Enterprise 8"
“Writing programs in which the result of a function call arrives unknown when is much more difficult than ordinary ones. Nested calls, error handling, control over what is happening - everything becomes more complicated,” only those who do not know how to properly use the platform’s capabilities will say this, but not us!
Let's demonstrate all the simplicity and elegance of asynchronous code execution in 1C:Enterprise 8!
Step 1. Let's create a new information security system for configuration development
Step 2. In the configuration we will add the general module “Asynchronous Handlers”
Why did we add a shared module? Everything is simple here: to perform asynchronous operations in 1C:Enterprise 8, background jobs are used, which have their own manager - “BackgroundTask Manager”. This object has a “Run” method, with the help of which the background task is launched.
Let's turn to the syntax assistant.
So we will need a common module.
Step 3. In the general module “Asyncronous Handlers” we will add the export procedure OurLongOperation()
Procedure OurLongOperation(Duration) Export // Simulation of a long-term action (Duration sec.). OperationStartDate = CurrentDate(); While CurrentDate() - Operation Start Date< Длительность Цикл КонецЦикла; КонецПроцедуры
Step 4. Add “Asynchronous Programming Concept” processing to the configuration (you can create external processing)
Add one attribute to the form:
Duration (Number)
and two teams
Perform LongOperation;
Perform a Long-Long Operation Asynchronously.
Step 5. According to the syntax assistant, fill out the form module
&On the Client Procedure Perform Long-RunningOperation(Command) ExecuteLong-RunningOperationOnServer(); EndProcedure &OnServer Procedure ExecuteLongOperationOnServer() AsynchronousHandlers.OurLongOperation(Duration); End of Procedure &On the Client Procedure Perform Long-running Operation Asynchronously (Command) Perform Long-running Operation Asynchronously on Server (); End of Procedure &On the Server Procedure Perform Long-running Operation Asynchronously On the Server() Parameters = New Array; Parameters.Add(Duration); BackgroundTasks.Execute("AsynchronousHandlers.OurLongOperation", Parameters, New UniqueIdentifier, "Example of asynchronous programming concept"); End of Procedure
Step 6. Let's launch and check!
Result:
If we click on the "Run" button long surgery", then the user interface is blocked for "Duration" seconds;
If we click on the button “Perform long-running operation asynchronously”, then the user interface is not blocked, but program code runs in parallel.
We can verify that the program code is executed asynchronously by looking at the log.
We can debug program code that runs in the “background” if we set the appropriate property in the debugging parameters.
An example of asynchronous code execution in 1C:Enterprise 8 using BSP
Let's consider an example of the implementation of the asynchronous programming concept in 1C:Enterprise 8 in the BSP using the example of processing “Current Affairs”.
The logic is as follows: when the program starts, the workspace is initialized home page, where you can display the “Current Affairs” processing form. This form is filled out by the user's current affairs, and it takes time to fill it out. If developers did not have the ability to execute code asynchronously, then the user interface would be blocked while the processing form was being filled out!
Let's analyze the program code of the form.
The form event “When CreatedOnServer” calls the “RunBackgroundTask” procedure - this is what we need.
Without being distracted by the nuances, let’s analyze this procedure
And here we see that the background job manager and its “Run” method are used. Note that developers store a unique ID for the background job.
To do this, developers use the method ConnectWaitHandler(<ИмяПроцедуры>, <Интервал>, <Однократно>).
In a connected procedure Connectable_CheckTaskComplete() developers call the function JobCompleted(TaskID)
This function checks the execution of a background job by identifier.
It should be noted that the BSP has developed general modules to support long-term server operations.
Thus, the asynchronous programming concept in 1C:Enterprise 8 slightly increases the complexity of solving problems for the developer, but significantly improves the functionality of the program from the user’s point of view.
The question we put in the title of the article is relevant for many system administrators working with this product. As far as possible, we try to talk about the parameters that affect 1C performance and debunk popular myths. Today, using the example of one recent case, we want to tell you about another aspect that can seriously affect productivity - routine tasks.
Let's start with a real case. Not long ago, one of our clients contacted us with a complaint about the 1C “brakes” of one of his employees. The symptoms were that after a certain period of time the Trade Management 10 configuration began to slow down greatly, or, more simply, froze for some time.
With more detailed analysis situation, it turned out that this only happens to one employee, and at any workplace, it has been happening for a long time, but if earlier the “brakes” lasted about a second, now, after the update, they can last up to 15-20 seconds, which makes the work extremely uncomfortable .
In principle, the initial data is already sufficient to draw the first conclusions. Let's list them again:
- “Brakes” occur constantly, with a certain frequency
- Only slows down for one user
- "Slows down" at any workplace
To confirm our guesses, let's look at Accounting Settings:
Indeed, the “problem” user is listed as a user for performing routine tasks. As it turned out, once upon a time a RIB auto-exchange task was running on behalf of this user. It remains to be seen what exactly was the cause of the episodic “braking”. This is also easy to do:
And here is the “hero of the occasion” - the task of updating the full-text search index, which was launched once every 2.5 minutes. In this case, the problem was completely solved by disabling the execution of routine tasks under this user, however, this is not always possible or advisable, so below we will look at how you can manage routine tasks and how to make sure that they do not affect negative influence for performance.
Regular application
In configurations based on regular application There is no single toolkit for managing routine tasks. This is largely due to the fact that at the time of their initial development the concept of routine tasks itself was rather poorly developed.
Many routine tasks are managed through setting up the subsystems associated with them. For example, the settings for regulatory tasks related to data exchange should be looked for in the exchange settings associated with the Unified State Automated Information System in the alcohol trading settings, etc.
At first glance, everything is quite logical, but the lack of a single tool makes it difficult to control the configured routine tasks and the optimality of their settings. It’s good if there are one or two tasks, but if there are more of them or, as in our case, there is a suspicion of one of the scheduled tasks, but you have no idea who configured what in this database.
In this case, you should use external processing ConsoleTasks (JobsConsole), which is included in the set of standard processing on the ITS disk. Processing provides a single interface for all tasks and allows them to be centrally configured, as well as control those running in current time assignments.
This list need to be carefully studied, all unnecessary tasks should be turned off, and those that are needed should have their schedule adjusted to meet immediate needs and common sense. For example, in our case, there is no need to process EGAIS responses once every 30 seconds (this setting was made for testing) and in operating mode it will be quite enough to do this, say, once every half hour.
Managed Application
In configurations based on managed application routine tasks are assigned a more significant role; with their help, various tasks can be performed to maintain the information base and keep it up to date, but at the same time, it is routine tasks that most often become the cause of “brakes”.
There is a separate item in the menu to manage routine tasks Administration - Support and Maintenance.
It can be immediately noted that the number of tasks has increased significantly (for example, we took the same configuration - Retail) and their proper configuration can significantly improve the performance of the information base. The default settings are made by 1C based on the needs of an average spherical company in a vacuum and are not even close to optimal.
First of all, we disable what is clearly unnecessary, what you do not work with. Then we optimize the schedule of rarely used functions, for example, updating the bank classifier in Retail, as well as checking counterparties, can be carried out once a week during non-working hours or at the end (beginning) of the working day.
Special attention should be paid to everything related to the search index. Full-text search is certainly a convenient thing, but working with its index is a very, very resource-intensive task. Therefore, you should not go to the extreme and abandon it, but you should seriously reconsider and adjust its parameters.
Let's start with text extraction, this operation allows you to search the contents of attached files, so if you do not use them, do not search for them, or you only have images there, then this operation can be disabled, in any case, performing it once every 85 seconds is clearly overkill.
PPD index update- one of the most resource-intensive operations, performed once per minute by default.
Now let’s think about how often the information that you most often search for is added or updated in the database? Obviously not every minute, so it will be quite enough to update the index much less frequently: once an hour, once a day, or even once a week.
The same applies to merger of the PPD index If you update the index once a day, you should configure the merge to run once a week, choosing the least disruptive time to start the job.
These simple operations will allow you, without much damage to the functionality of the configuration, to raise the comfort of working with it to a new level by refusing to frequently perform quite resource-intensive operations. Just don’t go to extremes; judge wisely how much you need certain capabilities and how often you should perform tasks related to them.
Tags:
Platforms: 1C:Enterprise 8.3, 1C:Enterprise 8.2, 1C:Enterprise 8.1
Configurations: All configurations
2012-11-13
53989
In document management, there are tasks that require periodic execution - for example, on the twentieth, or daily. As a rule, companies specifically for this purpose create certain rules that indicate when and how the necessary task should be performed, and who should control the process. Such tasks are performed according to regulations and are called regulated.
Quite often, monitoring regulations are observed in IT. This method is very familiar to administrators, since there are special programs, used to periodically check the performance of network infrastructure and servers. They notify the administrator about detected problems via SMS or email.
A similar system operates for webmasters, and the site’s availability is checked within 24 hours. Using the "Routine 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 take a closer look at this topic.
Scheduled tasks 1C
The 1C object, called “Routine tasks,” makes it possible to process information not after a problem occurs, but according to a schedule. In the configurator, a routine task is a way to set settings and set a schedule. In addition, it is possible to subsequently change the schedule in 1C Enterprise mode.
When using file database data, tasks are not executed automatically. In order to start the process, you need to start a 1C session in 1C Enterprise mode and start executing a routine task in it.
All standard configurations have a user setting that allows you to specify 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 job 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.
Adding a scheduled task
Routine tasks are located in - Configurator - General - Routine tasks. Add a new "task" and provide a name. Next, you need to go to the “Tasks” properties. And select Method Name. Here, you need to specify a handler function, just as it happens in an 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 a scheduled task allows you to define its name, which will then appear in the task management tools. The Routine Task Properties function is a key that allows you to group several different routine tasks. In this case, only one task can be launched at a time with the same value key Here, the value can be arbitrary, but it must be filled in, since an empty value is not taken into account by the system.
In Accounting edition 2.0, which is a standard configuration, routine tasks such as: “Recalculation of totals” and “Updating the configuration” are predefined, but such as, for example, “Deferred movements” and “Data exchange” are not predefined.
Retry on abnormal termination - restarts the current job. Designed to perform a launch that was not successful the first time. Here, it is indicated how many times you can restart and after what time has passed after an abnormal termination.
Monitoring and management tools for routine tasks 1C
The standard processing “Task Console”, which can be found on the ITS disks, is responsible for managing a routine task. This processing is a universal external standard processing for 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 a scheduled task;
Assign and change schedules;
Designate the user name with which the routine task will be performed;
See completed tasks (when and with what result), as well as task errors;
Routine task and copies of databases
When using server 1C, the following moment may arise:
To program, 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 was not included in the test database.
If one of these situations arose during the execution of tasks by a routine task that are associated only with their database, then this does not have negative consequences. But, often, a routine task can save files or other data, send emails, carry out an exchange. In this case, confusion may arise between the results of the “job” and the copies. To prevent this from happening, you need to disable “tasks” in the server management console.
Completed and not completed regulatory tasks
When creating routine tasks, it is important to check whether the task can be executed as a routine task. It's important to know that the server module doesn't do many things that are possible on the client. Further, a task dealing with something that is outside the base - rights play an important role in this Windows user, under which the task is executed.
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.