Detailed Description
The invention is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting thereof. It should be further noted that, for convenience of description, only some, but not all of the structures related to the present invention are shown in the drawings.
Example 1
Fig. 1 is a schematic diagram of a task scheduling system according to an embodiment of the present invention, where the embodiment is applicable to scheduling and executing task logic of a scheduling task, and the system may be implemented in software and/or hardware, and the system may be configured in a server. The task scheduling system comprises a database 10 and at least one task subsystem 20, wherein each task subsystem 20 is deployed in a cluster server, and each task subsystem 20 respectively comprises a task scheduling module 201, wherein at least one task processing unit for scheduling tasks is registered in the task scheduling module 201, and task processing logic corresponding to the scheduled tasks is registered in the task processing unit;
The task scheduling module 201 is configured to add task information of a scheduled task sent by a service end to a database when a preset trigger logic is detected to be invoked by the service end, and send the read task information of the scheduled task in the database to the task processing unit, so that the task processing unit executes task processing operation based on the task processing logic and outputs generated task processing data, where the preset trigger logic is configured to trigger the task information adding operation of the scheduled task.
Exemplary types of databases 10 include, but are not limited to, hierarchical databases, relational databases, document oriented databases, key value store databases, or column store databases, among others. In one embodiment, database 10 may alternatively be a relational database. Specifically, the relational database may use a two-dimensional table composed of rows and columns to manage data, and uses SQL (Structured Query Language ) to operate on the data, and all the data generated by the task scheduling system provided in this embodiment may be stored in the database.
Wherein, each task subsystem 20 is deployed in a cluster server, and specifically, each task subsystem 20 supports a cluster architecture deployment. Wherein the cluster architecture represents that each task subsystem 20 operates as a cluster node in a respective independent server.
The preset task triggering logic is, for example, a static method related to JobManager (task management) components provided by the task scheduling module 201, and is logic used by the service end when the task scheduling system is exposed. Wherein, jobManager component is responsible for the dispatching and resource management of the whole cluster task, and the static method is a method formed by adding a static keyword before the class method. In one embodiment, optionally, a buried point unit is set for the preset task trigger logic, and whether the preset task trigger logic is invoked is detected through the buried point unit.
The service end may specifically set a trigger logic for scheduling tasks according to its own service requirement, and the trigger logic includes, but is not limited to, time period-based trigger, message notification-based trigger, or instant external condition-based trigger, where the instant external condition may be whether to perform task triggering after interaction with a third party system. When the service end detects that the triggering condition of the scheduling task is met, a preset task triggering logic provided by the task scheduling system is called to add the task information of the scheduling task into a database. When the trigger logic is trigger based on a time period, and the service end adopts a java program based on springboot frames to perform logic development, the trigger logic is set by using a spring timer provided by the java program. Specifically, a timer in the form of an "@ Scheduled" annotation is built based on received time rules defined based on the cron parameter, fixedDelay parameter, or fixedRate parameter.
On the basis of the above embodiment, optionally, the task scheduling module 201 is further configured to, when it is detected that the task subsystem 20 is started, obtain task information of a scheduled task in a task interface on the task scheduling module 201 and an instance bean class of task processing logic encapsulated with the scheduled task in the task scheduling interface, and register the scheduled task in the task processing unit based on the task information and the bean class.
The task interface and the task scheduling interface are interfaces exposed to the service end of the task scheduling system, and in one embodiment, the task interface is an optional IJob interface, and the task scheduling interface is a IJobHandler interface. Based on the above embodiments, the task subsystem 20 is optionally built based on springboot-starter mechanism. The benefit of this is that the task subsystem 20 built based on springboot-starter mechanism automatically registers the task information and bean class at the interface in the task processing unit at start-up. The starter is a settable project provided by springboot application development framework, and for example, a maven project management tool may be used to create a starter project, and after creation, each task subsystem 20 corresponds to a jar package.
On the basis of the embodiment, the task scheduling module 201 is optionally specifically configured to read task information of a scheduled task in a database based on a preset time interval through a single-thread executor service, package the task information of the scheduled task into an executable object and submit the executable object to a multi-thread executor service, and send the executable object to a task processing unit through the multi-thread executor service based on an exclusive mechanism of the database, where the exclusive mechanism of the database is used to control a unique multi-thread executor service in a plurality of task scheduling modules that read the task information of the scheduled task to execute a sending operation of the executable object.
Specifically, the task scheduling module 201 includes 2 executor services (ExecutorService) that serve single-threaded and multi-threaded executors, respectively. The preset time interval may be 1 minute, for example. The executable object (Runnable object) is an executable object of a process (Thread), and specifically, the executable object is sent to the task processing unit by calling a run method of the executable object. Specifically, when the multithreaded executor service receives a plurality of executable objects, each executable object is respectively sent to a task processing unit corresponding to each scheduling task. On the basis of the above-described embodiment, optionally, when the task processing unit completes the task processing operation, the processing state information based on the generated scheduled task is updated in the database 10. Illustratively, the processing state information includes success information, failure information, or exception information.
For example, after the task subsystem a and the task subsystem B both read the scheduling information of the scheduled task 1 in the database and encapsulate the scheduling information into the executable object, the task subsystem a and the task subsystem B claim the task information of the scheduled task 1 in the database, respectively, and if the task subsystem a has claimed the task information of the scheduled task 1, the task subsystem B cannot claim the task information of the scheduled task 1 again by the exclusive mechanism of the database, so that the multithreaded executor service in the task subsystem a sends the executable object corresponding to the scheduled task 1 to the task processing unit corresponding to the scheduled task 1 registered in the task subsystem a.
On the basis of the above embodiment, optionally, the task scheduling module 201 is further configured to, after reading task information of a scheduled task in the database, match the task information of the scheduled task with task information in a task processing unit registered in the task scheduling module 201, and use the task information of the scheduled task that is successfully matched as task information that can be packaged as an executable object.
The types and the numbers of the task processing units registered by the task scheduling module 201 in each task subsystem 20 in the task scheduling system in this embodiment may be the same or different. Specifically, the task processing units that can execute the scheduled task 1 are registered in the task subsystem a, or the task processing units that can execute the scheduled task 2 are registered in the task subsystem B. For example, when the task subsystem a reads the task information of the scheduled task 2, the task subsystem a does not perform the encapsulation operation on the task information of the scheduled task 2 if the task information of the scheduled task 2 is not matched with the task information of the task processing unit registered in the task subsystem.
According to the technical scheme, the preset task trigger scheduling logic is provided for the service end, and a new scheduling task is added when the service end is detected to call the preset task trigger scheduling logic, so that the problem that code development and trigger configuration are required to be executed at the service end and the scheduling center system end respectively when the service end develops the scheduling task is solved, and the development difficulty of a task scheduling system is reduced. Furthermore, the embodiment of the invention adopts the task scheduling system meeting the cluster architecture, and completes the scheduling work of scheduling tasks based on the database, so that the service codes and the operation configuration are managed in a centralized way, the problem of multiple external dependency factors of a scheduling center system in the distributed task scheduling system is solved, and the portability of the task scheduling system is improved.
Example two
Fig. 2 is a schematic diagram of a task scheduling system according to a second embodiment of the present invention, and the technical solution of this embodiment is further refinement based on the foregoing embodiment. Optionally, the task subsystem 20 further includes a statistics analysis module 202, and accordingly, the task scheduling module 201 is further configured to send task processing data to the statistics analysis module 202, where the statistics analysis module 202 is configured to perform asynchronous statistics analysis on the task processing data sent by each task scheduling module 201 and output a generated statistics analysis result, and preset task triggering logic is configured to trigger an adding operation of task information of a scheduled task.
Specifically, in this embodiment, each task subsystem 20 of the task scheduling system includes a statistical analysis module 202, and any statistical analysis module is selected as the statistical analysis module 202 of the task scheduling system, so as to perform asynchronous statistical analysis on the task processing data sent by each task subsystem 20, that is, each task subsystem 20 sends the generated task processing data to the same statistical analysis module 202 in the task scheduling system.
On the basis of the above embodiment, optionally, the task processing logic includes a call operation for calling the data reporting logic, and the task scheduling module 201 is specifically configured to, when detecting that the data reporting logic is called by the task processing logic during the task processing unit executes the task processing operation, send the generated task processing data corresponding to the data reporting logic to the statistical analysis module 202, where the data reporting logic is configured to trigger the statistical analysis module 202 to execute a receiving operation on the task processing data sent by the task processing unit.
The data reporting logic is an exemplary static method related to JobManager components provided by the task scheduling module 201, and is a logic used by the task scheduling system exposed to a service end. In one embodiment, optionally, a buried point unit is set for the data reporting logic, and the buried point unit detects whether the data reporting logic is invoked. The data reporting logic includes data reporting logic for successful data processing, data reporting logic for failed data processing, and data reporting logic for abnormal data processing, for example. Specifically, when the task processing unit performs task processing on the data 1 based on the task processing logic and the processing is successful, the task processing logic invokes the data reporting logic that the data processing is successful, and reports the data that the data 1 is successful, so that the statistical analysis module 202 receives the data that the data 1 is successful.
Based on the above embodiment, the statistical analysis module 202 is specifically configured to encapsulate the received task processing data into an executable object and submit the executable object to the single-threaded executor service in the statistical analysis module 202, and perform an asynchronous storage operation on the executable object using the single-threaded executor service.
Based on the above embodiment, the bean class is optionally further encapsulated with data statistics logic of the scheduled task, and the corresponding statistical analysis module 202 is further configured to register the data statistics logic of the scheduled task in the statistical analysis module 202 based on the bean class, so that the statistical analysis module 202 performs statistical analysis processing on the received task processing data based on the data statistics logic, and outputs the generated statistical analysis result. Specifically, a data statistics logic is constructed in a "@ JobStatistics annotation" form.
On the basis of the embodiment, the statistical analysis result comprises task overview data and/or verification success information, and the corresponding statistical analysis module is specifically used for generating task overview data based on a time window dimension and outputting the task overview data based on the acquired task processing data corresponding to the time window when the data statistics logic comprises the statistics logic based on the time window, and/or acquiring processing state data in the task processing data corresponding to the scheduling task and matching the processing state data with a state verification standard corresponding to the scheduling task when the data statistics logic comprises the statistics logic based on the task dimension, and generating the verification success information of the scheduling task and outputting the verification success information if the matching is successful.
In one embodiment, the time window based statistics logic performs a statistical analysis on a scheduled task basis, and the task summary data includes task processing data for each scheduled task within the time window. For example, the task overview data includes an amount of processing success data and an amount of processing failure data corresponding to the scheduled task 1, and an amount of processing success data and an amount of processing failure data corresponding to the scheduled task 2.
In one embodiment, the statistical logic based on task dimensions performs statistical analysis with a single scheduled task as an object, and the processing state data in the task processing data includes, but is not limited to, processing success data, processing failure data, and processing exception data. Wherein the state check criteria are criteria for characterizing overall state data of the scheduled task. For example, when the scheduling task corresponds to data 1, data 2, and data 3, the state check criteria define that the processing state data corresponding to data 1 and data 2 are successful states, and the processing state data corresponding to data 3 is not limited. And if the processing state data is respectively a data 1 success state, a data 2 success state and a data 3 success state based on the task dimension, the processing state data is matched with the state verification standard, and verification success information is generated. If the processing state data is the successful state of the data 1, the failed state of the data 2 and the successful state of the data 3 respectively, the processing state data is not matched with the state verification standard, and verification failure information is generated.
Fig. 3 is a schematic diagram of a specific example of a task subsystem according to the second embodiment of the present invention. As shown in fig. 3, the task subsystem includes a task scheduling module and a statistical analysis module, wherein the task scheduling module registers the task processing unit 1, the task processing unit 2, the task processing unit 3, and so on. In the process that the task processing unit executes task processing operation based on the task processing logic, the buried point unit detects the calling condition of the task processing unit for calling the data reporting logic, and when the data reporting logic is detected to be called, the statistical analysis module receives task processing data corresponding to the data reporting logic. Among the basic statistical indexes received by the statistical analysis module, the left 3 graphs without gray scales (namely, task creation time, start execution time and task end time) represent the data automatically acquired by the statistical analysis module, and the right 3 graphs with gray scales (namely, expected processing data, successful processing data and task error data) represent the task processing data sent by the task scheduling module and received based on the data reporting logic. The statistical analysis module performs statistical analysis based on the basic statistical indexes, and specifically, the statistical functions include task overview based on a time window (i.e. statistical logic based on a time window) and task dimension task success verification (i.e. statistical logic based on a task dimension). In this embodiment, the statistical analysis module has an analysis output function, and specifically, the service end receives the statistical analysis result by calling the http interface provided by the statistical analysis module, or the statistical analysis module actively sends the statistical analysis result to the service end in a form of mail, etc. The specific output mode of the statistical analysis module is not limited herein.
According to the technical scheme, the statistical analysis module is arranged to carry out statistical analysis on the task processing data sent by the task scheduling module, and the generated statistical analysis result is output, so that the problem of data statistics of the task scheduling system is solved. Furthermore, the task scheduling system of the embodiment solves the problem that the data reporting of the scheduling task needs to be independently set in the scheduling center system of the distributed scheduling system by exposing the data reporting logic to the service end for use, further reduces the workload and the working difficulty of developers, and further improves the portability of the task scheduling system by delivering the data reporting function to the service end for independent development and setting.
It should be noted that, in the embodiment of the task scheduling system, each unit and module included are only divided according to the functional logic, but not limited to the above division, so long as the corresponding functions can be implemented, and the specific names of the functional units are only for convenience of distinguishing each other, and are not used for limiting the protection scope of the present invention.
Example III
Fig. 4 is a flowchart of a task scheduling method according to a third embodiment of the present invention, where the method may be adapted to perform scheduling and execution of task logic of a scheduled task, and the method may be configured in a task scheduling system according to any one of the foregoing embodiments, where the system may be implemented in software and/or hardware, and the system may be configured in a server. The specific implementation steps comprise:
And S310, when the preset trigger logic is detected to be called by the service end, the received task information of the scheduling task sent by the service end is added into a database.
In this embodiment, the preset trigger logic is used to trigger an adding operation of task information of the scheduled task.
In one embodiment, optionally, a buried point unit is set for the preset task trigger logic, and whether the preset task trigger logic is invoked is detected through the buried point unit.
S320, the task information of the scheduling task in the read database is sent to the task processing unit, so that the task processing unit executes task processing operation based on the task processing logic, and the generated task processing data is output.
In one embodiment, optionally, the task information of the scheduling task in the read database is sent to the task processing unit, and the method comprises the steps of reading the task information of the scheduling task in the database based on a preset time interval through a single-thread executor service, packaging the task information of the scheduling task into an executable object and then submitting the executable object to a multi-thread executor service, and sending the executable object to the task processing unit through the multi-thread executor service based on an exclusive mechanism of the database, wherein the exclusive mechanism of the database is used for controlling the unique multi-thread executor service in a plurality of task scheduling modules which read the task information of the scheduling task to execute the sending operation of the executable object.
In one embodiment, optionally, the method further comprises the step of matching task information of the scheduled task with task information in a task processing unit registered in a task scheduling module after the task information of the scheduled task in the database is read, and taking the task information of the scheduled task which is successfully matched as task information which can be packaged into an executable object.
In one embodiment, optionally, the method further comprises acquiring task information of the scheduled task in a task interface on the task scheduling module and an instance bean class of task processing logic packaged with the scheduled task in the task scheduling interface when the start of the task subsystem is detected, and registering the scheduled task in the task processing unit based on the task information and the bean class.
In one embodiment, the method optionally further comprises sending the generated task processing data to a statistical analysis module, so that the statistical analysis module performs asynchronous statistical analysis on the received task processing data sent by each task scheduling module, and outputs the generated statistical analysis result.
In one embodiment, optionally, the task processing logic includes a call operation for calling the data reporting logic, and correspondingly, the task processing logic sends the generated task processing data to the statistical analysis module, where the task processing module sends the generated task processing data corresponding to the data reporting logic to the statistical analysis module when detecting that the data reporting logic is called by the task processing logic in the process of executing the task processing operation by the task processing unit, and the data reporting logic is used for triggering the statistical analysis module to execute a receiving operation on the task processing data sent by the task processing unit.
According to the technical scheme, the preset task trigger scheduling logic is provided for the service end, and a new scheduling task is added when the service end is detected to call the preset task trigger scheduling logic, so that the problem that code development and trigger configuration are required to be executed at the service end and the scheduling center system end respectively when the service end develops the scheduling task is solved, and the workload and development difficulty of developers are reduced. Furthermore, the embodiment of the invention realizes the dispatching work of dispatching tasks based on the database, so that the service codes and the operation configuration are managed in a centralized way, the problem of more external dependence factors of a dispatching center system in the distributed task dispatching system is solved, and the portability of the task dispatching system is improved.
Example IV
Fig. 5 is a schematic structural diagram of an electronic device according to a fourth embodiment of the present invention, where the fourth embodiment of the present invention provides services for implementing the task scheduling method according to the foregoing embodiment of the present invention, and the task scheduling system according to the foregoing embodiment of the present invention may be configured. Fig. 5 shows a block diagram of an exemplary device 12 suitable for use in implementing embodiments of the present invention. The device 12 shown in fig. 5 is merely an example and should not be construed as limiting the functionality and scope of use of embodiments of the present invention.
As shown in fig. 5, device 12 is in the form of a general purpose computing device. The components of device 12 may include, but are not limited to, one or more processors or processing units 16, a system memory 28, and a bus 18 that connects the various system components, including system memory 28 and processing units 16.
Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, and a local bus using any of a variety of bus architectures. By way of example, and not limitation, such architectures include Industry Standard Architecture (ISA) bus, micro channel architecture (MAC) bus, enhanced ISA bus, video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
Device 12 typically includes a variety of computer system readable media. Such media can be any available media that is accessible by device 12 and includes both volatile and nonvolatile media, removable and non-removable media.
The system memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM) 30 and/or cache memory 32. Device 12 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from or write to non-removable, nonvolatile magnetic media (not shown in FIG. 5, commonly referred to as a "hard disk drive"). Although not shown in fig. 5, a magnetic disk drive for reading from and writing to a removable non-volatile magnetic disk (e.g., a "floppy disk"), and an optical disk drive for reading from or writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In such cases, each drive may be coupled to bus 18 through one or more data medium interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to carry out the functions of embodiments of the invention.
A program/utility 40 having a set (at least one) of program modules 42 may be stored in, for example, memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each or some combination of which may include an implementation of a network environment. Program modules 42 generally perform the functions and/or methods of the embodiments described herein.
Device 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), one or more devices that enable a user to interact with device 12, and/or any devices (e.g., network card, modem, etc.) that enable device 12 to communicate with one or more other computing devices. Such communication may occur through an input/output (I/O) interface 22. Also, device 12 may communicate with one or more networks such as a Local Area Network (LAN), a Wide Area Network (WAN) and/or a public network, such as the Internet, via network adapter 20. As shown in fig. 5, network adapter 20 communicates with other modules of device 12 over bus 18. It should be appreciated that although not shown, other hardware and/or software modules may be used in connection with device 12, including, but not limited to, microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, data backup storage systems, and the like.
The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, for example, implementing a task scheduling method provided by an embodiment of the present invention.
Through the electronic equipment, the problem that the service end needs to be executed respectively at the service end and the dispatching center system end when the dispatching task is developed is solved, the workload and the development difficulty of developers are reduced, the problem that the external dependence factors of the dispatching center system in the distributed task dispatching system are more is solved, and the portability of the task dispatching system is improved.
Example five
A fifth embodiment of the present invention also provides a storage medium containing computer-executable instructions, which when executed by a computer processor, are configured to perform a task scheduling method, the method comprising:
When the preset trigger logic is detected to be called by the service end, task information of a scheduling task sent by the service end is added into a database, wherein the preset trigger logic is used for triggering the adding operation of the task information of the scheduling task;
And sending the read task information of the scheduling task in the database to a task processing unit so that the task processing unit executes task processing operation based on task processing logic and outputs the generated task processing data.
The computer storage media of embodiments of the invention may take the form of any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the computer-readable storage medium include an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations of the present invention may be written in one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
Of course, the storage medium containing the computer executable instructions provided in the embodiments of the present invention is not limited to the above method operations, but may also perform the related operations in the task scheduling method provided in any embodiment of the present invention.
Note that the above is only a preferred embodiment of the present invention and the technical principle applied. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, while the invention has been described in connection with the above embodiments, the invention is not limited to the embodiments, but may be embodied in many other equivalent forms without departing from the spirit or scope of the invention, which is set forth in the following claims.