Summary of the invention
In view of this, the embodiment of the present invention provides a kind of method for scheduling task and system, list is executed using multiple tasks
The server cluster of member composition carries out the storage and execution of task, to make system that can cope with the situation that high concurrent accesses;In addition,
Appropriate person can be also selected to handle task with lifting system performance in multiple tasks execution unit.
To achieve the above object, according to an aspect of the invention, there is provided a kind of method for scheduling task.
The method for scheduling task of the embodiment of the present invention includes: to hold at least one pending task of user's creation through first
Row unit is sent to cache unit and is stored;Wherein, trigger condition and the execution task institute are contained in each pending task
The mark that need to be serviced;First execution unit is in the multiple tasks execution unit pre-established, and load capacity meets the first default item
The task executing units of part;Whether the trigger condition for monitoring each pending task meets;In the triggering of any pending task
When condition meets, the task is obtained from cache unit using the second execution unit in the multiple task executing units, and
The service of the required by task is called from service rendering units to execute the task.
Optionally, the trigger condition is time trigger condition;The method further includes: it is sent out by pending task
It is sent to after cache unit stored: for each pending task, being touched by the first execution unit according to the time of the task
Clockwork spring part determines its following each triggering moment, and obtained each triggering moment is stored in cache unit;The monitoring
Whether the trigger condition of each pending task meets, and specifically includes: whether monitoring current time is equal to each pending task
Any triggering moment.
Optionally, the service rendering units are as follows: in the multiple clothes for the required by task service that can provide trigger condition satisfaction
Business is provided in unit, and load capacity meets the service rendering units of the second preset condition;Each pending task further comprises
Task status;The method further includes: second execution unit using in the multiple task executing units from
After obtaining the task in cache unit, the task status of the task is changed to lock state;It is held in any pending task
After row failure, which is continuously performed until running succeeded with predetermined period, and is continuously performing the frequency of failure equal to default
It is alerted when threshold value.
Optionally, the multiple task executing units form server cluster;First preset condition are as follows: choose load capacity most
Small task executing units;Second preset condition are as follows: choose the smallest service rendering units of load capacity;In each pending task
It further comprise at least one of following information: task identification, task type, mission mode, alarm mode, service call side
Formula, service call interface name or service call URL;Wherein, service call mode includes that HTTP pulls mode, the push side HTTP
Formula or Socket access mode.
To achieve the above object, according to another aspect of the present invention, a kind of task scheduling system is provided.
The task scheduling system of the embodiment of the present invention can include: task creation unit, for storing user's creation at least
One pending task;Wherein, the mark containing the required by task service of trigger condition and execution in each pending task;Clothes
Business governance unit, in the multiple tasks execution unit pre-established, load capacity to be met to the task of the first preset condition
Execution unit is determined as the first execution unit;And cache unit is sent through the first execution unit by the pending task and is carried out
Storage;Multiple tasks execution unit including the second execution unit, for monitor each pending task trigger condition whether
Meet;Wherein, the second execution unit is used for when monitoring that the trigger condition of any pending task meets, from cache unit
The task is obtained, and calls the service of the required by task from service rendering units to execute the task.
Optionally, the trigger condition is time trigger condition;First execution unit can be further used for: will it is described to
Execution task is sent to after cache unit stored, and determines its future according to the time trigger condition of each pending task
Each triggering moment, and obtained each triggering moment is stored in cache unit;The multiple task executing units can be into
One step is used for: whether monitoring current time is equal to any triggering moment of each pending task.
Optionally, each pending task further comprises task status;Second execution unit can be further used for:
It is described after obtaining the task in cache unit, the task status of the task is changed to lock state;Any pending
After task execution failure, which is continuously performed until running succeeded with predetermined period, and continuously performing frequency of failure etc.
It is alerted when preset threshold.
Optionally, service governance unit can be further used for: can provide the required by task service of trigger condition satisfaction
In multiple service rendering units, the service rendering units that load capacity meets the second preset condition are determined as the second execution unit tune
The corresponding service rendering units of service;The system can further comprise Database Unit, described pending for storing
The triggering moment of task and each pending task.
Optionally, the multiple task executing units form server cluster;First preset condition are as follows: choose load capacity most
Small task executing units;Second preset condition are as follows: choose the smallest service rendering units of load capacity;Each pending task into
One step includes at least one of following information: task identification, task type, mission mode, alarm mode, service call side
Formula, service call interface name or service call URL;Wherein, service call mode includes: the service governance unit interface side of pulling
Formula, service governance unit interface push mode, HTTP pull mode, HTTP push mode or Socket access mode.
To achieve the above object, in accordance with a further aspect of the present invention, a kind of computer readable storage medium is provided.
A kind of computer readable storage medium of the invention, is stored thereon with computer program, described program is by processor
Method for scheduling task provided by the present invention is realized when execution.
According to the technique and scheme of the present invention, one embodiment in foregoing invention has the following advantages that or the utility model has the advantages that leads to
It crosses to establish by server cluster that multiple tasks execution unit forms and stores and execute task, access system can in high concurrent
In the case where keep high reliability and high availability, while situations such as server power failure, network failure can also be coped with;Pass through service
The load balancing of governance unit can select the lesser task executing units of load capacity and service rendering units to handle and appoint
Business, to avoid causing system risk;For the ease for use of lifting system, the task scheduling system of the embodiment of the present invention with clothes
Business supports the general-purpose accessings modes such as http protocol when providing unit interaction;In addition, existing task schedule frame is often because of data
The limitation of library inquiry bottleneck is difficult to largely concurrently obtain mission bit stream, and in response to this problem, the present invention is using database purchase task
While information, using high-performance cache unit store tasks information, thus lifting system performance and user experience.
Further effect possessed by above-mentioned non-usual optional way adds hereinafter in conjunction with specific embodiment
With explanation.
Specific embodiment
Below in conjunction with attached drawing, an exemplary embodiment of the present invention will be described, including the various of the embodiment of the present invention
Details should think them only exemplary to help understanding.Therefore, those of ordinary skill in the art should recognize
It arrives, it can be with various changes and modifications are made to the embodiments described herein, without departing from scope and spirit of the present invention.Together
Sample, for clarity and conciseness, descriptions of well-known functions and structures are omitted from the following description.
It should be pointed out that in the absence of conflict, the technical characteristic in the embodiment of the present invention and embodiment can
To be combined with each other.
Fig. 1 is the key step schematic diagram of middle method for scheduling task according to embodiments of the present invention.
As shown in Figure 1, the method for scheduling task of the embodiment of the present invention can be executed specifically in accordance with the following steps:
Step S101: by user creation at least one pending task through the first execution unit be sent to cache unit into
Row storage;Wherein, the mark containing the required by task service of trigger condition and execution in each pending task;First executes list
Member is in the multiple tasks execution unit pre-established, and load capacity meets the task executing units of the first preset condition.
In this step, task refers to the deliberate action dependent on certain trigger mechanism and some component software.For example,
Document progress, which is automatically saved, when monthly No. 25 credits card are refunded automatically, user issues shutdown command belongs to above-mentioned task.Wherein,
Trigger mechanism can be realized by time trigger condition, action triggers condition etc..For example, " monthly No. 25 " in above-mentioned example are i.e.
For time trigger condition, " user issues shutdown command " is action triggers condition.For time trigger condition, in practical application
In, the time trigger condition of natural language description can be converted to temporal expression by system, and then be calculated according to temporal expression
Following each triggering moment out.Illustratively, temporal expression can (Cron be that the timing under Linux is held for Cron expression formula
Row tool, Linux are a kind of open source operating systems).
In embodiments of the present invention, the task creation unit that can provide a user page end, makes user that can create one herein
A or multiple pending tasks.Generally, each pending task may be configured with multiple-task information, such as task identification,
Task status, trigger condition, the mark for executing the required by task service, task type, mission mode, alarm mode, service are adjusted
With mode, service call interface name or service call uniform resource position mark URL (Uniform Resource Locator)
And task inherent parameters.
Wherein, each task has unique task identification, for other assessment of tasks, often to appoint in concrete application
Business name is referred to as task identification;The option of task status has lock state and non-locking state, wherein task, which is performed, to be in
Lock state is in non-locking state when task is not performed or is released;Trigger condition is used to embody the trigger mechanism of task,
It can be time trigger condition or action triggers condition;The mark of required by task service can be the title of the service, be used for
The service is determined in service invocation procedure;The option of task type has single machine task, distributed task scheduling etc., appoints for characterizing to execute
The main body of business is a server or distributed system;The option of mission mode has and can concurrently execute, can not concurrently execute;It accuses
Police's formula may be selected to be short message alarm or mail alarm, further comprise corresponding transmission short message address or email address;Appoint
Business inherent parameters are parameter informations relevant to specific business.
Particularly, any pending service can also configure service call mode and service call interface name or service is adjusted
Use URL.Specifically, service call mode may be selected to be: HTTP pulls mode, HTTP push mode or socket Socket and visits
Ask mode.Wherein, it is pulled in mode in HTTP, task executing units (will be described hereinafter) call service according to http protocol
There is provided unit (will be described hereinafter) relevant interface to realize service call;In HTTP push mode, service rendering units
Relevant interface according to http protocol access task executing units is to realize service call;In Socket access mode, task
The Internet protocol IP address (Internet Protocol) and port that execution unit is bound by service rendering units Socket
It number is communicated with service rendering units to call service.Obviously, if service call mode is that HTTP pulls mode, task execution list
Member need to obtain the URL of service rendering units;If service call mode is that HTTP pushes mode, service rendering units need to be appointed
The URL of business execution unit;If service call mode is Socket access mode, task executing units need to obtain service and provide list
The IP address and port numbers of first Socket binding.It is appreciated that supporting http protocol that can promote the ease for use of task scheduling system.
In addition, service call mode also may be selected to be: service governance unit interface pulls mode or service governance unit
Interface pushes mode.Both modes all rely on service governance unit.In embodiments of the present invention, service governance unit refers to
It is for realizing the distribution of remote procedure call protocol RPC (Remote Procedure Call Protocol) invocation scheme
Service framework.Generally, service governance unit provides service-oriented architecture (Service Oriented
Architecture) the service resolution of level.In concrete application, service governance unit can be such that service provider and service adjusts
With side's directly interaction to realize service call, also service registration and service call side of the offer registration center for service provider
Service discovery, provide monitoring center for statistical fractals call number and allocating time.
It is a kind of service governance unit framework can be as shown in Figure 2.In Fig. 2, following steps are can be performed in service call process:
Step S201: service container starting loads simultaneously operation service provider.
Step S202: the service oneself provided is registered in service provider starting to registration center.
Step S203: the starting of service call side, the service needed for subscribing to oneself to registration center.
Step S204: registration center returns to the address list of service provider to service call side.If address above mentioned
List has altered, and the address list after change will be pushed to service call side based on long connection by registration center.
Step S205: service call side is based on soft load-balancing algorithm, selects a service to mention from address above mentioned list
Supplier is called.If malloc failure malloc, another service provider of replacement continues to call.
Step S206: service provider and service called side count call number and allocating time, and timing in memory
It is sent to monitoring center.
In practical application, service governance unit provides across programming language calling, data compression, black and white lists, clothes toward contact
The functions such as provider's Dynamic Packet of being engaged in.Illustratively, it is (a kind of to can be Dubbo for the service governance unit in practical application scene
Open source service framework), it is also possible to independently developed service framework with the above function.
Preferably, in embodiments of the present invention, realizing task executing units and service using above-mentioned service governance unit
Service call between unit is provided.In this interactive process, service rendering units are as service provider, task executing units
As service call side, the optional service governance unit interface of service call mode pulls mode or service governance unit interface pushes away
Send mode.It is pulled in mode in service governance unit interface, task executing units actively call service the dedicated of governance unit to connect
Mouth pulling data;In service governance unit interface push mode, service governance unit is based on its special purpose interface to task execution
Unit propelling data.Generally, in above-mentioned service call mode, need to predefine the special purpose interface of service governance unit
Title.
In step s101, task creation unit is after the pending task of storage user's creation, by pending task
It is sent to service governance unit, service governance unit determines suitable task executing units, and sends this for pending task
Task executing units.In the process, task creation unit is provided as service call side, task executing units as service
Side.Particularly, task executing units are the servers for storing, executing task.In embodiments of the present invention, it can be preset
Multiple tasks execution unit forms server cluster to be responsible for the storage of task and specific execution, to make system can be in high concurrent
Situations such as keeping high reliability and high availability in the case where access, while server power failure, network failure can also be coped with.
In concrete application, service governance unit chooses load capacity in multiple tasks execution unit and meets the first preset condition
Person is sent to the first execution unit as the first execution unit, by pending task.Wherein, load capacity can be according to each task
Execution unit current access request processing quantity, service call quantity or central processor CPU (Central
Processing Unit), memory, disk utilization power determine.First preset condition, which can be, " it is minimum to choose load capacity
Task executing units ".In this way, by the above-mentioned load balancing of service governance unit, the present invention can select load capacity
The smallest task executing units store and execute task, to avoid causing system risk.It is understood that first is default
Condition can need flexible setting according to business, however it is not limited to above content.
After receiving pending task, the first execution unit is sent to cache unit and Database Unit carries out
Storage.Preferably, cache unit can be cache server, Database Unit can be database server.In order to improve number
According to readwrite performance, cache unit and Database Unit server cluster can be used to carry out store tasks.Later, the first execution unit
The corresponding temporal expression of time trigger condition of each pending task can be converted to message, issued in message queue, and
The message is consumed after (such as one second) after length when preset shorter, is calculated according to the temporal expression in the message wait hold
Each triggering moment in row task future, and obtained triggering moment is stored in cache unit and Database Unit.Specific
In application scenarios, cache unit and Database Unit can store each triggering moment and its corresponding according to chronological order
Mission bit stream, this facilitates the accuracy for promoting execution task.It is appreciated that realizing task triggering moment using message queue
Asynchronous computing can be with lifting system response performance and user experience.
Step S102: whether the trigger condition of each pending task of monitoring meets;In the triggering of any pending task
When condition meets, the task is obtained from cache unit using the second execution unit in multiple tasks execution unit, and from clothes
Business provides in unit and calls the service of the required by task to execute the task.
In this step, when whether task executing units monitoring current time is equal to any triggering of each pending task
It carves.When the triggering moment for monitoring a certain task reaches, all task executing units can be attempted to pull from cache unit
The task, pulling successful task executing units at first is the second execution unit.In general, the second execution unit can be
Above-mentioned first execution unit.After second execution unit pulls the task, its task status is changed to lock state, is thus avoided
The task is repeated by other task executing units.It is understood that before the second execution unit change task status, it should
The task status of task is non-locking state.
After second execution unit pulls Mission Success, the service of the required by task can be called from service rendering units
To execute the task.Obviously, the second execution unit can determine required service according to the service identifiers configured in task.Actually answer
In, there are multiple service rendering units that can provide respective service can therefrom choose more appropriate for lifting system performance
Service rendering units come call service.Based on above-mentioned consideration, load capacity is chosen using service governance unit and meets second in advance
If the service rendering units of condition.Wherein, the second preset condition can be configured according to application environment, such as be set as " choosing negative
The smallest service rendering units of carrying capacity ".In this way, the load balancing that the present invention can be provided by service governance unit, is realized
The Rational choice of service rendering units, to avoid causing system risk.
In addition, as a preferred embodiment, the second execution unit, can be by after any pending task execution failure
Continuously perform the task until running succeeded according to predetermined period, and when continuously performing the frequency of failure equal to preset threshold according to
The alarm mode of configuration is alerted.By above-mentioned setting, it can be ensured that system will not omit each pending task.In addition, being
The accuracy for guaranteeing task execution sequence realizes the clock mechanisms of high-precision, High Availabitity in task executing units, can be with milli
Second is the triggering moment that unit monitors task.
Fig. 3 is the specific execution step schematic diagram of middle method for scheduling task according to a first embodiment of the present invention.Such as Fig. 3 institute
Show, steps are as follows for the specific execution of method for scheduling task:
Step S301: task creation unit stores the pending task of user's creation.
Step S302: pending task is sent service governance unit by task creation unit.
Step S303: service governance unit determines the first execution unit from task executing units.Generally, it first executes
Unit is the wherein the smallest task executing units of load capacity.
Step S304: pending task is sent the first execution unit by service governance unit.
Pending task is sent cache unit by the S305: the first execution unit of step and Database Unit stores.
The S306: the first execution unit of step turns the temporal expression obtained according to the time trigger condition of pending task
It is changed to message.This step can realize the asynchronous computings of task triggering moment.
The S307: the first execution unit of step is by the news release being converted to message queue.
The S308: the first execution unit of step consumes the message from message queue.
The S309: the first execution unit of step calculates each triggering of pending task using the temporal expression in the message
Moment.
Obtained triggering moment is stored in cache unit and Database Unit by the S310: the first execution unit of step.By
Above step completes pending task in the storage of cache unit and Database Unit.
Step S311: task executing units monitor the triggering moment of pending task.
Step S312: task executing units judge whether current time is equal to triggering moment: if so, performing the next step rapid;
Otherwise previous step is returned.
Step S313: when monitoring that triggering moment reaches, the second execution unit obtains corresponding task from cache unit.
Task status is changed to lock state by the S314: the second execution unit of step, is performed a plurality of times to avoid task.
The S315: the second execution unit of step determines suitable service rendering units to call task by servicing governance unit
Required service.Generally, which is the smallest service rendering units of load capacity.
The S316: the second execution unit of step is according to the service execution task of calling, to complete the entire stream of task schedule
Journey.
In the technical solution of the embodiment of the present invention, can establish the server cluster that is made of multiple tasks execution unit Lai
Storage and the task of execution, thus make system that can keep high reliability and high availability in the case where high concurrent accesses, while
Situations such as server power failure, network failure can be coped with.Except, by servicing the load balancing of governance unit, can select
The lesser task executing units of load capacity and service rendering units handle task, to avoid causing system risk.
It should be noted that for the various method embodiments described above, for ease of description, being stated that a series of dynamic
It combines, but those skilled in the art should understand that, the present invention is not limited by the sequence of acts described, certain steps
In fact it can be carried out using other sequences or be carried out simultaneously.In addition, those skilled in the art should also know that, in specification
Described embodiment belongs to preferred embodiment, and related actions and modules not necessarily realizes that institute of the invention is necessary
's.
For the above scheme convenient for the better implementation embodiment of the present invention, phase for implementing the above scheme is also provided below
Relationship system.
It please refers to shown in Fig. 3, a kind of task scheduling system 400 provided in an embodiment of the present invention may include: task creation
Unit 401, service governance unit 402, the server cluster 407 being made of multiple tasks execution unit 403,404,405,406,
Cache unit 408 and Database Unit 409.It is appreciated that four task executing units in server cluster 407 are only to show
, can according to need setting in practical application has the server cluster of task executing units of various quantity.
Specifically, task creation unit 401 can be used for storing at least one pending task of user's creation;Wherein, often
Mark containing the required by task service of trigger condition and execution in one pending task.
Service governance unit 402 can be used in the multiple tasks execution unit pre-established, and load capacity is met first
The task executing units of preset condition are determined as the first execution unit;And the pending task is sent through the first execution unit
It is stored to cache unit 408.
Multiple tasks execution unit 403,404,405,406, for monitor each pending task trigger condition whether
Meet;Wherein, the second execution unit is used for when monitoring that the trigger condition of any pending task meets, from cache unit
The task is obtained in 408, and calls the service of the required by task from service rendering units 410 to execute the task.
As a preferred embodiment, the trigger condition is time trigger condition.First execution unit can be further used for:
After sending the pending task to cache unit 408 and being stored, according to the time trigger of each pending task
Condition determines its following each triggering moment, and obtained each triggering moment is stored in cache unit 408.It is the multiple
Task executing units 403,404,405,406 can be further used for: whether monitoring current time is equal to each pending task
Any triggering moment.
Preferably, in embodiments of the present invention, each pending task further comprises task status.Second executes list
Member can be further used for: described after obtaining the task in cache unit 408, the task status of the task be changed to lock
Determine state;After any pending task execution failure, which is continuously performed until running succeeded with predetermined period, and
Alarm when continuously performing the frequency of failure equal to preset threshold.
In concrete application, service governance unit 402 can be further used for: in the required by task that can provide trigger condition satisfaction
In multiple service rendering units of service, the service rendering units 410 that load capacity meets the second preset condition are determined as second
The corresponding service rendering units of service that execution unit calls.Database Unit 409 can be used for storing the pending task and
The triggering moment of each pending task.
In addition, in embodiments of the present invention, the first preset condition are as follows: choose the smallest task executing units of load capacity;The
Two preset conditions are as follows: choose the smallest service rendering units of load capacity;Each pending task further comprises in following information
At least one: task identification, task type, mission mode, alarm mode, service call mode, service call interface name
Or service call URL;Wherein, service call mode includes: that service governance unit interface pulls mode, service governance unit interface
Push mode, HTTP pull mode, HTTP push mode or Socket access mode.
In the technical solution of the embodiment of the present invention, can establish the server cluster that is made of multiple tasks execution unit Lai
Storage and the task of execution, thus make system that can keep high reliability and high availability in the case where high concurrent accesses, while
Situations such as server power failure, network failure can be coped with.Except, by servicing the load balancing of governance unit, can select
The lesser task executing units of load capacity and service rendering units handle task, to avoid causing system risk.
In addition, the computer-readable medium can be above-mentioned implementation the present invention also provides a kind of computer-readable medium
Included in task scheduling system described in example.Above-mentioned computer-readable medium carries one or more program, when
When said one or multiple programs are executed by the equipment, so that the equipment includes: to create user at least the step of execution
One pending task is sent to cache unit through the first execution unit and is stored;Wherein, contain in each pending task
Trigger condition and the mark for executing the required by task service;First execution unit is the multiple tasks execution unit pre-established
In, load capacity meets the task executing units of the first preset condition;Whether the trigger condition for monitoring each pending task meets;
When the trigger condition of any pending task meets, postponed using the second execution unit in the multiple task executing units
The task is obtained in memory cell, and calls the service of the required by task from service rendering units to execute the task.
Above-mentioned specific embodiment, does not constitute a limitation on the scope of protection of the present invention.Those skilled in the art should be bright
It is white, design requirement and other factors are depended on, various modifications, combination, sub-portfolio and substitution can occur.It is any
Made modifications, equivalent substitutions and improvements etc. within the spirit and principles in the present invention, should be included in the scope of the present invention
Within.