Method and apparatus for automatically configuring tasks based on a task scheduling platform

By implementing an automated executor and task registration mechanism on the task scheduling platform, the problem of manual configuration is solved and the accuracy and efficiency of configuration is improved.

CN119781872BActive Publication Date: 2025-05-30BEIJING QINGSONG YIKANG INFORMATION TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510283413.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-11
Publication Date
2025-05-30
Estimated Expiration
2045-03-11

AI Technical Summary

Technical Problem

The configuration operations of the task scheduling platform are prone to errors, especially when the number of tasks increases, manual configuration operations increase the risk of operational errors.

Method used

Provides an automatic configuration of task based on the task scheduling platform, and realizes automatic configuration and registration at project startup by detecting the executor configuration, automatically registering the executor, analyzing task annotation information and registering tasks.

Benefits of technology

It reduces the need for manual intervention, reduces errors caused by human negligence, and improves the configuration accuracy and efficiency of the task scheduling platform.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119781872B_ABST
    Figure CN119781872B_ABST
Patent Text Reader

Abstract

The present application relates to a method and device for automatically configuring tasks based on a task scheduling platform. The method includes: after a project in the task scheduling platform is successfully started, if the actuator configuration of the project is detected, it is determined that the necessary components of the project have been correctly configured; if it is queried according to the value of the actuator configuration that the target actuator has not been registered in the task scheduling platform, the target actuator is registered in the task scheduling platform; if it is determined that the target task with the first annotation information in the project also has the second annotation information, the configuration parameters of the target task are parsed according to the second annotation information; if the target task does not exist in the task set registered by the target actuator in the task scheduling platform, task registration is performed in the task scheduling platform through the task name and configuration parameters of the target task. The present application improves the configuration accuracy of the task scheduling platform.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of cloud computing technology, and in particular, to a method and device for automatically configuring tasks based on a task scheduling platform. Background Art

[0002] In modern software development, task scheduling is an indispensable part. For example, XXL-JOB, as a lightweight task scheduling platform, has been widely used due to its clear interface, simple configuration, and support for distribution. It significantly simplifies the operation process of timed task scheduling and improves development and operation and maintenance efficiency.

[0003] However, in the actual use process, the executor and tasks must be manually configured through the page of the task scheduling platform. When the number of executors and tasks is small, this configuration method is relatively easy to manage. But as the number of tasks increases, the manual configuration operation on the page increases the risk of operation errors. Summary of the Invention

[0004] This application provides a method and device for automatically configuring tasks based on a task scheduling platform to solve the problem that the configuration operation of the task scheduling platform is prone to errors.

[0005] In a first aspect, this application provides a method for automatically configuring tasks based on a task scheduling platform, and the method includes:

[0006] After the project in the task scheduling platform starts successfully, if the executor configuration of the project is detected, it is determined that the necessary components of the project have been correctly configured;

[0007] If it is queried according to the value of the executor configuration that the target executor has not been registered in the task scheduling platform, the target executor is registered in the task scheduling platform, where the value of the executor configuration is used to uniquely identify the executor;

[0008] If it is determined that the target task with the first annotation information in the project also has the second annotation information, the configuration parameters of the target task are parsed according to the second annotation information, where the first annotation information is used to mark the task, and the second annotation information is used to provide the configuration information of the task;

[0009] If the target task does not exist in the task set registered by the target executor in the task scheduling platform, the task is registered in the task scheduling platform through the task name and configuration parameters of the target task.

[0010] Optionally, after the project in the task scheduling platform starts successfully, if the executor configuration of the project is detected, determining that the necessary components of the project have been correctly configured includes:

[0011] After the project is successfully launched, listen for the executor addition event through the automatic registration manager;

[0012] When the executor addition event is detected, scan the configuration files in the project;

[0013] If the configuration file contains the executor configuration, it is determined that the necessary components of the project have been correctly configured.

[0014] Optionally, if it is queried according to the value of the executor configuration that the target executor has not been registered in the task scheduling platform, registering the target executor in the task scheduling platform includes:

[0015] Use the value of the executor configuration to determine the target executor in the project;

[0016] If it is queried through the executor query interface preset in the task scheduling platform that the target executor has not been registered in the task scheduling platform, register the target executor through the executor registration interface preset in the task scheduling platform.

[0017] Optionally, if it is determined that the target task with the first annotation information in the project also has the second annotation information, parsing the configuration parameters of the target task according to the second annotation information includes:

[0018] Determine the task list with the first annotation information by scanning the methods or classes that mark tasks in the project;

[0019] If the target task in the task list has both the first annotation information and the second annotation information, parse the configuration parameters of the target task according to the second annotation information.

[0020] Optionally, if the target task does not exist in the task set registered by the target executor in the task scheduling platform, registering the task in the task scheduling platform through the task name and configuration parameters of the target task includes:

[0021] Call the task query interface preset in the task scheduling platform to query the task set registered by the target executor in the task scheduling platform;

[0022] Compare the task list scanned in the project with the task set registered in the task scheduling platform;

[0023] If the target task in the task list does not exist in the task set, it is determined that the target task has not been registered in the task scheduling platform;

[0024] Register the task through the task registration interface preset in the task scheduling platform according to the task name and configuration parameters of the target task.

[0025] Optionally, before the project in the task scheduling platform is started, the method further includes:

[0026] Configure interface information in the task scheduling platform and introduce the call logic of the interface information in the project, where the interface information includes an actuator query interface, an actuator registration interface, a task query interface, and a task registration interface;

[0027] Add second annotation information for the task in the project;

[0028] Add an automatic registration manager in the project, where the automatic registration manager inherits the listening interface and is used to listen for events and execute query and registration processes;

[0029] Package and publish the project to a set repository.

[0030] In a second aspect, the present application provides a device for automatically configuring tasks based on a task scheduling platform, and the device includes:

[0031] A detection module, configured to determine that the necessary components of the project have been correctly configured if it detects the actuator configuration of the project after the project in the task scheduling platform is successfully started;

[0032] An actuator registration module, configured to register the target actuator in the task scheduling platform if it is found according to the value of the actuator configuration that the target actuator has not been registered in the task scheduling platform, where the value of the actuator configuration is used to uniquely identify the actuator;

[0033] An analysis module, configured to analyze the configuration parameters of the target task according to the second annotation information if it is determined that the target task with the first annotation information in the project also has the second annotation information, where the first annotation information is used to mark the task, and the second annotation information is used to provide configuration information of the task;

[0034] A task registration module, configured to register the task in the task scheduling platform through the task name and configuration parameters of the target task if the target task does not exist in the task set registered by the target actuator in the task scheduling platform.

[0035] Optionally, the task registration module is used to:

[0036] Call the task query interface preset in the task scheduling platform to query the task set registered by the target actuator in the task scheduling platform;

[0037] Compare the task list scanned in the project with the set of tasks registered in the task scheduling platform;

[0038] If the target task in the task list does not exist in the set of tasks, it is determined that the target task has not been registered in the task scheduling platform;

[0039] Register the task through the task registration interface preset in the task scheduling platform according to the task name and configuration parameters of the target task.

[0040] In a third aspect, the present application provides an electronic device, including: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; and at least one memory connected to the at least one bus.

[0041] In a fourth aspect, the present application further provides a computer storage medium storing computer-executable instructions for executing the method for automatically configuring tasks based on a task scheduling platform according to any one of the above in the present application.

[0042] The above technical solutions provided by the embodiments of the present application have the following advantages compared with the prior art:

[0043] After determining the correct configuration of the project components through actuator configuration, the actuator can be automatically registered in the task scheduling platform, and the configuration parameters of the task can be determined according to the annotation information of the task in the actuator. Then, the task is registered in the task scheduling platform according to the project name and configuration parameters. The present application can automatically register the actuator and the task in the task scheduling platform when the project is started. The automated configuration detection and registration mechanism reduces the need for manual intervention, avoids errors caused by human negligence, and improves the configuration accuracy of the task scheduling platform. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] The accompanying drawings herein are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.

[0045] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0046] One or more embodiments are exemplarily illustrated by the pictures in the corresponding accompanying drawings. These exemplary illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the accompanying drawings are represented as similar elements, unless otherwise stated, and the figures in the accompanying drawings do not constitute a scale limitation.

[0047] Figure 1 It is a flowchart of a method for automatically configuring tasks based on a task scheduling platform provided by an embodiment of the present application;

[0048] Figure 2 It is a flowchart of automatically configuring tasks based on a task scheduling platform provided by an embodiment of the present application;

[0049] Figure 3 It is a schematic structural diagram of a device for automatically configuring tasks based on a task scheduling platform provided by an embodiment of the present application;

[0050] Figure 4 It is a schematic structural diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners

[0051] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Apparently, the described embodiments are some, but not all, of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the protection scope of the present application.

[0052] The following disclosure provides many different embodiments or examples for implementing different structures of the present application. To simplify the disclosure of the present application, the components and settings of specific examples are described below. Of course, they are only examples and are not intended to limit the present application. In addition, the present application may repeat reference numerals and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.

[0053] To solve the problem that the configuration operation of the task scheduling platform mentioned in the background technology is error-prone, the embodiments of the present application automatically add the executors and tasks required for the project to the task scheduling platform after the project is started, without manual configuration, improving the configuration accuracy.

[0054] The present application can be applied to distributed task scheduling or to a single-machine environment.

[0055] Some terms mentioned in the embodiments of the present application are explained below, including the following content.

[0056] Value of the executor configuration xxl.job.executor.appname: It is used to identify and distinguish different executors. Each executor has a unique executor name appName in the task scheduling platform, which is the identity identifier of the executor.

[0057] The first annotation information @xxlJob: It is an annotation used to mark a method or class of a task.

[0058] The second annotation information xxlJobRegisterWithParam: It is used to mark and configure specific tasks. It contains various parameters of the task, such as task description, person in charge, Cron expression, scheduling type, running mode, etc. This information helps the task scheduling platform understand the scheduling rules and behaviors of the tasks.

[0059] Task list taskNameList: This is a list of task names obtained by scanning all methods or classes with the @xxlJob annotation in the current project. These tasks are defined according to the business requirements of the project and may include newly added tasks or modified tasks.

[0060] Registered task set xxlJobtaskNameList: This is a list of the names of all registered tasks under the executor name obtained from the task scheduling platform. These tasks have been registered on the task scheduling platform and can be managed and scheduled.

[0061] Next, in combination with specific implementation manners, a method for automatically configuring tasks provided by an embodiment of the present application will be described in detail. Taking an application to a server as an example, as Figure 1 shown, the specific steps are as follows:

[0062] Step 101: After the project in the task scheduling platform is successfully started, if the executor configuration of the project is detected, it is determined that the necessary components of the project have been correctly configured;

[0063] Step 102: If it is queried according to the value of the executor configuration that the target executor has not been registered in the task scheduling platform, the target executor is registered in the task scheduling platform, where the value of the executor configuration is used to uniquely identify the executor;

[0064] Step 103: If it is determined that the target task with the first annotation information in the project also has the second annotation information, the configuration parameters of the target task are parsed according to the second annotation information, where the first annotation information is used to mark the task, and the second annotation information is used to provide the configuration information of the task;

[0065] Step 104: If the target task does not exist in the task set registered by the target executor in the task scheduling platform, perform task registration in the task scheduling platform using the task name and configuration parameters of the target task.

[0066] In step 101, after the project in the task scheduling platform starts successfully, it is first necessary to detect whether the executor configuration of the project is correct. This step is achieved by checking the xxl.job.executor.appname configuration item in the configuration file. If this configuration item exists and is valid, it can be determined that the necessary components of the project have been correctly configured. This automatic detection mechanism not only improves the accuracy of the configuration but also reduces the need for manual intervention. For example, in a Spring Boot project, developers only need to add the corresponding executor configuration in the file, and the system will automatically verify the existence and validity of these configuration items at startup.

[0067] Among them, the task scheduling platform includes but is not limited to XXL-JOB, Quartz, ElasticJob (elastic job), or Spring Batch (Spring batch processing). The type of the task scheduling platform is not specifically limited in this application.

[0068] In step 102, once it is confirmed that the executor configuration is correct, the system then needs to query the task scheduling platform (such as XXL-JOB) to determine whether the target executor has been registered. If it has not been registered, call the corresponding API to register the executor in the task scheduling platform. The value of the executor configuration is used to uniquely identify the executor, ensuring that each executor has a unique name in the task scheduling platform. This automated registration mechanism simplifies the executor management process and avoids the cumbersome operation of registering one by one manually. In addition, it also reduces errors caused by human negligence and improves the reliability and stability of the system.

[0069] In step 103, for each task in the project, the system needs to check whether it has two annotations at the same time: one for marking the task (the first annotation information), and the other for providing the configuration information of the task (the second annotation information). This dual-annotation design makes the management and configuration of tasks more flexible and efficient. For example, the @XxlJob annotation (the first annotation information) can be used to mark the task, while the @XxlJobRegisterWithParam annotation (the second annotation information) provides the specific configuration parameters of the task, such as the Cron expression, task processor, etc. By parsing the @XxlJobRegisterWithParam annotation, the system can automatically generate the detailed configuration of the task, which is convenient for registering it in the task scheduling platform.

[0070] In step 104, the system obtains the set of tasks registered by the target executor in the task scheduling platform. If the system finds that a certain task in the project does not exist in this task set, indicating that the task has not been registered in the task scheduling platform, it can be automatically registered in the task scheduling platform according to the task name and configuration parameters of the task.

[0071] Exemplarily, there is an e-commerce background management system, which contains multiple scheduled tasks, such as order processing, inventory update, and promotion activity management, etc. To simplify the configuration process of task scheduling, an automated configuration mechanism can be introduced:

[0072] 1. Executor configuration detection: When the application starts, the system will listen for executor addition events through the automatic registration manager and automatically scan the application.properties file to find whether there is a valid xxl.job.executor.appname configuration item in this file. If this configuration item is detected, it is considered that the necessary components of the project have been correctly configured.

[0073] 2. Executor registration: Query the task scheduling platform (such as XXL-JOB) according to the value of xxl.job.executor.appname. If the corresponding executor is not found, the executor will be automatically registered. This can ensure that each executor can be correctly identified and managed.

[0074] 3. Task annotation parsing: The system will automatically scan all methods and classes in the project to find tasks with @XxlJob and @XxlJobRegisterWithParam annotations. For each eligible task, the system will parse its configuration parameters, such as task name, Cron expression, etc.

[0075] 4. Task automatic registration: If a certain task has not been registered in the task scheduling platform, the system will automatically register it in the task scheduling platform according to its task name and configuration parameters. This can ensure that all tasks can be scheduled and executed in a timely manner without manual configuration one by one.

[0076] In this application, after determining that the project components are correctly configured through executor configuration, the executor can be automatically registered in the task scheduling platform, and the configuration parameters of the task can be determined according to the annotation information of the task in the executor. Then, the task is registered in the task scheduling platform according to the project name and configuration parameters. This application can automatically register the executor and tasks in the task scheduling platform when the project starts. The automated configuration detection and registration mechanism reduces the need for manual intervention, avoids errors caused by human negligence, and improves the configuration accuracy of the task scheduling platform.

[0077] In addition, the automated registration mechanism in this application not only improves the accuracy of configuration but also reduces the workload of manual operations. Especially when the number of tasks is large, through automated registration, the system can automatically scan all executors and eligible tasks at the startup of the application and register them in the task scheduling platform, thus improving work efficiency.

[0078] As an alternative implementation, in step 101, after the project in the task scheduling platform starts successfully, if the executor configuration of the project is detected, it is determined that the necessary components of the project have been correctly configured, including the following:

[0079] Step S11: After the project starts successfully, listen for the executor addition event through the automatic registration manager;

[0080] Step S12: When the executor addition event is detected, scan the configuration files in the project;

[0081] Step S13: If the configuration file contains the executor configuration, it is determined that the necessary components of the project have been correctly configured.

[0082] In step S11, after the project starts successfully, the automatic registration manager (such as the xxlJobAddexecutor class) inherits the ApplicationListener interface to listen for the executor addition event. This mechanism can ensure that the configuration and registration work related to the executor are automatically detected and processed at the startup of the application. Specifically, the automatic registration manager will trigger the corresponding event listener after the application startup is completed to check whether the executor configuration of the project has been correctly set. This method not only improves the accuracy of configuration but also reduces the need for manual intervention.

[0083] In step S12, once the executor addition event is detected, the next step is to scan the configuration files of the project to further confirm the specific content of the executor configuration. This step usually involves reading and parsing the configuration files (such as application.properties or application.yml) to extract the configuration items related to the executor. In this way, the system can obtain the detailed information of the executor, such as the name, address, etc.

[0084] The process of scanning the configuration files not only simplifies the configuration management but also improves the flexibility of the system. For example, if some parameters of the executor need to be modified, only the configuration file needs to be updated and the application restarted, without manually adjusting the relevant settings in the task scheduling platform. In addition, centralized management of the configuration files also helps to reduce the possibility of configuration errors because all configurations are centralized in one place, facilitating unified management and maintenance.

[0085] In step S13, the executor configuration xxl.job.executor.appname is a crucial configuration item used to identify and distinguish different executors. Each executor needs to have a unique appName so that the xxl-job task scheduling platform can identify and manage different executors. In xxl-job, tasks are assigned to specific executors for execution. Therefore, tasks can be associated with specific executors through the appName.

[0086] When the project starts, the system scans and checks whether there is a valid xxl.job.executor.appname configuration. If this configuration does not exist, it means that the executor cannot be correctly identified, and the system has no idea which executor to use to run the tasks. Moreover, tasks rely on executors to execute specific logic. If the executor is not correctly configured or registered, the tasks cannot be scheduled and executed properly.

[0087] After scanning the configuration file, if a valid executor configuration is found, it can be determined that the necessary components of the project have been correctly configured. This means that the system already has the basic conditions required to run scheduled tasks and can continue with subsequent operations such as task registration and scheduling. This automated detection mechanism not only improves the accuracy of configuration but also reduces the need for manual intervention and the errors caused by human negligence. When the system detects that these configuration items exist and are valid, it considers the executor configuration to be correctly set and proceeds to the next step. This mechanism ensures that each executor can be correctly identified and managed, thus laying a solid foundation for subsequent task scheduling.

[0088] For example, in a Spring Boot project, developers can add the relevant executor configuration to the application.properties file and use the automatic registration manager to automatically verify the existence and validity of these configuration items when the application starts. In this way, the system can complete the necessary preparatory work during the startup phase to ensure the smooth progress of subsequent task scheduling.

[0089] In this application, after the automatic registration manager (such as the xxlJobAddexecutor class) listens to the executor addition event, it scans the executor configuration xxl.job.executor.appname in the project. Since each executor needs to have a unique appName, it can be checked through the executor configuration whether the necessary components of the project (executors and tasks) have been correctly configured, thus ensuring that the registration of executors and tasks can proceed normally subsequently. This mechanism ensures that all executors can be correctly identified and managed, avoiding task scheduling failures caused by configuration errors or omissions.

[0090] As an alternative implementation, in step 102, if it is queried according to the value configured in the actuator that the target actuator has not been registered in the task scheduling platform, then registering the target actuator in the task scheduling platform includes:

[0091] Step S21: Determine the target actuator in the project by using the value configured in the actuator;

[0092] Step S22: If it is queried through the preset actuator query interface in the task scheduling platform that the target actuator has not been registered in the task scheduling platform, then register the target actuator through the preset actuator registration interface in the task scheduling platform.

[0093] In step S21, after the project starts successfully, the system first needs to determine the target actuator in the project according to the value of the actuator configuration xxl.job.executor.appname. This process involves reading and parsing the configuration file to extract the unique identifier appName of the actuator. This step ensures that each actuator has a unique identifier and that this identifier can be correctly recognized and managed on the task scheduling platform. In this way, the system can clearly identify the target actuator that needs to be managed and scheduled in the current project.

[0094] In step S22, once the target actuator is determined, the next step is to query whether the actuator has been registered through the preset interface provided by the task scheduling platform. Specifically:

[0095] 1. Query the actuator: Call the actuator query interface provided by the task scheduling platform (such as XXL-JOB), use appName as the query parameter, and check whether the actuator has been registered in the task scheduling platform.

[0096] 2. Register the actuator: If the query result shows that the target actuator has not been registered, then call the actuator registration interface provided by the task scheduling platform to register the actuator in the task scheduling platform. When registering, relevant information of the actuator, such as appName and address, needs to be provided.

[0097] In this application, the automated query and registration mechanism reduces the need to manually register actuators one by one. Developers only need to add the necessary information in the configuration file, and the system will automatically complete the relevant verification and registration work at startup, reducing the workload of manual intervention and also avoiding possible errors caused by manual registration of actuators.

[0098] As an alternative implementation, in step 103, if it is determined that the target task with the first annotation information in the project also has the second annotation information, then parsing the configuration parameters of the target task according to the second annotation information includes:

[0099] Step S31: Determine the task list with the first annotation information by scanning the methods or classes marked with tasks in the project;

[0100] Step S32: If the target task in the task list has both the first annotation information and the second annotation information, parse the configuration parameters of the target task according to the second annotation information.

[0101] After the project starts successfully, the system first needs to scan all the methods or classes in the project, find the tasks with the first annotation information (such as @XxlJob), and generate a task list. This process ensures that the system can comprehensively identify all the tasks that need to be scheduled in the project. This scanning mechanism not only simplifies the task management process but also improves the flexibility of the system. Developers only need to add the corresponding annotations when defining tasks, and the system will automatically complete the relevant identification work at startup.

[0102] Once the task list with the first annotation information is determined, the next step is to check whether these tasks have the second annotation information and parse the configuration parameters. Specifically, use the @XxlJobRegisterWithParam annotation to provide the specific configuration parameters of the task, such as the Cron expression, task processor, etc. If a task has both the @XxlJob and @XxlJobRegisterWithParam annotations, the system will parse the configuration parameters of the task according to the @XxlJobRegisterWithParam annotation. In this way, the system can obtain the detailed configuration information of the task, such as the task name, Cron expression, task processor, etc. These configuration parameters are crucial for the correct registration and scheduling of the task, ensuring that the task can be correctly executed at the specified time interval. If a task in the project has the first annotation information but does not have the second annotation information, then the system needs to notify the developer to add the second annotation information for this task.

[0103] Exemplarily, when the application starts, the system scans all methods or classes in the project, looks for tasks with the @XxlJob annotation, and generates a task list. For example, the system scans the following tasks: orderProcessingTask, inventoryUpdateTask, and promotionManagementTask. For each task, the system checks whether it has the @XxlJobRegisterWithParam annotation at the same time and parses the configuration parameters therein. For example, assume that only the task orderProcessingTask has the @XxlJobRegisterWithParam annotation. Then, the configuration parameters of the task orderProcessingTask are parsed, including but not limited to the task name (orderProcessingTask), Cron expression (00 / 5…), or task handler (OrderProcessingTaskHandler), etc.

[0104] In this application, only when a task has the first annotation information will the system recognize it as a schedulable task. This step ensures that the system will not mistakenly treat ordinary classes or methods as tasks. Only when a task has the second annotation information at the same time will the system parse its specific configuration parameters. This step ensures that the system can obtain the detailed configuration information of the task, such as the scheduling time, processor, etc., so as to ensure that the task can be executed at the correct time and in the correct way. If the system parses the configuration parameters for all tasks with the first annotation, it may lead to unnecessary parsing operations. For example, some tasks may not require complex scheduling configurations and only need to be simply marked. Therefore, only when a task has both the first and second annotations will the configuration parameters be parsed, which can avoid unnecessary calculations and resource consumption.

[0105] In addition, by centrally managing the configuration information of tasks through annotations, the configuration becomes more intuitive and easier to maintain. Developers can manage the configurations of all tasks uniformly in one place, which is convenient for subsequent adjustment and optimization, and reduces the maintenance cost and complexity.

[0106] As an optional implementation manner, in step 104, if the target task does not exist in the task set registered by the target executor in the task scheduling platform, then registering the task in the task scheduling platform through the task name and configuration parameters of the target task includes:

[0107] Step S41: Call the preset task query interface in the task scheduling platform to query the task set registered by the target executor in the task scheduling platform;

[0108] Step S42: Compare the task list scanned in the project with the set of tasks registered in the task scheduling platform;

[0109] Step S43: If the target task in the task list does not exist in the set of tasks, it is determined that the target task has not been registered in the task scheduling platform;

[0110] Step S44: Register the task through the task registration interface preset in the task scheduling platform according to the task name and configuration parameters of the target task.

[0111] After the project starts successfully, the system first needs to call the task query interface provided by the task scheduling platform (such as XXL-JOB) to query the set of tasks registered by the target executor in the task scheduling platform. This process queries all registered tasks related to this executor by using the appName. This step ensures that the system can accurately obtain the task status of the current executor on the task scheduling platform and provides basic data support for subsequent operations.

[0112] Next, the system scans the project's code and configuration files to find tasks with the first annotation information @XxlJob, generates a task list, and then compares this task list with the set of tasks obtained from the task scheduling platform. This comparison mechanism can help the system identify which tasks have been registered on the task scheduling platform and which tasks have not been registered. In this way, the system can comprehensively master the status of all tasks in the project and ensure that each task can be correctly managed and scheduled.

[0113] During the comparison process, if it is found that a certain task exists in the task list in the project but not in the set of tasks in the task scheduling platform, it can be determined that the task has not been registered in the task scheduling platform. This process ensures that all necessary tasks are correctly identified and managed, avoiding task scheduling failures caused by unregistered tasks. For example, assume that a task named orderProcessingTask is defined in the project but not found in the set of tasks in the task scheduling platform, then the system can confirm that the task has not been registered.

[0114] For those target tasks that have not been registered in the task scheduling platform, the system can register them through the task registration interface provided by the task scheduling platform according to their task names and configuration parameters. This step ensures that all newly added tasks can be recognized and managed by the task scheduling platform in a timely manner, thus ensuring the smooth progress of task scheduling. For example, assume that the system discovers that orderProcessingTask has not been registered, then it will register it in the task scheduling platform according to the name, Cron expression, and other configuration parameters of this task.

[0115] This application compares the task list in the project with the task set in the task scheduling platform to ensure that all tasks in the project are correctly registered, avoid task scheduling failures caused by missing tasks, and improve the reliability of the system.

[0116] As an optional implementation, before the project starts in the task scheduling platform, the method further includes the following steps:

[0117] Step S51: Configure interface information in the task scheduling platform and introduce the call logic of the interface information in the project, where the interface information includes an executor query interface, an executor registration interface, a task query interface, and a task registration interface;

[0118] Step S52: Add second annotation information for tasks in the project;

[0119] Step S53: Add an automatic registration manager in the project, where the automatic registration manager inherits the listening interface and is used to listen for events and execute query and registration processes;

[0120] Step S54: Package the project and publish it to the specified repository.

[0121] In step S51, configure the necessary interface information in the task scheduling platform (such as XXL-JOB), including an executor query interface, an executor registration interface, a task query interface, and a task registration interface. These interfaces are used to interact with the task scheduling platform to ensure that the system can automatically complete operations such as querying and registering executors and tasks. Then, introduce the call logic of this interface information in the project. This step ensures that the system can automatically communicate with the task scheduling platform when starting, obtain the status of the current executor and tasks, and perform corresponding operations as needed. The functions of each interface information are as follows.

[0122] Executor query interface: Used to query whether the current executor has been registered in the task scheduling platform.

[0123] Executor registration interface: Used to register a new executor on the task scheduling platform.

[0124] Task query interface: Used to query the tasks that have been registered by the current executor in the task scheduling platform.

[0125] Task registration interface: Used to register a new task on the task scheduling platform.

[0126] In this way, the system can automatically detect and process the configuration of executors and tasks when starting, reducing the need for manual intervention.

[0127] In step S52, introduce second annotation information (such as @XxlJobRegisterWithParam) for the newly added task in the project to provide specific configuration parameters for the task. This kind of annotation not only identifies the existence of the task, but also provides detailed configuration information, such as task name, Cron expression, task processor, etc.

[0128] In this way, the system can obtain the detailed configuration information of the task to ensure that the task can be scheduled and executed at the correct time and in the correct way. For example, the task name is used to uniquely identify the task; the Cron expression is used to define the scheduling time of the task; the task processor is used to specify the specific execution logic of the task. This design improves the flexibility of the system, enabling developers to set different configuration parameters for each task according to actual business requirements.

[0129] In step S53, the system introduces an automatic registration manager in the project. This manager inherits the listening interface and is used to listen for events and execute the query and registration processes. It specifically includes the following functions: 1. Listening interface. The automatic registration manager will listen for the application startup event to ensure that relevant operations are automatically executed when the project starts. 2. Query process. The automatic registration manager will call the query interface provided by the task scheduling platform at startup to check the registration status of the executor and the task. 3. Registration process. If it is found that a certain executor or task has not been registered, the corresponding registration interface will be automatically called to register the executor or task to the task scheduling platform. In this way, the system can automatically complete the management and registration of the executor and the task at startup, reducing the need for manual operations and improving the accuracy and efficiency of configuration.

[0130] In step S54, finally, the system packages the project and publishes it to the set repository (such as Maven repository or Nexus repository). This step ensures that the project can be easily deployed and distributed, facilitating subsequent version management and maintenance. Among them, a build tool can be used to package the project into a deployable format (such as JAR file or WAR file), and then upload the packaged file to the set repository for other team members or production environments to download and deploy. In this way, the project can be easily version-controlled and continuously integrated, improving the efficiency of development and operation and maintenance.

[0131] This application provides a method and process for automatically configuring tasks based on a task scheduling platform, including the following steps.

[0132] 1. Preprocessing stage.

[0133] In the preprocessing stage of the project, it is first necessary to ensure that all necessary dependencies and tools are installed and configured, including build tools (such as Maven or Gradle), task scheduling platforms (such as XXL-JOB), and related development environments. Developers need to configure the executor query interface, executor registration interface, task query interface, and task registration interface on the task scheduling platform according to the project requirements. These interfaces will be used for subsequent automated query and registration operations. In addition, corresponding configuration items, such as xxl.job.executor.appname, need to be added to the project's configuration file to ensure that the system can correctly identify and manage the executor.

[0134] 2. Project initialization and configuration.

[0135] Next, in the project initialization stage, developers need to introduce the interface information provided by the task scheduling platform and write the interface call logic in the project. This step ensures that the system can automatically communicate with the task scheduling platform at startup, obtain the status of the current executor and tasks, and perform corresponding operations as needed.

[0136] 3. Introduction of the automatic registration manager.

[0137] To achieve automatic management and registration of tasks, an automatic registration manager needs to be introduced into the project. This manager inherits the listener interface, is used to listen for application startup events, and automatically checks the executor configuration and executes the query and registration process at startup. Specifically, the automatic registration manager will call the query interface provided by the task scheduling platform at project startup to check the registration status of the executor and tasks. If it is found that some executors or tasks have not been registered, the corresponding registration interface will be automatically called to complete the registration operation. This automated mechanism not only improves the accuracy and efficiency of configuration but also reduces the workload of manual operations.

[0138] 4. Project packaging and release.

[0139] After completing all configuration and management operations, the project then needs to be packaged and released to a set repository (such as a Maven repository or a Nexus repository). Use a build tool (such as Maven or Gradle) to package the project into a deployable format (such as a JAR file or a WAR file) and upload it to the set repository for other team members or the production environment to download and deploy. In this way, the project can be conveniently version-controlled and continuously integrated, improving the efficiency of development and operation and maintenance.

[0140] 5. Project automatic execution.

[0141] After the project is released to the specified repository, the production environment can achieve automatic execution of tasks by downloading and deploying the project package. After the deployment is completed, the system will automatically execute the configuration, query, and registration processes in the automatic registration manager at startup and ensure that all business logics can be completed on time.

[0142] 6. Executor configuration and detection.

[0143] After the project starts successfully, the system will automatically detect the executor configuration of the project. By reading the xxl.job.executor.appname configuration item in the configuration file, the system can determine that the necessary components of the project have been correctly configured. This automatic detection mechanism not only improves the accuracy of the configuration but also reduces the need for manual intervention. If a valid executor configuration is detected, the system will continue with the next step; otherwise, it will prompt the developer to make corresponding configuration corrections.

[0144] 7. Executor registration.

[0145] Once it is confirmed that the executor configuration is correct, the system will call the executor query interface provided by the task scheduling platform to check whether the target executor has been registered in the task scheduling platform. If the query result shows that the target executor has not been registered, the system will automatically call the executor registration interface to register the executor in the task scheduling platform. This can ensure that each executor can be correctly identified and managed, thus laying a foundation for subsequent task scheduling.

[0146] 8. Task scanning and annotation parsing.

[0147] After the executor registration is completed, the system will scan all methods or classes in the project to find tasks with the first annotation information @XxlJob and generate a task list. For each task, the system will further check whether it also has the second annotation information @XxlJobRegisterWithParam. If it has the second annotation information, it will parse the configuration parameters therein. In this way, the system can obtain the detailed configuration information of the tasks, such as task names, Cron expressions, and task processors, to ensure that the tasks can be executed at the correct time and in the correct way.

[0148] 9. Task query and comparison.

[0149] The system will call the task query interface provided by the task scheduling platform to obtain the set of tasks registered by the current executor in the task scheduling platform. Then, it will compare the task list scanned in the project with the set of tasks obtained from the task scheduling platform. If it is found that a certain task exists in the task list in the project but not in the set of tasks in the task scheduling platform, it can be determined that the task has not been registered in the task scheduling platform. This comparison mechanism can help the system identify which tasks need to be further registered and avoid task scheduling failures caused by task omissions.

[0150] 10. Task registration.

[0151] For those target tasks that have not been registered in the task scheduling platform, the system will register them through the task registration interface provided by the task scheduling platform according to their task names and configuration parameters. This step ensures that all newly added tasks can be recognized and managed by the task scheduling platform in a timely manner, thus ensuring the smooth progress of task scheduling. For example, assume that the system discovers that orderProcessingTask has not been registered. Then, it will register it in the task scheduling platform according to the name, Cron expression, and other configuration parameters of this task.

[0152] Figure 2 The flowchart for automatically configuring tasks based on the task scheduling platform is as Figure 2 shown and includes the following steps.

[0153] Step 201: Determine that the project components have been configured through the xxl.job.executor.appname configuration item.

[0154] Step 202: Call the executor query interface to determine whether the target executor has been registered. If so, execute Step 204; if not, execute Step 203.

[0155] Step 203: Call the executor registration interface to register the executor.

[0156] Step 204: Scan the task list with the @XxlJob annotation.

[0157] Step 205: Determine whether the tasks in the task list have the @XxlJobRegisterWithParam annotation. If not, notify the developer to add this annotation; if so, execute Step 206.

[0158] Step 206: Determine whether the tasks in the task list also exist in the task scheduling platform. If they exist, end; if not, execute Step 207 and then end.

[0159] Step 207: Call the task registration interface to register the task.

[0160] Based on the same technical concept, this application provides a device for automatically configuring tasks based on a task scheduling platform, as Figure 3 shown, the device includes:

[0161] A detection module 301, configured to determine that the necessary components of a project have been correctly configured if an actuator configuration of the project is detected after the project in the task scheduling platform is successfully started;

[0162] An actuator registration module 302, configured to register a target actuator in the task scheduling platform if it is queried according to the value of the actuator configuration that the target actuator has not been registered in the task scheduling platform, where the value of the actuator configuration is used to uniquely identify the actuator;

[0163] An analysis module 303, configured to parse the configuration parameters of a target task according to the second annotation information if it is determined that the target task with the first annotation information in the project also has the second annotation information, where the first annotation information is used to mark the task and the second annotation information is used to provide the configuration information of the task;

[0164] A task registration module 304, configured to perform task registration in the task scheduling platform through the task name and configuration parameters of the target task if the target task does not exist in the task set registered by the target actuator in the task scheduling platform.

[0165] Optionally, the detection module 301 is configured to:

[0166] After the project is successfully started, listen for the actuator addition event through the automatic registration manager;

[0167] When the actuator addition event is listened for, scan the configuration files in the project;

[0168] If the configuration file contains the actuator configuration, determine that the necessary components of the project have been correctly configured.

[0169] Optionally, the actuator registration module 302 is configured to:

[0170] Determine the target actuator in the project by using the value of the actuator configuration;

[0171] If it is queried through the preset actuator query interface in the task scheduling platform that the target actuator has not been registered in the task scheduling platform, register the target actuator through the preset actuator registration interface in the task scheduling platform.

[0172] Optionally, the analysis module 303 is configured to:

[0173] Determine the task list with the first annotation information by scanning the methods or classes that mark tasks in the project;

[0174] If the target task in the task list has both the first annotation information and the second annotation information, the configuration parameters of the target task are parsed according to the second annotation information.

[0175] Optionally, the task registration module 304 is used for:

[0176] Call the preset task query interface in the task scheduling platform to query the set of tasks already registered by the target executor in the task scheduling platform;

[0177] Compare the task list scanned in the project with the set of tasks already registered in the task scheduling platform;

[0178] If the target task in the task list does not exist in the task set, it is determined that the target task has not been registered in the task scheduling platform;

[0179] Perform task registration through the preset task registration interface in the task scheduling platform according to the task name and configuration parameters of the target task.

[0180] Optionally, the device is further used for:

[0181] Configure interface information in the task scheduling platform and introduce the call logic of the interface information in the project, where the interface information includes an executor query interface, an executor registration interface, a task query interface, and a task registration interface;

[0182] Add the second annotation information of the task in the project;

[0183] Add an automatic registration manager in the project, where the automatic registration manager inherits the listening interface and is used to listen for events and execute the query and registration processes;

[0184] Package the project and publish it to the set repository.

[0185] As Figure 4 shown, an embodiment of the present application provides an electronic device, including a processor 401, a communication interface 402, a memory 403, and a communication bus 404. Among them, the processor 401, the communication interface 402, and the memory 403 complete mutual communication through the communication bus 404.

[0186] The memory 403 is used to store computer programs.

[0187] In an embodiment of the present application, when the processor 401 is used to execute the program stored on the memory 403, it implements the method for automatically configuring tasks based on the task scheduling platform provided by any of the foregoing method embodiments.

[0188] The embodiments of the present application also provide a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for automatically configuring tasks based on a task scheduling platform provided in any of the foregoing method embodiments are implemented.

[0189] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0190] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the essence of the above technical solution, or the part that contributes to the related technology, can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0191] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" as used herein may also include the plural forms. The terms "comprising", "including", "containing" and "having" are inclusive and thus specify the presence of the stated features, steps, operations, elements and / or components, but do not preclude the presence or addition of one or more other features, steps, operations, elements, components, and / or combinations thereof. The method steps, processes, and operations described herein are not to be construed as necessarily requiring them to be executed in the particular order described or illustrated, unless the execution order is clearly stated. It should also be understood that additional or alternative steps can be used.

[0192] The above are only the specific embodiments of the present application, enabling those skilled in the art to understand or implement the present application. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to these embodiments shown herein, but will be accorded the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A method for automatically configuring tasks based on a task scheduling platform, characterized in that: The method comprises: After the project in the task scheduling platform is successfully started, if the executor configuration of the project is detected, it is determined that the necessary components of the project have been correctly configured; If it is found according to the value of the executor configuration that the target executor has not been registered in the task scheduling platform, registering the target executor in the task scheduling platform, wherein the value of the executor configuration is used to uniquely identify the executor; If it is determined that the target task in the project having the first annotation information also has the second annotation information, then parsing the configuration parameters of the target task according to the second annotation information, wherein the first annotation information is used to mark the task, and the second annotation information is used to provide configuration information of the task; If the target task does not exist in the task set registered by the target executor in the task scheduling platform, register the task in the task scheduling platform according to the task name and configuration parameters of the target task; If it is determined that the target task in the project having the first annotation information also has the second annotation information, parsing the configuration parameters of the target task according to the second annotation information includes: Determine a task list having the first annotation information by scanning the methods or classes marking the tasks in the project; If the target task in the task list has both the first annotation information and the second annotation information, parsing the configuration parameters of the target task according to the second annotation information; Wherein, if the target task does not exist in the task set registered by the target executor in the task scheduling platform, registering the task in the task scheduling platform using the task name and configuration parameters of the target task includes: Calling a preset task query interface in the task scheduling platform to query the task set registered by the target executor in the task scheduling platform; Comparing the task list scanned in the project with the task set registered in the task scheduling platform; If the target task in the task list does not exist in the task set, determining that the target task has not been registered in the task scheduling platform; According to the task name and configuration parameters of the target task, the task is registered through a task registration interface preset in the task scheduling platform.

2. The method according to claim 1, characterized in that After the project in the task scheduling platform is successfully started, if the executor configuration of the project is detected, it is determined that the necessary components of the project have been correctly configured including: After the project in the task scheduling platform is successfully started, the executor adds events by automatically registering the manager; When the executor addition event is monitored, scanning the configuration files in the project; If the configuration file includes the actuator configuration, it is determined that the necessary components of the project are correctly configured.

3. The method according to claim 1, characterized in that If it is found according to the value of the executor configuration that the target executor has not been registered in the task scheduling platform, registering the target executor in the task scheduling platform includes: Determining a target executor in the project using the value of the executor configuration; If it is found through the preset executor query interface in the task scheduling platform that the target executor has not been registered in the task scheduling platform, the target executor is registered through the preset executor registration interface in the task scheduling platform.

4. The method according to claim 1, characterized in that: Before the project in the task scheduling platform is started, the method further includes: Configure interface information in the task scheduling platform, and introduce the calling logic of the interface information in the project, wherein the interface information includes an executor query interface, an executor registration interface, a task query interface, and a task registration interface; second annotation information for adding a task to the project; Add an automatic registration manager to the project, wherein the automatic registration manager inherits the monitoring interface and is used to monitor events and execute query and registration processes; Package the project and publish it to the settings repository.

5. A device for automatically configuring tasks based on a task scheduling platform, characterized in that: The device comprises: A detection module, used for determining that necessary components of the project have been correctly configured if the executor configuration of the project is detected after the project in the task scheduling platform is successfully started; An executor registration module, configured to register the target executor in the task scheduling platform if it is found according to the value of the executor configuration that the target executor has not been registered in the task scheduling platform, wherein the value of the executor configuration is used to uniquely identify the executor; A parsing module, configured to parse the configuration parameters of the target task according to the second annotation information if it is determined that the target task with the first annotation information in the project also has the second annotation information, wherein the first annotation information is used to mark the task and the second annotation information is used to provide configuration information of the task; A task registration module, used for registering the target task in the task scheduling platform by using the task name and configuration parameters of the target task if the target task does not exist in the task set registered by the target executor in the task scheduling platform; Wherein, the parsing module is used for: Determine a task list having the first annotation information by scanning the methods or classes marking the tasks in the project; If the target task in the task list has both the first annotation information and the second annotation information, parsing the configuration parameters of the target task according to the second annotation information; Wherein, the task registration module is used to: Calling a preset task query interface in the task scheduling platform to query the task set registered by the target executor in the task scheduling platform; Comparing the task list scanned in the project with the task set registered in the task scheduling platform; If the target task in the task list does not exist in the task set, determining that the target task has not been registered in the task scheduling platform; According to the task name and configuration parameters of the target task, the task is registered through a task registration interface preset in the task scheduling platform.

6. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-4 when executing a program stored in a memory.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Networked simulation operation supporting system and method

    CN102523104A

  • Websocket-based task progress interaction method and system

    CN114327898A