Search

CN-122019100-A - Timing task scheduling method based on dynamic time configuration

CN122019100ACN 122019100 ACN122019100 ACN 122019100ACN-122019100-A

Abstract

The invention discloses a timing task scheduling method based on dynamic time configuration, which relates to the technical field of computer software and comprises the following steps of S1, initializing a single-thread timing task executor in a system starting stage, synchronously triggering configuration refreshing and task starting processes, S2, calling a configuration service to obtain task execution interval configuration parameters containing time unit identifiers, wherein the configuration service is selected from a database or a configuration center, and S3, analyzing the configuration parameters through a preset time tool class and converting the configuration parameters into unified reference time units. The timing task scheduling method based on dynamic time configuration, provided by the invention, has the advantages that the flexibility and the efficiency of timing task scheduling are obviously improved by innovatively introducing a dynamic time configuration mechanism, the task execution interval is allowed to be dynamically adjusted according to external configuration during operation, the application is not required to be restarted, the adaptability and maintainability of the system are greatly enhanced, the configuration flow is simplified, and human errors are reduced.

Inventors

  • CHEN DEBIN
  • ZHAI QIANG
  • YU YANG
  • CHEN YANLEI
  • XU YUHANG
  • TANG YONGJI
  • SU RUIZHI

Assignees

  • 北京华能新锐控制技术有限公司
  • 西安热工研究院有限公司
  • 华能吉林发电有限公司新能源分公司

Dates

Publication Date
20260512
Application Date
20260203

Claims (10)

  1. 1. The timing task scheduling method based on dynamic time configuration is characterized by comprising the following steps of: S1, initializing a single-thread timing task executor in a system starting stage, and synchronously triggering configuration refreshing and task starting processes; S2, calling a configuration service to obtain a task execution interval configuration parameter containing a time unit identifier, wherein the configuration service is selected from a database or a configuration center; s3, analyzing the configuration parameters through a preset time tool class, converting the configuration parameters into a unified reference time unit, and if the new interval obtained through analysis is different from the current execution interval, updating the execution interval parameters; s4, canceling the scheduled original timing tasks, and rescheduling based on the updated execution interval, namely triggering the execution of the instant tasks once, and then periodically scheduling the execution according to the interval; S5, scanning data meeting preset screening conditions from a cache or a database in the task execution process, screening overtime data according to an execution interval and executing cleaning operation; and S6, when the system is closed, terminating the operation of the timing task executor to finish the release of resources.
  2. 2. The method for scheduling timed tasks based on dynamic time configuration according to claim 1, wherein S1 specifically comprises: after the system is deployed and started, a timing task component is synchronously loaded, and a single-thread timing task executor is initialized based on a Java standard concurrency tool, wherein the executor adopts an unbounded task queue design; In the initialization process of the executor, checking the core parameters of the executor and the availability of threads, and pre-testing the connection state of configuration services; after the executor is initialized, a configuration refreshing flow is started through a built-in trigger mechanism, and a task starting preposed flow is synchronously triggered; and in the task starting front-end process, finishing the initialization work of the buffer connection establishment and the data access layer.
  3. 3. The method for scheduling timed tasks based on dynamic time configuration according to claim 2, wherein the checking of the executor core parameters and the thread availability is specifically: Checking the core parameters of the executor, wherein the core parameters comprise thread priority, task queue initial capacity and executor starting identification, judging whether the thread of the single-thread executor is in a ready state or not through a Java thread state detection interface, and checking the scheduling authority of the thread of the executor, wherein the checking contents comprise a resource access limit condition and a thread blocking condition; If the core parameters meet the preset threshold value and the thread state is normal, judging that the verification is passed; If the verification fails, triggering a system alarm and recording a failure log, and ending the timed task starting flow.
  4. 4. The method for scheduling timed tasks based on dynamic time configuration according to claim 1, wherein S2 specifically comprises: Reading a preset configuration service type identifier in a system configuration file, wherein the identifier is a unique code corresponding to a database or a configuration center, calling a database connection test interface to verify the validity of JDBC connection parameters if the identifier is the database code, and confirming the service communication state through a health check API provided by the configuration center if the identifier is the configuration center code; Judging the current configuration service type according to the identification code and the connection verification result, triggering configuration service abnormality warning and recording reasons if the effective identification is not read or the connection verification fails; after the judgment is completed, the configuration parameter query is executed according to the corresponding service type, wherein the configuration parameter query comprises the steps that a database queries a configuration field of a preset data table, and a configuration center calls a configuration query API of the configuration field.
  5. 5. The method for scheduling timed tasks based on dynamic time configuration according to claim 1, wherein S2 further comprises: extracting corresponding task execution interval configuration parameters according to the key value format of the task unique identification-configuration value; confirming a time unit identifier contained in the configuration parameters, wherein the time unit identifier is standardized shorthand of seconds, minutes, hours and days; Setting a configuration acquisition timeout threshold, and triggering a retry mechanism if the configuration is not acquired beyond the threshold, adopting default configuration parameters and recording an abnormal log when the retry times reach a preset upper limit and are not acquired successfully; and after the configuration parameters are successfully acquired, transmitting the configuration parameters to an analysis flow.
  6. 6. The method for scheduling timed tasks based on dynamic time configuration according to claim 1, wherein S3 specifically comprises: based on the successfully acquired task execution interval configuration parameters, calling a preset time tool class, matching the configuration parameter format through a regular expression, and checking whether the configuration parameter format accords with a combination rule of a number and a standardized time unit; Extracting the currently effective task execution interval parameter, comparing the currently effective task execution interval parameter with the new interval parameter obtained by analysis, maintaining the current execution interval if the new interval is consistent with the current interval value, terminating the flow of the step, and if the new interval is inconsistent with the current interval value, updating the execution interval parameter to be the new interval after analysis and recording an interval change log.
  7. 7. The method for scheduling timed tasks based on dynamic time configuration according to claim 1, wherein S4 specifically comprises: If the original task exists, a cancellation interface of a timing task executor is called to terminate the periodic scheduling of the old task; if the old task is cancelled, triggering a conflict alarm and forcibly terminating the old task process, and recording the failure reason; Triggering a new task instant execution instruction based on the updated execution interval; After the instant execution task is completed, the configuration executor starts a periodic scheduling mechanism according to the new interval, binds the new task identifier and the execution interval, and stores the new task identifier and the execution interval in a task scheduling registry; and recording a task scheduling change log, wherein the scheduling change log comprises an old task identifier, a new interval value, an instant execution result and a period scheduling starting time.
  8. 8. The method for scheduling timed tasks based on dynamic time configuration according to claim 1, wherein S5 specifically comprises: Reading a type of a data storage medium preset by a system, if the type is cache, establishing cache connection, and if the type is database, acquiring connection through a data access layer; Checking the connection state of the storage medium, triggering a retry mechanism if the connection fails, recording an abnormal log if the retry is unsuccessful, and terminating the step; The method comprises the steps of scanning original data meeting the conditions in a storage medium according to a preset service screening rule, calculating a data timeout threshold value, namely subtracting the execution interval from the current system time by combining the updated execution interval; Invoking a data processing service to perform batch cleaning operation on the batch extracted timeout data; if the cleaning failure data exists, recording the failure data identification and the reason, and triggering a subsequent retry cleaning mechanism; And after the cleaning is finished, closing the data storage medium connection, and releasing the data access resource.
  9. 9. The method for scheduling timed tasks based on dynamic time configuration according to claim 8, wherein the executing batch cleaning operation is specifically: invoking a batch cleaning interface of the data processing service, and transmitting a unique identification set of the current batch overtime data; The method comprises the steps of adapting a cleaning strategy according to the type of a storage medium, wherein the cleaning strategy comprises the steps of calling a batch deleting command by a cache medium and executing batch deleting SQL by a database medium; If the related data index exists, synchronously generating an index cleaning instruction, executing the index cleaning instruction and a data subject cleaning operation atom, and recording the starting time, the data identification range and the cleaning strategy type of the current batch cleaning; the method comprises the steps of receiving a cleaning execution result returned by a data processing service, wherein the cleaning execution result comprises a success identification number, a failure identification number and a failure reason, suspending the cleaning of a subsequent batch and triggering an alarm if the single batch cleaning failure rate exceeds a preset threshold value, and continuously executing batch cleaning operation of timeout data of the next batch if the single batch cleaning failure rate does not exceed the threshold value.
  10. 10. The method for scheduling timed tasks based on dynamic time configuration according to claim 1, wherein S6 specifically comprises: Monitoring a system shutdown trigger signal, wherein the signal comprises a service shutdown instruction, a system restart notification and an active shutdown trigger instruction; Detecting the current state of a single-thread timing task executor, judging whether a task being executed and a queue task to be executed exist or not, starting a task graceful termination mechanism if an incomplete task exists, and setting the maximum waiting timeout time; After waiting for overtime, the task is not completed, the task process is forcedly terminated, and a task interrupt log is recorded; Releasing associated resources of the executor, including configuration cache data, task scheduling registry information and memory resources occupied by the executor thread; The method comprises the steps of checking the termination state of an executor, confirming that a core thread is destroyed and associated resources are not occupied, triggering a system-level alarm and forcedly releasing a resource occupied port if the termination of the executor fails, and recording an executor termination log which comprises a closing triggering reason, termination time, a resource release list and incomplete task details.

Description

Timing task scheduling method based on dynamic time configuration Technical Field The invention relates to the technical field of computer software, in particular to a timing task scheduling method based on dynamic time configuration. Background In the technical field of computer software, timing task scheduling is one of key technologies for guaranteeing stable operation of a system, and is widely applied to various scenes such as alarm data processing, cache cleaning, log archiving and the like. The method has the core effects of automatically triggering task execution according to the preset rule, reducing manual intervention and improving the operation and maintenance efficiency and the data processing timeliness of the system. At present, the mainstream timing task scheduling implementation mode in the industry comprises fixed period configuration based on injection, professional scheduling framework deployment and the like, and the technologies realize basic automatic task management through presetting execution intervals, so that important support is provided for the normalized operation of various software systems. The existing timing task scheduling technology forms a mature floor mode in practical application, can meet the basic requirements of partial scenes, and still has some aspects to be optimized. On the one hand, the execution interval of most technical schemes is required to be defined by a hard code or a static configuration file, and is difficult to dynamically adjust in the running process, and if the service requirement changes, the execution frequency is required to be modified, and the application program is required to be restarted, so that the continuous running of the system is affected. On the other hand, the configuration mode with fixed intervals is difficult to adapt to the dynamic fluctuation of the traffic, and the situation that the execution frequency is not matched with the actual demand possibly occurs, so that the utilization of system resources is not reasonable enough. In addition, a framework supporting dynamic scheduling partially often needs to rely on complex external components or additionally maintain a special database table, and the deployment complexity and the later maintenance cost of the system are increased. In this regard, we propose a timed task scheduling method based on dynamic time configuration. Disclosure of Invention In order to solve the technical problems, the technical scheme solves the problems that the prior timing task scheduling technology is difficult to dynamically adjust and change and restart application in operation due to the fact that the execution interval is defined by code hard coding or static configuration files, the fixed interval is difficult to adapt to traffic fluctuation, resource utilization is easy to be unreasonable, a framework for supporting dynamic scheduling is partially supported, and complex components or a special database table is needed to be maintained, so that the system deployment complexity and the later maintenance cost are increased. In order to achieve the above purpose, the invention adopts the following technical scheme: a timing task scheduling method based on dynamic time configuration comprises the following steps: S1, initializing a single-thread timing task executor in a system starting stage, and synchronously triggering configuration refreshing and task starting processes; S2, calling a configuration service to obtain a task execution interval configuration parameter containing a time unit identifier, wherein the configuration service is selected from a database or a configuration center; s3, analyzing the configuration parameters through a preset time tool class, converting the configuration parameters into a unified reference time unit, and if the new interval obtained through analysis is different from the current execution interval, updating the execution interval parameters; s4, canceling the scheduled original timing tasks, and rescheduling based on the updated execution interval, namely triggering the execution of the instant tasks once, and then periodically scheduling the execution according to the interval; S5, scanning data meeting preset screening conditions from a cache or a database in the task execution process, screening overtime data according to an execution interval and executing cleaning operation; and S6, when the system is closed, terminating the operation of the timing task executor to finish the release of resources. Preferably, the S1 specifically includes: after the system is deployed and started, a timing task component is synchronously loaded, and a single-thread timing task executor is initialized based on a Java standard concurrency tool, wherein the executor adopts an unbounded task queue design; In the initialization process of the executor, checking the core parameters of the executor and the availability of threads, and pre-testing the connection state of configu