Event task scheduling method and device, storage medium, and electronic device
By introducing RabbitMQ and a MySQL database into a distributed environment, creating task queues and listening to the execution time of event tasks, and adopting the producer/consumer pattern and data sharding technology, the problems of accurate triggering and resource waste of device scheduled tasks and delayed tasks are solved, improving execution efficiency and server utilization.
Patent Information
- Application Number
- CN202011554016.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-24
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2040-12-24
AI Technical Summary
In a distributed deployment environment, the execution of scheduled and delayed tasks on devices suffers from problems such as untimely execution, duplicate execution, and resource waste. This is especially true when there are multiple scheduling servers and a large number of tasks, where existing technologies struggle to guarantee the accurate triggering and efficient execution of event tasks.
By introducing data middleware such as RabbitMQ and MySQL database, a task queue is created and the execution time of event tasks is monitored. The producer/consumer pattern and data sharding technology are adopted to ensure that delayed tasks are triggered at the accurate time and optimize the distribution of scheduled tasks, avoiding duplicate execution and resource waste.
It enables accurate triggering of delayed and scheduled tasks, improves execution efficiency and increases the utilization of the scheduling server, and solves the problems of untimely event tasks and resource waste.
Smart Images

Figure CN114661433B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of cloud computing, and in particular to a method and device for scheduling event tasks, a storage medium, and an electronic device. Background Art
[0002] In related technologies, in smart home applications, devices are often subjected to some timed or delayed operations, such as turning on a water heater at 8 o'clock every night, or turning on a colored light with a delayed time.
[0003] In related technologies, device scheduled and delayed tasks are typically implemented using Spring Quartz. This submits the time task directly to a scheduling server, which then polls for tasks to be executed and executes them when the time arrives. However, with long polling cycles or a large number of tasks, there's no guarantee that event tasks will be triggered on time. In a distributed deployment environment, the simultaneous submission of the same event task to multiple scheduling servers can lead to duplicate event execution and inaccurate delayed triggering. Even in a distributed deployment, dedicating a single scheduling server to execute tasks can lead to inefficient task execution and waste of server resources.
[0004] Currently, no effective solution has been found for the above-mentioned problems existing in the related technologies. Summary of the Invention
[0005] The embodiments of the present invention provide a method and device for scheduling event tasks, a storage medium, and an electronic device.
[0006] According to one aspect of an embodiment of the present application, a method for scheduling event tasks is provided, comprising: receiving multiple event tasks submitted by a user device, wherein the event tasks are used to indicate delayed or scheduled execution of corresponding target events; creating a task queue in a data middleware based on the multiple event tasks; monitoring the task queue from the data middleware, and scheduling a target device to execute the target event when the execution time of the target event arrives.
[0007] Furthermore, when the event task is a delayed task, creating a task queue in the data middleware based on the multiple event tasks includes: obtaining task messages triggered by the multiple delayed tasks when they are submitted; creating a message queue in the RabbitMQ server based on the task messages, wherein the data middleware includes the RabbitMQ server.
[0008] Furthermore, when the event task is a delayed task, the task queue is monitored from the data middleware, and when the execution time of the target event arrives, the target device is scheduled to execute the target event, including: monitoring the message queue of the delayed task in the data middleware; obtaining multiple task messages from the message queue, and creating a delay queue locally based on the multiple task messages, wherein the delay queue is a blocking queue based on the delay arrival time; monitoring the delay queue, and when the execution time of the first target event of the delayed task arrives, sending a control instruction to execute the first target event to the first target device.
[0009] Furthermore, monitoring the delay queue includes: storing multiple task messages in the delay queue in multiple memory queues of the calling server respectively; creating a monitoring thread for each memory queue, and using the monitoring thread to monitor the corresponding memory queue.
[0010] Furthermore, when the event task is a scheduled task, creating a task queue in the data middleware according to the multiple event tasks includes: obtaining the timing times of the multiple scheduled tasks; creating a scheduled data queue in the MySQL database based on the order of the timing times, wherein the data middleware includes the MySQL database.
[0011] Furthermore, when the event task is a scheduled task, the task queue is monitored from the data middleware, and when the execution time of the target event arrives, the target device is scheduled to execute the target event, including: reading the scheduled data that meets the preset time conditions from the scheduled data queue of the scheduled task of the data middleware, wherein the scheduled data includes multiple scheduled tasks; splitting the scheduled data into multiple data slices, and assigning a scheduling server to each data slice, wherein the scheduling server is used to send a control instruction to the second target device to execute the second target event when the scheduled time of the second target event of the scheduled task is monitored to arrive.
[0012] Furthermore, splitting the timing data into multiple data slices includes: obtaining a server list, wherein the server list includes M scheduling servers, wherein M is an integer greater than 1; splitting the timing data into M data slices based on the device identifier of the scheduling server, wherein each data slice corresponds to a scheduling server.
[0013] According to another aspect of an embodiment of the present application, a scheduling device for event tasks is also provided, including: a receiving module for receiving multiple event tasks submitted by a user device, wherein the event tasks are used to indicate delayed or scheduled execution of corresponding target events; a creation module for creating a task queue in a data middleware based on the multiple event tasks; a scheduling module for monitoring the task queue from the data middleware, and scheduling a target device to execute the target event when the execution time of the target event arrives.
[0014] Furthermore, when the event task is a delayed task, the creation module includes: a first acquisition unit, used to obtain the task messages triggered by the multiple delayed tasks when they are submitted; a first creation unit, used to create a message queue in the RabbitMQ server based on the task message, wherein the data middleware includes the RabbitMQ server.
[0015] Furthermore, when the event task is a delayed task, the scheduling module includes: a monitoring unit for monitoring the message queue of the delayed task in the data middleware; a creation unit for obtaining multiple task messages from the message queue and creating a delayed queue locally based on the multiple task messages, wherein the delayed queue is a blocking queue based on the delayed arrival time; a first scheduling unit for monitoring the delayed queue and sending a control instruction to execute the first target event to the first target device when the execution time of the first target event of the delayed task arrives.
[0016] Furthermore, the first scheduling unit includes: a saving subunit, used to save the multiple task messages in the delay queue in multiple memory queues of the calling server respectively; a monitoring subunit, used to create a monitoring thread for each memory queue, and use the monitoring thread to monitor the corresponding memory queue.
[0017] Furthermore, when the event task is a scheduled task, the creation module includes: a second acquisition unit, used to obtain the scheduled times of the multiple scheduled tasks; a second creation unit, used to create a scheduled data queue in the MySQL database based on the order of the scheduled times, wherein the data middleware includes the MySQL database.
[0018] Furthermore, when the event task is a scheduled task, the scheduling module includes: a reading unit, used to read scheduled data that meets the preset time conditions from the scheduled data queue of the scheduled task of the data middleware, wherein the scheduled data includes multiple scheduled tasks; a second scheduling unit, used to split the scheduled data into multiple data slices, and assign a scheduling server to each data slice, wherein the scheduling server is used to send a control instruction to the second target device to execute the second target event when it monitors that the scheduled time of the second target event of the scheduled task arrives.
[0019] Furthermore, the second scheduling unit includes: an acquisition subunit, used to obtain a server list, wherein the server list includes M scheduling servers, wherein M is an integer greater than 1; a splitting subunit, used to split the timing data into M data slices based on the device identifier of the scheduling server, wherein each data slice corresponds to a scheduling server.
[0020] According to another aspect of an embodiment of the present application, a storage medium is further provided, which includes a stored program, and the above steps are executed when the program is run.
[0021] According to another aspect of an embodiment of the present application, an electronic device is also provided, including 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; wherein: the memory is used to store computer programs; the processor is used to execute the steps in the above method by running the program stored in the memory.
[0022] An embodiment of the present application also provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the steps in the above method.
[0023] Through the present invention, multiple event tasks submitted by user devices are received, and then a task queue is created in the data middleware according to the multiple event tasks. The task queue is monitored from the data middleware, and when the execution time of the target event arrives, the target device is scheduled to execute the target event. By introducing the data middleware, multiple event tasks can be cached and distributed through the data middleware, and a task queue is created, which solves the technical problem of untimely triggering of event tasks in related technologies, improves the execution efficiency of delayed tasks and scheduled tasks, and improves the utilization rate of the scheduling server. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0025] Figure 1 This is a hardware structure block diagram of a server according to an embodiment of the present invention;
[0026] Figure 2 is a flow chart of a method for scheduling event tasks according to an embodiment of the present invention;
[0027] Figure 3 is a monitoring schematic diagram of an embodiment of the present invention;
[0028] Figure 4 is a scheduling flow chart of an embodiment of the present invention;
[0029] Figure 5 is a structural block diagram of a scheduling device for event tasks according to an embodiment of the present invention;
[0030] Figure 6 It is a structural block diagram of an electronic device implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0031] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only embodiments of a part of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work should fall within the scope of protection of this application. It should be noted that, in the absence of conflict, the embodiments in the present application and the features in the embodiments can be combined with each other.
[0032] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0033] Example 1
[0034] The method embodiment provided in the first embodiment of the present application can be executed on a server (such as a network server, cloud server, etc.), a computer, a mobile phone, a tablet or a similar computing device. Taking running on a server as an example, Figure 1This is a hardware structure diagram of a server according to an embodiment of the present invention. Figure 1 As shown, the server may include one or more ( Figure 1 Only one is shown) a processor 102 (the processor 102 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA and other processing devices) and a memory 104 for storing data. Optionally, the server may also include a transmission device 106 and an input / output device 108 for communication functions. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above server. Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.
[0035] The memory 104 can be used to store server programs, for example, software programs and modules of application software, such as a server program corresponding to a scheduling method for an event task in an embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the server program stored in the memory 104, that is, implementing the above-mentioned method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories may be connected to the server via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0036] The transmission device 106 is used to receive or send data via a network. Specific examples of the aforementioned network may include a wireless network provided by the server's communications provider. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0037] In this embodiment, a method for scheduling event tasks is provided. Figure 2 FIG. 1 is a flow chart of a method for scheduling event tasks according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:
[0038] Step S202: receiving multiple event tasks submitted by a user device, wherein the event tasks are used to indicate delayed or scheduled execution of corresponding target events;
[0039] The event tasks in this embodiment include non-real-time tasks such as delayed tasks and scheduled tasks. Delayed tasks execute an event after a certain period of time based on the current time, such as delayed switching or air conditioning. Scheduled tasks execute an event at a certain time in the future, such as timed alarms and scheduled power on / off. After a user device submits an event task to the scheduling server, the server monitors the time and, when the execution time arrives, controls the corresponding target device to execute the event. In one example, a user submits an event task to the server on their mobile phone to turn on a water heater at 6:00 PM. The server monitors the event and, at 6:00 PM, sends a command to the water heater to automatically start the water heater remotely.
[0040] Step S204: creating a task queue in the data middleware according to the multiple event tasks;
[0041] Optional data middleware refers to the use of efficient and reliable messaging mechanisms for data exchange and the integration of distributed systems based on data communication. It is used to cache event tasks between senders and receivers / executors of event tasks and implement asynchronous communication between event task producers and consumers.
[0042] Step S206: monitor the task queue from the data middleware, and when the execution time of the target event arrives, schedule the target device to execute the target event.
[0043] Through the above steps, multiple event tasks submitted by the user device are received, and then a task queue is created in the data middleware according to the multiple event tasks. The task queue is monitored from the data middleware, and when the execution time of the target event arrives, the target device is scheduled to execute the target event. By introducing the data middleware, multiple event tasks can be cached and distributed through the data middleware, and a task queue is created, which solves the technical problem of untimely triggering of event tasks in related technologies, improves the execution efficiency of delayed tasks and scheduled tasks, and improves the utilization rate of the scheduling server.
[0044] This embodiment can be applied to both delayed tasks and scheduled tasks. Real-time tasks with low timeliness requirements can also be implemented using the solution of this embodiment.
[0045] In an application scenario of this embodiment, when the event task is a delayed task, creating a task queue in the data middleware based on multiple event tasks includes: obtaining task messages triggered by multiple delayed tasks when they are submitted; creating a message queue in the RabbitMQ server based on the task messages, wherein the data middleware includes the RabbitMQ server.
[0046] Optionally, when creating a message queue in the RabbitMQ server based on the task message, the message queue may be created in the RabbitMQ server in order based on the triggering time of the task message.
[0047] The task message of this embodiment is a message (Rabbit MQ message) sent to the Rabbit MQ server when the user submits a delayed task. It consists of a method frame, a content header frame, and a message body frame. The method header frame carries the command and the parameters required to execute it (such as the switch and routing key), the content frame contains the basic properties of the message and the size of the message, and the message body frame carries the message content to be sent (event task).
[0048] Optionally, RabbitMQ in this embodiment creates two processes, msg_store_persistent and msg_store_transient, at startup: one for persistent message storage and one for transferring non-persistent data stored in memory to disk when memory is insufficient. These two processes ultimately handle writing and deleting messages from all queues. Messages can be read directly from files opened by the queue itself, or by the msg_store_persistent / msg_store_transient processes.
[0049] In addition to RabbitMQ, the data middleware of this embodiment can also be Apache Kafka, ActiveMQ, RocketMQ, ZeroMQ and other middleware based on different programming languages and architectures.
[0050] In one embodiment of this implementation scenario, when the event task is a delayed task, the task queue is monitored from the data middleware, and when the execution time of the target event arrives, the target device is scheduled to execute the target event, including:
[0051] S11, monitors the message queue of delayed tasks in the data middleware;
[0052] S12, obtaining multiple task messages from the message queue, and creating a delay queue locally based on the multiple task messages, wherein the delay queue is a blocking queue based on the delayed arrival time;
[0053] The delay queue is a blocking queue. The elements in the queue can only be obtained from the delay queue when the time is up.
[0054] S13: monitor the delay queue, and when the execution time of the first target event of the delay task arrives, send a control instruction to execute the first target event to the first target device.
[0055] In one example based on this implementation, monitoring a delay queue includes: storing multiple task messages in the delay queue in multiple memory queues of the calling server; creating a monitoring thread for each memory queue, and using the monitoring thread to monitor the corresponding memory queue, thereby implementing multi-threaded consumption. Each memory queue stores a single task message, or it can store a collection of task messages of the same type, such as a collection of task messages with the same target device identifier or a collection of task messages with the same order ID.
[0056] Figure 3 This is a monitoring diagram of an embodiment of the present invention. Monitoring and scheduling are implemented based on the producer / consumer model. One producer sends three task messages, and another producer sends message n to the middleware. A queue is created in the middleware. Then the same consumer takes messages from the middleware and saves them in multiple memory queues. Each memory queue is assigned a thread to realize multi-threaded consumption of the same scheduling server, thereby achieving accurate triggering of delayed tasks.
[0057] In another application scenario of this embodiment, when the event task is a scheduled task, creating a task queue in the data middleware based on multiple event tasks includes: obtaining the timing times of multiple scheduled tasks; creating a scheduled data queue in the MySQL database based on the order of the timing times, wherein the data middleware includes the MySQL database.
[0058] In one embodiment of this implementation scenario, when the event task is a scheduled task, the task queue is monitored from the data middleware, and when the execution time of the target event arrives, the target device is scheduled to execute the target event, including:
[0059] S21, reading timing data that meets a preset time condition from a timing data queue of a timing task of a data middleware, wherein the timing data includes a plurality of timing tasks;
[0060] Optionally, the preset time condition may be that the scheduled arrival time is less than a first preset duration, the submission time of the scheduled task is greater than a second preset duration, etc.
[0061] S22: Split the scheduled data into multiple data slices and assign a scheduling server to each data slice. The scheduling server is configured to send a control instruction to the second target device to execute the second target event when the scheduled time of the second target event of the scheduled task is detected. Different scheduling servers can be assigned to the data slices in a random or round-robin manner.
[0062] In a network environment such as a distributed server deployment, scheduled tasks are guaranteed to be triggered only once and will not cause scheduled events to be executed repeatedly.
[0063] In an example of this embodiment, splitting the timing data into multiple data slices includes: obtaining a server list, wherein the server list includes M scheduling servers, wherein M is an integer greater than 1; splitting the timing data into M data slices based on the device identifier of the scheduling server, wherein each data slice corresponds to a scheduling server.
[0064] Data sharding can improve the utilization of server resources, while ensuring that each server executes different sharded data, making full use of server resources, and thus improving the execution efficiency of scheduled tasks.
[0065] Figure 4 This is a scheduling flow chart of an embodiment of the present invention, such as Figure 4 As shown, it includes two parts: delayed task and scheduled task.
[0066] On the one hand, when scheduling a device delay task, the process includes:
[0067] The user submits a device delay task and sends a message to the Rabbit MQ server to create a message queue;
[0068] The scheduled task service monitors the Rabbit MQ message queue;
[0069] Put the acquired message into the locally created delay queue (DelayQueue). The delay queue is a blocking queue. The elements in the queue can only be obtained from the delay queue when the time is up.
[0070] Get the content in the queue and execute the device timing command according to the information in the queue.
[0071] On the other hand, when scheduling device scheduled tasks, the process includes:
[0072] The user submits a device timing task to the device timing microservice, and the device timing microservice stores the data in MySQL;
[0073] The device timing microservice starts a thread to monitor the device timing task and obtains the device timing data that meets the conditions from the database according to the current time;
[0074] Get the server list registered in Zookeeper and shard the data for scheduled tasks based on the obtained server list;
[0075] According to the sharded data and the machine information obtained from the server, the server's pending execution methods are scheduled by polling or random means, and then the scheduled tasks are executed.
[0076] Data sharding can improve the utilization of server resources and ensure that each server executes different sharded data, thereby improving execution efficiency.
[0077] This embodiment implements the solution to accurately trigger device delayed tasks. This is achieved using a Rabbit MQ message delay queue and a producer / consumer model for event triggering. During scheduled task execution, the machine is dynamically retrieved to determine which node to call to execute the scheduled task, ensuring it is executed only once. Data sharding can address issues such as inefficient scheduled task execution and wasted machine resources, solving the problem of inefficient and duplicate scheduled execution for large numbers of devices.
[0078] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0079] Example 2
[0080] In this embodiment, a scheduling device for event tasks is also provided to implement the above-mentioned embodiments and preferred implementations. Details that have already been described will not be repeated. As used below, the term "module" may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.
[0081] Figure 5 is a structural block diagram of a scheduling device for event tasks according to an embodiment of the present invention, such as Figure 5 As shown, the device includes: a receiving module 50, a creating module 52, and a scheduling module 54, wherein:
[0082] A receiving module 50 is configured to receive multiple event tasks submitted by a user device, wherein the event tasks are used to indicate a delayed or scheduled execution of a corresponding target event;
[0083] A creation module 52, configured to create a task queue in the data middleware according to the plurality of event tasks;
[0084] The scheduling module 54 is configured to monitor the task queue from the data middleware and schedule the target device to execute the target event when the execution time of the target event arrives.
[0085] Optionally, when the event task is a delayed task, the creation module includes: a first acquisition unit, used to obtain the task messages triggered by the multiple delayed tasks when they are submitted; a first creation unit, used to create a message queue in the RabbitMQ server based on the task message, wherein the data middleware includes the RabbitMQ server.
[0086] Optionally, when the event task is a delayed task, the scheduling module includes: a monitoring unit for monitoring the message queue of the delayed task in the data middleware; a creation unit for obtaining multiple task messages from the message queue and creating a delayed queue locally based on the multiple task messages, wherein the delayed queue is a blocking queue based on the delayed arrival time; a first scheduling unit for monitoring the delayed queue and sending a control instruction to execute the first target event to the first target device when the execution time of the first target event of the delayed task arrives.
[0087] Optionally, the first scheduling unit includes: a saving subunit, used to save the multiple task messages in the delay queue in multiple memory queues of the calling server respectively; a listening subunit, used to create a listening thread for each memory queue, and use the listening thread to listen to the corresponding memory queue.
[0088] Optionally, when the event task is a scheduled task, the creation module includes: a second acquisition unit, used to obtain the scheduled times of the multiple scheduled tasks; a second creation unit, used to create a scheduled data queue in the MySQL database based on the order of the scheduled times, wherein the data middleware includes the MySQL database.
[0089] Optionally, when the event task is a scheduled task, the scheduling module includes: a reading unit, used to read scheduled data that meets preset time conditions from the scheduled data queue of the scheduled task of the data middleware, wherein the scheduled data includes multiple scheduled tasks; a second scheduling unit, used to split the scheduled data into multiple data slices, and assign a scheduling server to each data slice, wherein the scheduling server is used to send a control instruction to execute the second target event to the second target device when it monitors that the scheduled time of the second target event of the scheduled task arrives.
[0090] Optionally, the second scheduling unit includes: an acquisition subunit, used to obtain a server list, wherein the server list includes M scheduling servers, wherein M is an integer greater than 1; a splitting subunit, used to split the timing data into M data slices based on the device identifier of the scheduling server, wherein each data slice corresponds to a scheduling server.
[0091] It should be noted that the above modules can be implemented through software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0092] Example 3
[0093] An embodiment of the present invention further provides a storage medium storing a computer program, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0094] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:
[0095] S1, receiving multiple event tasks submitted by a user device, wherein the event tasks are used to indicate delayed or scheduled execution of corresponding target events;
[0096] S2, creating a task queue in the data middleware according to the multiple event tasks;
[0097] S3: Monitor the task queue from the data middleware, and when the execution time of the target event arrives, schedule the target device to execute the target event.
[0098] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.
[0099] An embodiment of the present invention further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0100] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0101] Optionally, in this embodiment, the processor may be configured to execute the following steps through a computer program:
[0102] S1, receiving multiple event tasks submitted by a user device, wherein the event tasks are used to indicate delayed or scheduled execution of corresponding target events;
[0103] S2, creating a task queue in the data middleware according to the multiple event tasks;
[0104] S3: Monitor the task queue from the data middleware, and when the execution time of the target event arrives, schedule the target device to execute the target event.
[0105] Optionally, specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0106] Figure 6 is a structural diagram of an electronic device according to an embodiment of the present invention, such as Figure 6 As shown, it includes a processor 61, a communication interface 62, a memory 63 and a communication bus 64, wherein the processor 61, the communication interface 62, and the memory 63 communicate with each other through the communication bus 64, the memory 63 is used to store computer programs; the processor 61 is used to execute the programs stored in the memory 63.
[0107] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0108] In the above embodiments of the present application, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0109] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0110] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0111] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0112] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0113] The above is only a preferred embodiment of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for scheduling event tasks, characterized in that: include: Receiving multiple event tasks submitted by a user device, wherein the event tasks are used to indicate delayed or scheduled execution of corresponding target events; Creating a task queue in the data middleware according to the multiple event tasks; Monitor the task queue from the data middleware, and when the execution time of the target event arrives, schedule the target device to execute the target event; When the event task is a delayed task, monitoring the task queue from the data middleware and scheduling the target device to execute the target event when the execution time of the target event arrives includes: Monitoring the message queue of the delayed task in the data middleware; obtaining multiple task messages from the message queue, and creating a delay queue locally based on the multiple task messages, wherein the delay queue is a blocking queue based on the delay arrival time; monitoring the delay queue, and sending a control instruction to execute the first target event to the first target device when the execution time of the first target event of the delayed task arrives; The method of monitoring the delay queue includes: storing the plurality of task messages in the delay queue in a plurality of memory queues of the calling server, each memory queue storing a task message or a set of task messages of the same type; creating a monitoring thread for each memory queue, and using the monitoring thread to monitor the corresponding memory queue; The data middleware is a RabbitMQ server, which creates a msg_store_persistent process and a msg_store_transient process when it is started. The msg_store_persistent process is used to store persistent messages, and the msg_store_transient process is used to transfer non-persistent data stored in the memory to the disk when the memory is insufficient.
2. The method according to claim 1, characterized in that When the event task is a delayed task, creating a task queue in the data middleware according to the multiple event tasks includes: Get the task messages triggered when multiple delayed tasks are submitted; A message queue is created in a RabbitMQ server based on the task message, wherein the data middleware includes the RabbitMQ server.
3. The method according to claim 1, characterized in that When the event task is a scheduled task, creating a task queue in the data middleware according to the multiple event tasks includes: Get the timing of multiple scheduled tasks; A timing data queue is created in a MySQL database based on the order of the timing times, wherein the data middleware includes the MySQL database.
4. The method according to claim 1, wherein When the event task is a scheduled task, the task queue is monitored from the data middleware, and when the execution time of the target event arrives, the target device is scheduled to execute the target event, including: Reading timing data that meets a preset time condition from a timing data queue of the timing task of the data middleware, wherein the timing data includes a plurality of timing tasks; The timing data is split into multiple data slices, and a scheduling server is assigned to each data slice, wherein the scheduling server is used to send a control instruction to the second target device to execute the second target event when the timing time of the second target event of the timing task is detected to arrive.
5. The method according to claim 4, characterized in that Splitting the timing data into multiple data slices includes: Obtain a server list, wherein the server list includes M scheduling servers, where M is an integer greater than 1; The timing data is split into M data slices based on the device identification of the scheduling server, wherein each data slice corresponds to a scheduling server.
6. A scheduling device for event tasks, characterized in that: include: A receiving module, configured to receive a plurality of event tasks submitted by a user device, wherein the event tasks are used to indicate a delayed or scheduled execution of a corresponding target event; A creation module, configured to create a task queue in the data middleware according to the plurality of event tasks; A scheduling module, configured to monitor the task queue from the data middleware and schedule a target device to execute the target event when the execution time of the target event arrives; When the event task is a delayed task, the scheduling module includes: a monitoring unit, configured to monitor a message queue of the delayed task in the data middleware; a creating unit, configured to obtain a plurality of task messages from the message queue and locally create a delayed queue based on the plurality of task messages, wherein the delayed queue is a blocking queue based on a delayed arrival time; a first scheduling unit, configured to monitor the delayed queue and, when the execution time of a first target event of the delayed task arrives, send a control instruction to a first target device to execute the first target event; The first scheduling unit includes: a storage subunit, which is used to store multiple task messages in the delay queue in multiple memory queues of the calling server, each memory queue stores one task message or a set of task messages of the same type; a monitoring subunit, which is used to create a monitoring thread for each memory queue and use the monitoring thread to monitor the corresponding memory queue; The data middleware is a RabbitMQ server, which creates a msg_store_persistent process and a msg_store_transient process when it is started. The msg_store_persistent process is used to store persistent messages, and the msg_store_transient process is used to transfer non-persistent data stored in the memory to the disk when the memory is insufficient.
7. A storage medium, characterized in that: The storage medium includes a stored program, wherein the program executes the method steps of any one of claims 1 to 5 when running.
8. An electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein: The processor, communication interface, and memory communicate with each other via a communication bus; wherein: Memory for storing computer programs; A processor, configured to execute the method steps according to any one of claims 1 to 5 by running a program stored in a memory.
Citation Information
Patent Citations
Message processing method and device, and electronic device
CN108415759A
A message management method with high reliability that supports timed transmission
CN109298957A
Distributed task polling method based on delay queue
CN110262910A
Clustered timed task scheduling system
CN111176812A