Task processing method and device, equipment, medium and product
By scanning preset tags to obtain task parameters, using the agent factory to create and bind job details and triggers, combined with distributed locks, the Quartz framework development complexity and memory scheduling problems are solved, and zero-code development and efficient timing task management are achieved. .
Patent Information
- Application Number
- CN202411237907.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2024-12-31
AI Technical Summary
When developing timing tasks based on the Quartz framework, it is necessary to manually create a large number of business-independent job implementation classes, resulting in complex and inefficient development processes, and memory scheduling has problems such as task loss and repeated scheduling.
Get task parameters by scanning preset tags, calling the agent factory to create job details and triggers, and store them in a persistent storage device. Dynamically schedule tasks and job details and triggers are bound to use distributed locks to avoid the same Repeat dispatch at all times.
It realizes zero-code development, improves development efficiency, avoids task loss and duplicate scheduling problems, supports multi-device deployment, and simplifies the use of the scheduling framework.
Smart Images

Figure CN119225711A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of software technology, and in particular, relates to a task processing method, device, equipment, medium and product. Background Art
[0002] In actual applications, some tasks need to be executed automatically at a scheduled time. The commonly used framework for batch processing of scheduled tasks is Quartz. Quartz is an open source framework implemented in pure Java. It can be run as an independent application or embedded in another independent application.
[0003] When developing based on the Quartz framework, you need to manually create an independent Job class and trigger for each task to be executed for scheduling. That is, you need to write a large number of Job implementation classes that are not related to the business, which makes the development process complicated and inefficient. Summary of the invention
[0004] The embodiments of the present application provide a task processing method, device, equipment, medium and product to simplify the development process and improve development efficiency.
[0005] On the one hand, an embodiment of the present application provides a task processing method, which is applied to a target device, and the method includes:
[0006] Scan the target code to be executed to obtain the preset tags;
[0007] Parsing the preset tag to obtain task parameters; the task parameters include a target class, a target method name, and an execution rule; the target class and the target method name correspond to a target method;
[0008] Calling a pre-established proxy factory to create job details and triggers based on the task parameters; the job details and triggers are stored in a persistent storage device;
[0009] Calling the proxy factory, creating a dynamically scheduled task, and binding the dynamically scheduled task with the job details and the trigger; storing the dynamically scheduled task in the persistent storage device;
[0010] In the case that the dynamic scheduling task is not executed, the calling agent executes the dynamic scheduling task to call the target method according to the execution rule.
[0011] On the other hand, the dynamically scheduled task corresponds to a distributed lock, and the distributed lock is acquired by at most one device at the same time;
[0012] In the case where the dynamic scheduling task is not executed, calling the proxy to execute the dynamic scheduling task to call the target method according to the execution rule includes:
[0013] Obtain the distributed lock corresponding to the dynamically scheduled task;
[0014] In the case where the distributed lock is acquired, the calling agent executes the dynamic scheduling task to call the target method according to the execution rule.
[0015] On the other hand, before calling the pre-established agent factory to create job details and triggers based on the task parameters, the method further includes:
[0016] In the persistent storage device, searching for the job details and the trigger corresponding to the task parameters;
[0017] The call to the pre-established agent factory creates job details and triggers based on the task parameters, including:
[0018] In the case that the job details and the trigger corresponding to the task parameters do not exist in the persistent storage device, a pre-established proxy factory is called to create the job details and the trigger based on the task parameters.
[0019] On the other hand, the execution rule is specifically an execution time rule;
[0020] In the case where the dynamic scheduling task is not executed, calling the proxy to execute the dynamic scheduling task to call the target method according to the execution rule includes:
[0021] The proxy factory is called, and when the execution time rule is met, the trigger is called once to execute the target method once.
[0022] On the other hand, the execution time rule includes: executing the dynamically scheduled task at a preset time interval;
[0023] The calling of the proxy factory, when the execution time rule is met, mobilizing the trigger once to execute the target method once, includes:
[0024] Since the first execution of the dynamic scheduling task, the trigger is activated once every preset time interval to execute the target method once.
[0025] On the other hand, the execution time rule includes: executing the dynamically scheduled task at a preset time point;
[0026] The calling of the proxy factory, when the execution time rule is met, mobilizing the trigger once to execute the target method once, includes:
[0027] When the current moment is the preset time point, the trigger is activated once to execute the target method once.
[0028] On the other hand, before scanning the target code to be executed to obtain the preset tag, the method further includes:
[0029] Monitoring the startup event of the application on the target device;
[0030] The scanning of the target code to be executed to obtain a preset tag includes:
[0031] After the start event occurs, the task loader is started to scan the target code to obtain the preset tag.
[0032] On the other hand, an embodiment of the present application provides a task processing device, which is applied to a target device, and the device includes:
[0033] A scanning module, used for scanning the target code to be executed to obtain a preset tag;
[0034] A parsing module, used for parsing the preset tag to obtain task parameters; the task parameters include a target class, a target method name and an execution rule; the target class and the target method name correspond to a target method;
[0035] A first calling module is used to call a pre-established proxy factory to create job details and triggers based on the task parameters; the job details and triggers are stored in a persistent storage device;
[0036] A second calling module is used to call the proxy factory, create a dynamic scheduling task, and bind the dynamic scheduling task with the job details and the trigger; the dynamic scheduling task is stored in the persistent storage device;
[0037] The third calling module is used to call the proxy to execute the dynamic scheduling task when the dynamic scheduling task is not executed, so as to call the target method according to the execution rule.
[0038] In yet another aspect, an embodiment of the present application provides a task processing device, comprising: a processor and a memory storing computer program instructions;
[0039] When the processor executes the computer program instructions, the processing method for the tasks described above is implemented.
[0040] On the other hand, an embodiment of the present application provides a computer-readable storage medium, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the processing method of the task as described above is implemented.
[0041] On the other hand, an embodiment of the present application provides a computer program product. When instructions in the computer program product are executed by a processor of an electronic device, the electronic device performs the processing method of the task as described above.
[0042] The embodiment of the present application provides a method for processing a task. The user writes the method to be called in advance. During the execution of the task, the code is no longer rewritten for the method, but the corresponding target method is found through the task parameters in the preset tag. The job details (JobDetail) and trigger (Trigger) are created based on the task parameters by calling the proxy factory, and stored in the persistent storage device; then, a dynamic scheduling task bound to JobDetail and Trigger is created, and the target method can be directly called when the dynamic scheduling task is executed. It can be seen that the present application uses the proxy factory to create tasks on behalf of users, and there is no need to manually create Job classes and Triggers, so as to achieve the goal of zero-code development of scheduling tasks by users and improve development efficiency. Compared with memory scheduling, the JobDetail and Trigger of the present application are stored in the persistent storage device, so even if the application hangs, the task will not disappear. In addition, the application may be deployed on multiple devices, so it is limited that the dynamically scheduled task is executed by at most one device at the same time to avoid repeated scheduling of the dynamically scheduled task. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0044] Figure 1 A flowchart of a method for processing a task provided by an embodiment of the present application is shown;
[0045] Figure 2 An architectural diagram of a system for processing tasks provided in an embodiment of the present application;
[0046] Figure 3 A complete flowchart of a task processing method provided in an embodiment of the present application;
[0047] Figure 4 A schematic diagram showing the structure of a task processing device provided in an embodiment of the present application is shown;
[0048] Figure 5 A schematic diagram of the hardware structure of a task processing device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0049] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.
[0050] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "include..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
[0051] When using the Quartz framework alone, the development efficiency is low, and a large number of job implementation classes that are irrelevant to the business need to be written; and its usage is complicated. In addition to creating a job implementation class, it is also necessary to create a JobDetail and Trigger instance, associate the JobDetail with the Trigger, and add it to the scheduler, but the key information is only the scheduling frequency. The default scheduling framework @Schedule in Spring is a memory scheduling, and the task will disappear directly after the instance hangs up, and there is a natural defect of repeated scheduling.
[0052] In order to solve the problems of the traditional solution, the embodiment of the present application provides a task processing method, device, equipment, medium and product. The following first introduces the task processing method provided by the embodiment of the present application, which is applied to the target device. Figure 1 FIG. 1 is a flow chart showing a method for processing a task provided by an embodiment of the present application. Figure 1 As shown, the method includes the following steps: S101 to S105.
[0053] S101: Scan the target code to be executed to obtain a preset tag.
[0054] The tasks involved in the embodiments of the present application are usually scheduled tasks, and the scheduled tasks need to be executed through the scheme proposed in the present application. The embodiments of the present application mainly provide a framework, and users use the framework to write the scheduled tasks to be performed. In actual applications, users who use the products of this solution are usually developers who write code. When writing scheduling tasks, users can first write the methods that need to be called in advance, and then use preset tags to bind the corresponding target methods and the execution rules of the target methods. It is no longer necessary to write complete method codes every time.
[0055] The user defines key task parameters through preset tags, and can use the @ProxyScheduled tag customized in the embodiment of the present application. If the user needs to call the target method, add the corresponding task parameters in the preset tag. Before executing the scheduled task, the target device needs to scan the target code to be executed to obtain the preset tag.
[0056] S102: Analyze the preset tags to obtain task parameters.
[0057] As mentioned in the above steps, users will add corresponding task parameters in the preset tags. Therefore, after obtaining the preset tags, you need to parse the preset tags to obtain the task parameters. Task parameters include target class, target method name, and execution rules; the target class and target method name in the preset tags correspond to a target method, and the execution rules represent the triggering conditions of the target method, such as when or under what circumstances it should be executed.
[0058] S103: Calling a pre-established agent factory to create job details and triggers based on task parameters.
[0059] There is a one-to-one correspondence between the job details JobDetail and the trigger Trigger, that is, each JobDetail object corresponds to a Trigger to trigger the execution of the job. After parsing the preset tags to obtain the task parameters, the proxy factory can be called to create the corresponding JobDetail and Trigger according to the task parameters.
[0060] S104: calling the agent factory, creating a dynamic scheduling task, and binding the dynamic scheduling task with the job details and the trigger.
[0061] The task actually processed is the dynamic scheduling task. The required JobDetail and Trigger have been created above, and then the dynamic scheduling task is bound to the JobDetail and Trigger to obtain the required dynamic scheduling task.
[0062] After creating JobDetail, Trigger and dynamically scheduled tasks, they are all stored in a persistent storage device, so as to avoid the task disappearing directly after the application crashes (for example, if memory scheduling is used, the task will disappear directly after the application crashes). The persistent storage device can be a database.
[0063] S105: When the dynamic scheduling task is not executed, the calling agent executes the dynamic scheduling task to call the target method according to the execution rule.
[0064] In the specific implementation, in order to ensure high availability, corresponding applications can be deployed on multiple devices. The application on each device is regarded as an instance. For example, the internal execution process of the spring default scheduling framework @Schedule is that spring automatically parses tasks and generates task information, and stores the scheduled tasks in the running memory of the instance. When multiple instances are deployed, each instance's running memory stores a task list and a Trigger list. The running memory is a private resource of the instance, which is isolated from each other and cannot be shared between instances. Each instance will schedule the tasks stored in its own internal running memory, which will lead to duplicate scheduling problems.
[0065] In this embodiment, the subject that executes the target code is the target device. Before the target device executes the dynamic scheduling task, this embodiment will first ensure that the dynamic scheduling task is not executed by other devices, thereby ensuring that only one device can execute the dynamic scheduling task at the same time, avoiding the repeated execution of the dynamic scheduling task.
[0066] The embodiment of the present application uses a dynamic proxy (i.e., ProxyJob) to execute dynamic scheduling tasks, which are bound to the above-mentioned JobDetail and Trigger, and JobDetail and Trigger are created by task parameters. The task parameters include the target class, target method name, and execution rules. The target class and target method name correspond to a target method, and the target method can be called according to user needs in combination with the execution rules.
[0067] It can be seen that the embodiment of the present application creates a proxy factory (i.e., ProxyFactory), passes the parsed task parameters to the proxy factory, and the proxy factory automatically creates JobDetail, and the dynamic proxy executes batch tasks, thereby avoiding users from developing code other than business, thereby improving R&D efficiency. In addition, this solution does not intrude on business logic, and does not require any business code to be modified, thereby improving the stability of the system. Users only need to add a tag to achieve automatic task scheduling, achieving the effect of simplifying usage.
[0068] This solution achieves zero-code development and improves R&D efficiency. Users only need to add annotations and do not need to develop code for scheduling, which saves the time for testing and deploying scheduling codes, greatly improving the development efficiency of R&D projects involving scheduling. In addition, the use of the framework is simplified, non-invasive to the business, and the threshold for access to the scheduling framework is lowered. Avoiding changes to the original method achieves the goal of non-invasiveness to the business. There is no threshold for annotation addition operations, and the proxy process is transparent to users, freeing users from the scheduling effect, avoiding the dilemma of users having to spend a lot of time to understand the scheduling principles, and lowering the threshold for access and use of the scheduling framework.
[0069] The embodiment of the present application provides a method for processing a task. The user writes the method to be called in advance. During the execution of the task, the code is no longer rewritten for the method, but the corresponding target method is found through the task parameters in the preset tag. The proxy factory is called to create JobDetail and Trigger based on the task parameters and stored in a persistent storage device; then, a dynamic scheduling task bound to JobDetail and Trigger is created. When executing the dynamic scheduling task, the target method can be called directly. It can be seen that the present application uses the proxy factory to create tasks on behalf of users, and there is no need to manually create Job classes and Triggers, so as to achieve the goal of zero-code development of scheduling tasks by users and improve development efficiency. Compared with memory scheduling, the JobDetail and Trigger of the present application are stored in a persistent storage device, so even if the application hangs, the task will not disappear. In addition, the application may be deployed on multiple devices, so it is limited that the dynamically scheduled task is executed by at most one device at the same time to avoid repeated scheduling of the dynamically scheduled task.
[0070] As mentioned above, only one device can execute a dynamically scheduled task at the same time. To achieve this effect, the embodiment of the present application provides a solution, that is, to set a distributed lock. Each dynamically scheduled task corresponds to a distributed lock, and the distributed lock is acquired by at most one device at the same time. Therefore, when calling the proxy to execute a dynamically scheduled task, it is necessary to first acquire the distributed lock corresponding to the dynamically scheduled task; only when the distributed lock is acquired, the proxy is called to execute the dynamically scheduled task to call the target method according to the execution rules.
[0071] The embodiment of the present application designs a distributed lock to solve the problem of applications of multiple devices repeatedly obtaining dynamically scheduled tasks. Taking a specific task A as an example, when the time point T that meets the conditions is reached, when the application obtains the execution permission of task A, it must first obtain a distributed lock. Once an application obtains the lock, task A can be executed. Other instances cannot obtain the lock because the lock is in an occupied state, that is, the execution permission of task A cannot be obtained, so that the same task A will only be executed once at the same time T, avoiding the problem of repeated scheduling.
[0072] The embodiment of the present application designs a distributed lock, which can only be acquired by one device at the same time, and only the device that acquires the distributed lock can execute the dynamically scheduled task. Through the embodiment of the present application, the problem of repeated execution of tasks is avoided, and the tasks are persisted in the persistent storage device, supporting cluster multi-instance deployment. Because the task-related information is persisted in the persistent storage device, it is decoupled from the application program and deployed. During execution, exclusive permissions are first obtained from the persistent storage device, and other competing instances cannot obtain the execution permission of the task, avoiding the risk of repeated task execution.
[0073] In actual applications, in order to avoid the proxy factory repeatedly generating JobDetail and Trigger, resulting in duplicate data in the persistent storage device, an embodiment of the present application provides a solution. Before creating JobDetail and Trigger, first search for JobDetail and Trigger corresponding to the task parameters in the persistent storage device. If there is no JobDetail and Trigger corresponding to the task parameters in the persistent storage device, call the pre-established proxy factory to create JobDetail and Trigger based on the task parameters.
[0074] That is, the proxy factory determines whether the relevant task already exists in the persistent storage device based on the task parameters. If so, no processing is performed. If not, the corresponding JobDetail and Trigger are generated and stored in the persistent storage device.
[0075] Before creating JobDetail and Trigger, the embodiment of the present application first determines that JobDetail and Trigger corresponding to the task parameters do not exist in the persistent storage device, thereby avoiding repeated creation.
[0076] The specific content of the execution rules is not limited in this application. For example, it can be some triggering events or preset conditions. When the triggering event occurs or the corresponding preset conditions are met, the target method is executed once. In actual application scenarios, it is usually necessary to execute some scheduled tasks. For example, in the online booking cloud supervision platform, a certain hotel needs to change the room price at 3 am.
[0077] Therefore, in this embodiment, the execution rule is specifically an execution time rule; when the dynamically scheduled task is not executed, the proxy is called to execute the dynamically scheduled task to call the target method according to the execution rule, including: calling the proxy factory, and when the execution time rule is met, mobilizing the Trigger once to execute the target method once.
[0078] In the embodiment of the present application, dynamically scheduled tasks are executed according to execution time rules to achieve task timing triggering, thereby realizing some timing task requirements in actual application scenarios.
[0079] In practical applications, there are some tasks that need to be executed at a fixed period, such as timed tasks such as information capture. In the solution provided in this embodiment, the execution time rule includes: executing dynamically scheduled tasks at preset time intervals.
[0080] The proxy factory is called, and when the execution time rules are met, the Trigger is mobilized once to execute the target method once, specifically including: since the first execution of the dynamic scheduling task, the Trigger is mobilized once every preset time interval to execute the target method once.
[0081] In different scenarios, the time interval required for task execution is different. Therefore, the preset time interval can be set according to actual needs.
[0082] The embodiment of the present application executes dynamic scheduling tasks at preset intervals, which can meet the needs of some scheduled tasks that need to be executed regularly in actual scenarios.
[0083] In other scenarios, tasks may need to be executed at a fixed point, so the execution time rule includes: executing dynamically scheduled tasks at a preset time point. Correspondingly, the proxy factory is called, and when the execution time rule is met, the Trigger is called once to execute the target method once, including: when the current moment is the preset time point, the Trigger is called once to execute the target method once.
[0084] For example, if a certain hotel needs to change the room price at three o'clock in the morning, the execution time rule is to execute the target method at the preset time point, and the preset time point is three o'clock in the morning.
[0085] The execution time rule provided in the embodiment of the present application is to execute the dynamically scheduled task on time at a preset time point, thereby meeting the requirements of some scheduled tasks that need to be executed at a fixed point in actual scenarios.
[0086] Before scanning the target code to be executed to obtain the preset tag, the startup event of the application on the target device can be monitored first; after the startup event occurs, the task loader is started to scan the target code to obtain the preset tag, so as to create and execute the task.
[0087] The embodiment of the present application develops a loader that automatically parses loading task parameters when the application is started, thereby realizing automatic task parsing, loading, and execution, avoiding the problem of users manually loading or the need to customize and develop a custom loader.
[0088] The present application embodiment provides a specific system architecture. Figure 2 This is an architecture diagram of a task processing system provided in an embodiment of the present application. Figure 2 As shown, it includes multiple cluster nodes 201 and a persistent storage device 202. One cluster node 201 is a device. Each cluster node 201 is connected to the persistent storage device 202 to store JobDetail, Trigger and dynamic scheduling tasks; each cluster node 201 includes a parameter configuration module, a task loading module, a dynamic proxy factory and a task scheduling execution module to achieve corresponding functions. Multiple cluster nodes 201 form a scheduling cluster, and the offline of a single cluster node 201 does not affect the execution of the dynamic scheduling task. In addition, only one cluster node 201 can obtain the distributed lock of the dynamic scheduling task at the same time, thereby executing the dynamic scheduling task.
[0089] The parameter configuration module enables users to define key task parameters by using preset tags. Users only need to use a custom @ProxyScheduled tag (preset tag) on the target method and indicate the cron expression corresponding to the task parameter (cron = "0*****").
[0090] The @ProxyScheduled tag is a custom tag designed and developed for the embodiment of the present application. Its function is to mark the location of the scheduled target method and the scheduled time point or frequency cron. When the task loader is running, it scans the @ProxyScheduled tag in the code and parses it to obtain key task parameters such as the target class (Class), target method name (orignfun), and execution rules.
[0091] Before creating JobDetail and Trigger, the proxy factory first determines whether the relevant task already exists in the database based on the task parameters. If it does, no processing will be done. If it does not, the relevant JobDetail, Trigger and dynamic scheduling task will be generated and stored in the database, which is separated from the application running the code. All applications access the only task list in the database.
[0092] When users add a custom @ProxyScheduled tag, there is no need to add any additional files or codes, because there is no need to implement the fixed method of the Job interface, which avoids the limitation that the same method in the same class in JAVA cannot be defined repeatedly. Custom @ProxyScheduled tags can be added to one or more methods that need to be scheduled in a Class class.
[0093] The dynamic proxy factory is the core of this system. Due to the design of the proxy factory, the system can automatically create dynamic scheduling tasks to be executed through the proxy factory according to the task parameters configured by the user, freeing users from the coding work that requires manual task creation.
[0094] Figure 3 A complete flow chart of a task processing method provided in an embodiment of the present application. Figure 3 As shown, it includes S301 to S314, among which S306 to S311 are the processing flow of the agent factory.
[0095] S301: Application starts.
[0096] S302: Start the loader.
[0097] S303: Obtain preset tags and task parameters.
[0098] S304: Call the dynamic proxy factory.
[0099] S305: Query the agent in the container.
[0100] S306: Assemble based on the target class and target method name.
[0101] S307: Create job details.
[0102] S308: Configure the job details and store them in the database.
[0103] S309: Create a dynamic trigger.
[0104] S310: Configure triggers and store them in the database.
[0105] S311: Create a dynamic scheduling task and bind the job details and trigger.
[0106] S312: Obtain a task list from the database.
[0107] S313: When the triggering condition is met, the agent takes over to execute the dynamic scheduling task.
[0108] S314: Call the actual target method.
[0109] The main process is that when the system starts, the loader is started. The loader scans the user's configuration tag parameter information, obtains the target Class, target method name orignfun and the execution rules in the cron expression, calls the proxy factory, and fixes the executed Job class name to the ProxyJob class. That is, the execution class of each task generated by this system is the fixed ProxyJob class, and there is no need to generate other classes.
[0110] At the same time, the dynamic proxy factory takes the target Class and target method name orignfun that the user needs to actually execute as ProxyJob parameters, creates a new JobDetail and stores it in the database. Then, based on the execution rules in the parsed cron expression, creates a new trigger Trigger and stores it in the database. Create a dynamic scheduling task, bind the dynamic scheduling task to JobDetail and Trigger, and also store it in the database.
[0111] When the task is executed, the proxy factory is called fixedly and the default execute method is executed. The proxy factory finds the user's targetBean in the container according to the parameter Class in the database when it is created, parses the targetMethod parameter to obtain the name of the target method actually scheduled by the user as orignfun, and calls the user method orignfun through reflection to realize the real timed execution of the logic in the user method. The calling process is transparent to the user, and the creation process is transparent to the user. The user only needs to pay attention to which method and frequency cron are scheduled.
[0112] The main function of the task loading module is to scan the ProxyScheduled tag in the code when the system starts, parse the task parameters set by the user, such as the target Class, target method name orignfun, and execution rules in the cron expression, and call the dynamic proxy factory to trigger the creation of a scheduled task.
[0113] The task scheduling execution module is a task-specific execution module. When the trigger conditions in the cron expression are met, the target method is called, that is, the tasks and parameters that meet the conditions are queried in the database and the related logic is run.
[0114] The persistent storage device 202 is generally a database device for storing task records.
[0115] Here is a specific implementation method. First, the pre-scenario and preparation, the user needs to schedule the orignfun method of method ClassA, and the scheduling frequency is once every 10 minutes. The user only needs to add an annotation to the defined method name to implement zero-code scheduling service.
[0116] Step 1: Start the application, start the task loader, scan the @ProxyScheduled annotation, and parse the Class, originfun, and cron information.
[0117] Specific logic of the loader: Develop a custom @ProxyScheduled tag, the loader implements the onApplicationEvent method of the listener Spring interface ApplicationListener, listens to the ApplicationReadyEvent event, that is, executes the loader when the application is started. Find the business ClassA through the container context ApplicationContext, and further find all methods with ProxyScheduled annotations in ClassA through the metadata management factory SimpleMetadataReaderFactory, collect the name of the target class ClassA, the method name orignfun, and the scheduling frequency cron and store them in the scannedScheansMap database.
[0118] Step 2: Start the proxy factory, create the proxy JobDetail and Trigger through the parsed task parameters, and store them in the database for persistence.
[0119] Next, create JobDetail, traverse the information obtained in the first step, create a proxy JobDetail in the proxy factory, set the JobClass property of JobDetail to the fixed proxy ProxyJob.class, set put("targetBean", ClassA) and put("targetMethod", orignfun) in the JobDetail running parameter collection object JobDataMap, and persist it in the database.
[0120] Then, create a proxy Trigger, set the Trigger frequency through the parsed cron expression and store it in the database.
[0121] Step 3: Create a dynamic scheduling task, bind JobDetail and Trigger, and store it in the database. At the scheduling time, the proxy ProxyJob will execute it at runtime. ProxyJob parses the target class object and target method name in JobDataMap to find out that the business class object to be called is ClassA and the business method is orignfun, and then reflects and calls the method orignfun in ClassA to run the real business orignfun logic.
[0122] The above processes and steps are all through Figure 2 The system realizes development and automatic execution, which is transparent to users. Users only need to add tags to achieve zero-code development and scheduling tasks, thereby improving R&D efficiency. More importantly, users do not need to understand the scheduling principles, and the execution process is transparent to users. Users do not need to care about the intermediate scheduling process and the system calls involved, which lowers the usage threshold and allows them to focus their main energy on business development.
[0123] In order to solve the above technical problems, the embodiment of the present application further provides a task processing device, which is applied to a target device. Figure 4 FIG. 1 is a schematic diagram showing the structure of a task processing device provided in an embodiment of the present application. Figure 4 As shown, the device includes the following modules:
[0124] Scanning module 401, used to scan the target code to be executed to obtain a preset tag;
[0125] The parsing module 402 is used to parse the preset tags to obtain task parameters; the task parameters include a target class, a target method name, and an execution rule; the target class and the target method name correspond to a target method;
[0126] The first calling module 403 is used to call the pre-established proxy factory to create JobDetail and Trigger based on the task parameters; JobDetail and Trigger are both stored in a persistent storage device;
[0127] The second calling module 404 is used to call the proxy factory, create a dynamic scheduling task, and bind the dynamic scheduling task with the JobDetail and the Trigger; the dynamic scheduling task is stored in a persistent storage device;
[0128] The third calling module 405 is used to call the proxy to execute the dynamic scheduling task when the dynamic scheduling task is not executed, so as to call the target method according to the execution rule.
[0129] In some embodiments, a dynamically scheduled task corresponds to a distributed lock, and the distributed lock is acquired by at most one device at the same time;
[0130] The third calling module 405 is specifically used for:
[0131] Get the distributed lock corresponding to the dynamically scheduled task;
[0132] When the distributed lock is acquired, the call proxy performs the dynamic scheduling task to call the target method according to the execution rule.
[0133] In some embodiments, the task processing device further includes: a search module for searching the JobDetail and Trigger corresponding to the task parameters in a persistent storage device before calling a pre-established proxy factory to create the JobDetail and Trigger based on the task parameters;
[0134] The first calling module 403 is specifically used to call a pre-established proxy factory to create a JobDetail and a Trigger based on the task parameters when there are no JobDetail and Trigger corresponding to the task parameters in the persistent storage device.
[0135] In some embodiments, the execution rule is specifically an execution time rule;
[0136] The third calling module 405 is specifically used to call the proxy factory, and when the execution time rule is met, the Trigger is mobilized once to execute the target method once.
[0137] In some embodiments, executing the time rule includes: executing the dynamically scheduled task at a preset time interval;
[0138] The third calling module 405 is specifically used to call the Trigger once every preset time interval since the first execution of the dynamic scheduling task to execute the target method once.
[0139] In some embodiments, executing the time rule includes: executing the dynamically scheduled task at a preset time point;
[0140] The third calling module 405 is specifically used to call a Trigger once to execute a target method when the current moment is a preset time point.
[0141] In some embodiments, the task processing device further includes: a monitoring module, which is used to monitor the startup event of the application on the target device before scanning the target code to be executed to obtain the preset tag;
[0142] The scanning module 401 is specifically used to start the task loader after the start event occurs, so as to scan the target code to obtain the preset tag.
[0143] The device provided in the embodiment of the present application is the same as the method in the above embodiment, so both have the same embodiments and beneficial effects, which will not be repeated here.
[0144] Figure 5 FIG. 1 is a schematic diagram showing the hardware structure of a task processing device provided in an embodiment of the present application. Figure 5As shown, the task processing device may include a processor 501 and a memory 502 storing computer program instructions.
[0145] Specifically, the processor 501 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0146] The memory 502 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 502 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, the memory 502 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 502 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 502 is a non-volatile solid-state memory.
[0147] The memory 502 may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical or other physical / tangible memory storage device. Therefore, generally, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to one aspect of the present disclosure.
[0148] The processor 501 reads and executes computer program instructions stored in the memory 502 to implement any one of the task processing methods in the above embodiments.
[0149] In one example, the task processing device may further include a communication interface 503 and a bus 504. The processor 501, the memory 502, and the communication interface 503 are connected via the bus 504 and communicate with each other.
[0150] The communication interface 503 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0151] The bus 504 includes hardware, software, or both, coupling the components of the processing device of the task to each other. By way of example and not limitation, the bus may include an Accelerate Graphical Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an InfiniBand interconnect, a Low Pin Count (LPC) bus, a Memory bus, a Micro Channel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses or a combination of two or more of these. Where appropriate, the bus 504 may include one or more buses. Although embodiments of the present application describe and illustrate a particular bus, the present application contemplates any suitable bus or interconnect.
[0152] In addition, in combination with the task processing method in the above embodiment, the embodiment of the present application can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when the computer program instructions are executed by the processor, any task processing method in the above embodiment is implemented.
[0153] An embodiment of the present application also provides a computer program product, including a computer program, which, when executed, implements a processing method for any one of the tasks in the above embodiments.
[0154] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0155] The functional blocks shown in the block diagram above can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an ASIC, appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (Erasable ROM, EROM), floppy disks, compact disc read-only memory (Compact Disc Read-Only Memory, CD-ROM), optical discs, hard disks, optical fiber media, radio frequency (Radio Frequency, RF) links, etc. Code segments can be downloaded via computer networks such as the Internet, intranets, etc.
[0156] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0157] The above reference is to the flowchart and / or block diagram of a processing method, device, equipment, medium and product of a task according to an embodiment of the present disclosure, and describes various aspects of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs a specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0158] The above contents are only specific implementation methods of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application.
Claims
1. A task processing method, characterized in that: Applied to a target device, the method comprises: Scan the target code to be executed to obtain the preset tags; Parsing the preset tag to obtain task parameters; the task parameters include a target class, a target method name, and an execution rule; the target class and the target method name correspond to a target method; Calling a pre-established proxy factory to create job details and triggers based on the task parameters; the job details and triggers are stored in a persistent storage device; Calling the proxy factory, creating a dynamically scheduled task, and binding the dynamically scheduled task with the job details and the trigger; storing the dynamically scheduled task in the persistent storage device; In the case that the dynamic scheduling task is not executed, the calling agent executes the dynamic scheduling task to call the target method according to the execution rule.
2. The task processing method according to claim 1, characterized in that: The dynamically scheduled task corresponds to a distributed lock, and the distributed lock is acquired by at most one device at the same time; In the case where the dynamic scheduling task is not executed, calling the proxy to execute the dynamic scheduling task to call the target method according to the execution rule includes: Obtain the distributed lock corresponding to the dynamically scheduled task; In the case where the distributed lock is acquired, the calling agent executes the dynamic scheduling task to call the target method according to the execution rule.
3. The task processing method according to claim 1, characterized in that: Before calling the pre-established agent factory to create job details and triggers based on the task parameters, the method further includes: In the persistent storage device, searching for the job details and the trigger corresponding to the task parameters; The call to the pre-established agent factory creates job details and triggers based on the task parameters, including: In the case that the job details and the trigger corresponding to the task parameters do not exist in the persistent storage device, a pre-established proxy factory is called to create the job details and the trigger based on the task parameters.
4. The task processing method according to claim 1, characterized in that: The execution rule is specifically an execution time rule; In the case where the dynamic scheduling task is not executed, calling the proxy to execute the dynamic scheduling task to call the target method according to the execution rule includes: The proxy factory is called, and when the execution time rule is met, the trigger is called once to execute the target method once.
5. The task processing method according to claim 4, characterized in that: The execution time rule includes: executing the dynamic scheduling task at a preset time interval; The calling of the proxy factory, when the execution time rule is met, mobilizing the trigger once to execute the target method once, includes: Since the first execution of the dynamic scheduling task, the trigger is activated once every preset time interval to execute the target method once.
6. The task processing method according to claim 4, characterized in that: The execution time rule includes: executing the dynamic scheduling task at a preset time point; The calling of the proxy factory, when the execution time rule is met, mobilizing the trigger once to execute the target method once, includes: When the current moment is the preset time point, the trigger is activated once to execute the target method once.
7. The task processing method according to any one of claims 1 to 6, characterized in that: Before scanning the target code to be executed to obtain the preset tag, the method further includes: Monitoring the startup event of the application on the target device; The scanning of the target code to be executed to obtain a preset tag includes: After the start event occurs, the task loader is started to scan the target code to obtain the preset tag.
8. A task processing device, characterized in that: Applied to a target device, the apparatus comprises: A scanning module, used for scanning the target code to be executed to obtain a preset tag; A parsing module, used for parsing the preset tag to obtain task parameters; the task parameters include a target class, a target method name and an execution rule; the target class and the target method name correspond to a target method; A first calling module is used to call a pre-established proxy factory to create job details and triggers based on the task parameters; the job details and triggers are stored in a persistent storage device; A second calling module is used to call the proxy factory, create a dynamic scheduling task, and bind the dynamic scheduling task with the job details and the trigger; the dynamic scheduling task is stored in the persistent storage device; The third calling module is used to call the proxy to execute the dynamic scheduling task when the dynamic scheduling task is not executed, so as to call the target method according to the execution rule.
9. A task processing device, characterized in that: include: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the method for processing the task as claimed in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the method for processing a task as claimed in any one of claims 1 to 7 is implemented.
11. A computer program product, characterized in that When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the task processing method as described in any one of claims 1 to 7.
