Scheduled task execution method, device, and computer equipment

By pre-configuring the scheduled task start time and container switching mechanism through the cluster management system, the problem of long scheduled task start time is solved, efficient and stable scheduled task operation is achieved, and CPU resources are saved.

CN113886049BActive Publication Date: 2025-10-10NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111189186.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-12
Publication Date
2025-10-10
Estimated Expiration
2041-10-12

AI Technical Summary

Technical Problem

On the server side of the Linux operating system, the scheduling container process for scheduled tasks is long, resulting in a long startup time for scheduled tasks, especially consuming a large amount of CPU resources when running at high frequency.

Method used

The cluster management system pre-configures the start time of scheduled tasks. The container automatically runs the scheduled tasks at the preset time and switches to the new container before the task ends, reducing the frequent container scheduling of the cluster management system. The redundant container strategy and version verification mechanism are used to ensure the reliability and consistency of the tasks.

Benefits of technology

It shortens the startup time of scheduled tasks, saves CPU resources, ensures the stable operation of high-frequency scheduled tasks, and avoids excessive resource consumption and task accumulation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113886049B_ABST
    Figure CN113886049B_ABST
Patent Text Reader

Abstract

The application provides a timing task running method and device and computer equipment, and relates to the technical field of computers, and alleviates the technical problem that the starting time of a timing task is long. The method comprises the following steps: receiving a timing task sent by a cluster management system, wherein a preset starting time is configured in the timing task; requesting a server to obtain a first mark, and running the timing task at the preset starting time in the case of receiving the first mark.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method and apparatus for executing a scheduled task, and a computer device. Background Art

[0002] Currently, scheduled tasks are a function that is frequently used by Internet business servers. For example, e-commerce platforms need to process unprocessed orders on a regular basis, and statistical tasks also need to collect data from the previous day at dawn every day.

[0003] On the Linux operating system server, scheduled tasks are usually represented in the form of "*****", where each "*" represents the time at which the scheduled task is to be executed, such as minutes, hours, days of the month, months, and days of the week, which are used to represent time features. If the above scheduled task is represented by "*", it means that the time feature can use any value. For example, "4 5***" means that the scheduled task needs to start at 05:04 every morning, and "*****" means that the scheduled task needs to be executed once every minute.

[0004] However, the current scheduled task and container scheduling process are relatively long, which increases the startup time of the scheduled task. Summary of the Invention

[0005] The purpose of this application is to provide a method, device and computer equipment for running scheduled tasks, which can alleviate the technical problem of long startup time of scheduled tasks by automatically running scheduled tasks at corresponding times through containers.

[0006] In a first aspect, an embodiment of the present application provides a method for executing a scheduled task, the method comprising:

[0007] Receive a first scheduled task sent by the cluster management system, wherein a preset start time is configured in the first scheduled task;

[0008] A first flag is requested from a server, and upon receiving the first flag, the first scheduled task is executed at the preset start time.

[0009] In one possible implementation, the scheduled task execution method further includes:

[0010] When the running time of the first scheduled task reaches a preset duration, the running of the first scheduled task is terminated, and the first mark is released, so that the second container requests a second mark from the server and runs the second scheduled task based on the second mark, wherein the cluster management system creates or calls containers at preset time intervals so that the second container is generated before the running of the scheduled task of the current first container is terminated.

[0011] In a possible implementation, the first scheduled task is further configured with version information and version information of the application to which it belongs, and the step of requesting the server to obtain the first tag includes:

[0012] Submitting a request message to the server to enable the server to identify whether the version of the current first container is consistent with the version information of the first scheduled task; the request message includes the version ID of the current container, the version information corresponding to the first scheduled task, and the version information of the application to which the first scheduled task belongs;

[0013] If they are consistent, the first mark sent by the server is obtained.

[0014] In a possible implementation, the first scheduled task is created and generated by the server in the cluster management system according to preset conditions.

[0015] In one possible implementation, the step of requesting the server to obtain the first mark further includes:

[0016] Request the server to update the first mark at a preset time interval.

[0017] In one possible implementation, the step of requesting the server to update the first mark at a preset time interval includes:

[0018] Submitting the request information to the server, so that the server identifies whether the current version of the first container is consistent with the version information of the first scheduled task;

[0019] If they are consistent, updating the first mark according to the mark issued by the server;

[0020] If they are inconsistent, the first scheduled task is terminated to enable the third container to start running the corresponding scheduled task.

[0021] In one possible implementation, if there is inconsistency, terminating the execution of the first scheduled task so that the third container can start executing the corresponding scheduled task includes:

[0022] If they are inconsistent, the first scheduled task is terminated to enable the third container to start executing the newly configured scheduled task. The third container is a temporary container created by the server in the cluster management system using the newly configured scheduled task as a template.

[0023] In a possible implementation, the step of requesting the server to obtain the first mark further includes:

[0024] If they are inconsistent, the step of requesting the server to obtain the first mark is re-executed at a preset time interval.

[0025] In one possible implementation, upon receiving the first flag, the step of running the first scheduled task at the preset start time includes:

[0026] In case of receiving the first mark, adding the configuration command in the first scheduled task;

[0027] The first scheduled task is run according to the configuration command at the preset start time.

[0028] In a possible implementation, if there is inconsistency, terminating the execution of the first scheduled task so that the third container can start executing the corresponding scheduled task further includes:

[0029] If they are inconsistent, the configuration command added to the first scheduled task is deleted, and the running of the first scheduled task is terminated, so that the third container starts running the corresponding scheduled task.

[0030] In a possible implementation, the step of requesting the server to obtain the first mark further includes:

[0031] Requesting the server to obtain a first tag so that the server determines whether the interval between the update time of the first tag and the preset update time exceeds a threshold; if exceeded, the first tag expires; if not exceeded, determining whether the first tag has been obtained; if not obtained, issuing the first tag.

[0032] In a possible implementation, the step of requesting the server to obtain the first mark further includes:

[0033] A request is made to the server to obtain a first tag, so that the server determines whether the first tag is obtained based on whether the container ID is consistent with the container ID for which the first tag is requested; if they are consistent, the first tag is not obtained, the container ID of the scheduled task is set to the container ID for which the first tag is requested, and the update time of the first tag is set to the current time.

[0034] In a second aspect, a timed task execution device is provided, comprising:

[0035] A receiving module, configured to receive a first scheduled task sent by the cluster management system, wherein a preset start time is configured in the first scheduled task;

[0036] The running module requests a first tag from a server, and runs the first scheduled task at the preset start time when the first tag is received.

[0037] In a third aspect, the embodiments of the present application further provide a computer device, comprising a memory and a processor, the memory stores a computer program which can run on the processor, and the processor implements the method of the first aspect when executing the computer program.

[0038] In a fourth aspect, the embodiments of the present application further provide a computer readable storage medium, which stores computer executable instructions, and the computer executable instructions, when invoked and run by a processor, cause the processor to run the method of the first aspect.

[0039] The embodiments of the present application bring the following beneficial effects:

[0040] The method, device and computer device for running a timing task provided by the embodiments of the present application can alleviate the technical problem of long starting time of a timing task.

[0041] In the present solution, the cluster management system needs to schedule a corresponding container every time a timing task runs, so that the starting and running time of the timing task is long. The container receives a timing task created by the cluster management system, which is configured with a preset starting time, the cluster management system can be pre-configured, and the container automatically runs the timing task according to the preset starting time, thereby shortening the starting and running time of the timing task.

[0042] In order to make the above objectives, characteristics and advantages of the present application more apparent and easy to understand, the following preferred embodiments are described in detail below, and the accompanying drawings are described as follows. BRIEF DESCRIPTION OF DRAWINGS

[0043] In order to more clearly illustrate the specific embodiments of the present application or the technical solutions in the prior art, the following will briefly introduce the drawings needed to be used in the specific embodiments or the prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor on the basis of these drawings.

[0044] Figure 1 A multi-terminal interaction schematic diagram of a conventional timing task running method is shown;

[0045] Figure 2 A timing task running method flowchart provided by the embodiments of the present application is shown;

[0046] Figure 3 A multi-terminal interaction schematic diagram of a timing task running method provided by the embodiments of the present application is shown;

[0047] Figure 4A container switching schematic diagram of a timing task running method provided by an embodiment of the present application is shown in FIG. 1.

[0048] Figure 5 A container switching schematic diagram of another timing task running method provided by an embodiment of the present application is shown in FIG. 2.

[0049] Figure 6 A flowchart of a timing task running method based on a container side provided by an embodiment of the present application is shown in FIG. 3.

[0050] Figure 7 A flowchart of a timing task running method based on a server side provided by an embodiment of the present application is shown in FIG. 4.

[0051] Figure 8 A structure schematic diagram of a timing task running device provided by an embodiment of the present application is shown in FIG. 5.

[0052] Figure 9 A structure schematic diagram of a computer device provided by an embodiment of the present application is shown in FIG. 6. DETAILED DESCRIPTION

[0053] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions of the present application will be described below in detail with reference to the accompanying drawings. Obviously, the described embodiments are only some of the embodiments of the present application, but not all of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.

[0054] The terms “comprising” and “having” and any variations thereof mentioned in the embodiments of the present application are intended to cover the inclusions without limitation. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally further comprises other steps or units not listed, or optionally further comprises other steps or units inherent to the process, method, product or device.

[0055] The distributed cluster management system Kubernetes is used for managing containerized applications on multiple hosts in a cloud platform. The goal of Kubernetes is to make it simple and efficient to deploy containerized applications. A worker program that manages the life cycle of containers is run on each node, which is called kubelet. In simple terms, the main function of the kubelet program is to periodically obtain the desired state of the containers on the node from somewhere, such as what containers to run, the number of replicas to run, how to configure the network or storage, etc., and call the corresponding container platform interface to achieve this state.

[0056] Kubernetes is a relatively popular implementation solution for the timed task, as shown in Figure 1 FIG. 1, the process of running a timed task using Kubernetes is as follows:

[0057] A server for managing the timed task creates a CronJob for the preset scheduled time on the kubernetes. When the scheduled time of the timed task arrives, the CronJob Controller in the kubernetes checks that there is a timed task to be run, creates a Job corresponding to the CronJob, and makes the Scheduler schedule a suitable target server for the Job. The Kubelet program on the target server is responsible for starting a container, and the container directly runs the timed task after being started.

[0058] The container scheduling process of the above timed task has many steps and is relatively complicated. For a timed task that needs to be run frequently, the frequent starting of containers will cause excessive CPU consumption. In actual application, if multiple high-frequency timed tasks need to be run on a host machine, the kubelet program may need to create dozens of containers at the same time, which will cause the CPU resources of the host machine to be very tight, and the resources consumed by the non-business part will be excessive, thereby greatly prolonging the startup time of the timed task.

[0059] Therefore, the embodiments of the present application provide a timed task running method, device and computer equipment, which can alleviate the technical problem of long startup time of the timed task.

[0060] The embodiments of the present application will be further described below with reference to the accompanying drawings.

[0061] Figure 2 A flowchart of a timed task running method provided by the embodiments of the present application is shown. The method is applied to a first container. As shown in Figure 2 the method comprises the following steps.

[0062] In step S110, a first timed task sent by a cluster management system is received, wherein a preset startup time is configured in the first timed task.

[0063] The first container receives the first timed task from the cluster management system, and the first timed task is a task to be run at a predetermined time. The running time is configured in the first timed task, that is, the preset startup time.

[0064] For example, the first container receives a first timed task A, wherein the first timed task A is configured with a preset startup time of 8:00 am, and the first timed task A will be started and run at 8:00 am.

[0065] At step S120, a first token is requested from the server, and in a case where the first token is received, the first scheduled task is run at a preset start time.

[0066] The first token is used to indicate that the request sent by the first container to the server is verified. The first token is a credential for the container to run the first scheduled task. The hot container needs to apply for the first token from the server Master successfully before running the first scheduled task. The first container runs the first scheduled task after obtaining the first token.

[0067] It should be noted that if the first token is not obtained successfully at this time, the container may be in a start state, but the corresponding scheduled task is not run. The server Master is a server for managing scheduled tasks, and is responsible for creating a scheduled task CronJob in a cluster management system Kubernetes and issuing a first token to a container. The running mode of the embodiment of the application is based on the scheduled task function module of the cluster management system, but is also applicable to service frameworks with similar functions.

[0068] In a preferred embodiment in actual application, the container receives a scheduled task created by the cluster management system and configured with a preset start time. The cluster management system can be preconfigured, and the container automatically runs the scheduled task according to the preset start time, so that the cluster management system does not need to schedule the corresponding container every time the scheduled task is run, so that the container can run the scheduled task, and the problem that the start running time of the scheduled task is long is solved.

[0069] The above steps are described in detail below.

[0070] In some embodiments, the scheduled task can be created in advance, so that the corresponding container has received the corresponding scheduled task before the task starts running. The step of scheduling the container is completed before the task starts running, so that the start time of the scheduled task is short. As an example, the scheduled task can be generated by the server in the cluster management system according to a preset condition. The preset condition can include reaching a specific time interval or a specific time point.

[0071] It should be noted that the pre-started container saves the process of cluster management system scheduling and creating a container when running the timing task, and the start process is shortened to the timing task crond process in the container directly running the command to execute the timing task. Since this kind of timing task CronJob can automatically run at a preset time, the frequency of creating a container by the cluster management system is changed from possibly creating one every two minutes or even every minute to creating one every hour, and the creation and scheduling can be performed in advance, so that the cluster management system does not need to create a large number of containers with high frequency, thereby achieving the purpose of saving resources, and solving the problem of excessive consumption of server resources when a large number of high-frequency timing tasks are running.

[0072] In some embodiments, the cluster management system calls or creates a container every preset time interval and sends a timing task to the container. If the preset time interval is 1 hour, according to the foregoing embodiment, the cluster management system can call the first container at 7 o'clock and send the first timing task configured with the task start time of the first container to the first container. When the preset time interval of 1 hour is reached, that is, at 8 o'clock, the cluster management system creates or calls the second container and sends the second timing task configured with the task start time of the second container to the second container, to specifically realize the purpose of reducing the frequency of creating a container by the cluster management system and saving resources.

[0073] In some embodiments, the first container will automatically terminate its operation after a period of time (for example, at 8:05 after one hour and five minutes), and the newly started hot container will continue to run the next stage of the timing task, so as to avoid excessive accumulation of cache or files caused by long-term operation of a single container for multiple timing tasks. The container can be switched by redundancy to ensure that only one container runs at the same time for the same timing task. As an example, the foregoing embodiment can further include the following steps:

[0074] Step 1.1), when the running time of the first timing task reaches the preset time length, the running of the first timing task is terminated, and the first marker is released, so that the second container requests the second marker from the server and runs the second timing task based on the second marker, wherein the cluster management system creates or calls a container according to a preset time interval, so that the second container is generated before the termination of the timing task of the current first container.

[0075] It should be noted that when switching containers, the embodiments of the present application adopt a redundant operation strategy, and the second container of the next stage is started in advance (e.g., 5 minutes in advance, at 8 o'clock) before the first container of the current stage terminates operation. That is, the second container of the next stage is created or invoked by the cluster management system before the first container task of the current stage terminates, and the created or invoked second container continuously requests the server to obtain the second token according to a preset time interval until success. It can be understood that the preset time interval of the container is shorter than the preset time length of each current container running task, and the preset time interval and the preset time length can be set by the cluster management system and the server, respectively.

[0076] Since the second container needs to obtain the second token from the server before starting the crond process, the second container of the next stage will not start the crond process to run the timing task immediately after starting, but will wait for the first container of the current stage to release the first token before starting the crond process to start running the timing task, as shown in Figure 4 , thereby ensuring that only one container runs at the same time for the same timing task.

[0077] In some embodiments, the first timing task can also be configured with version information and application version information, so that the server can identify based on the above-mentioned version information to ensure the accuracy of the token distribution. As an example, the step of requesting the server to obtain the first token in step S120 can include the following steps:

[0078] Step 2.1), submit request information to the server to identify whether the version of the current first container is consistent with the version information of the first timing task; the request information includes the version ID of the current container, the version information corresponding to the first timing task, and the application version information to which the first timing task belongs.

[0079] Step 2.2), if consistent, obtain the first token distributed by the server.

[0080] Step 2.3), if inconsistent, re-execute the step of requesting the server to obtain the first token according to a preset time interval.

[0081] In order to ensure that the running container will terminate in advance, in addition to the current container id, the container will carry the version of the application and the version information of the first timing task when obtaining / updating the first token, and the server will ensure that the version of the container applying for the first token is consistent with the version of the first timing task before distributing the first token.

[0082] As an optional embodiment, at the same time, the corresponding container can be selected to run the timing task for different service applications, such as, for different application A and application B in the corresponding service platform, the application A corresponding to the single-point container A runs the timing task A, and the application B corresponding to the single-point container B runs the timing task B.

[0083] It can be understood that the implementation of the above scheme can be that the server creates the timing task A and the timing task B in the cluster management system to run once every period of time (such as every hour), so that the container A and the container B can run the corresponding timing task at the corresponding preset time to meet the demand of the corresponding service platform.

[0084] Based on the above steps 2.1)-2.3), the first mark can be updated according to the preset time or frequency, so that when the first mark cannot be updated in time, the running of the timing task is stopped, and the reliability of the running of the timing task is ensured. As an example, the step of requesting the server to obtain the first mark in the above step S120 can further include the following steps:

[0085] Step 3.1), requesting the server to update the first mark according to the preset time interval.

[0086] Exemplarily, as shown in Figure 3 After the server creates a new timing task, the server creates a timing task in the cluster management system to run once every period of time (such as every hour), and the timing task starts the container according to the preset time interval. In the container, the first mark is requested from the server before the timing task cron process is started to run the timing task in the container. When the container normally runs the timing task, the first mark is updated to the server at a timing (such as every minute) or according to the preset frequency or the preset time interval, so as to ensure that the currently obtained first mark is always valid and the timing task can continue to run.

[0087] In some embodiments, the server can identify the version of the current container and the timing task to determine the condition that the first mark can be updated. As an example, the above step 3.1) can include the following steps:

[0088] Step 3.1.1), submitting the request information to the server, so that the server identifies whether the version of the current first container is consistent with the version information of the current first timing task.

[0089] Step 3.1.2), if consistent, updating the first mark according to the mark issued by the server.

[0090] If the versions are inconsistent, the running of the first timing task is terminated, and the third container is started to run the corresponding timing task. It can be understood that the timing task run by the second container, the third container or other containers has the same information as the first timing task, and the tag acquisition and updating process and the configuration command process are similar, and the running process of the timing task of other containers will not be described here. The embodiments of the application take the first timing task run by the first container as an example for description.

[0091] Based on the above step 3.1), the timing task can be smoothly run and seamlessly connected through the temporary container transition. As an example, the above step 3.1.3) can include the following steps:

[0092] Step 3.1.3.1), if the versions are inconsistent, the running of the timing task is terminated, and the third container is started to execute the newly configured timing task. The third container is a temporary container created by the server in the cluster management system and taking the newly configured timing task as a template.

[0093] As shown in Figure 5 When the version of the application or the version of the timing task changes, the first container currently running will fail to update the first tag, and thus the running of the current container will be terminated in advance. The server will start a temporary container to run the timing task of the new version. When the second container of the next stage is started by the timing task command of the cluster management system, it will wait for the running of the temporary container to end before successfully acquiring the second tag and starting the timing task process to run the timing task.

[0094] Each timing task can belong to an application, and each timing task has its own version configuration. If the version of the application or the version of the timing task changes, the first container currently running the timing task cannot run the timing task with the outdated version, and the second container of the next stage can not be started at this time, and a temporary container needs to be started to execute the timing task of the new version.

[0095] In order to ensure that the running container will terminate running in advance, when the container acquires / updates the first tag, in addition to the current container id in the request information, the version of the application and the version of the timing task are also carried, so that the server ensures that the version of the first container applying for the first tag is consistent with the version of the timing task before the first tag is released.

[0096] It should be noted that the creation process of the temporary container can include: when the version of the application or the version of the timing task changes, the server needs to update the configuration change of the timing task CronJob in the cluster management system; after the timing task configuration is updated to the new version number, the server creates a temporary container in the cluster management system and taking the newly configured CronJob as a template.

[0097] In some embodiments, the timing task can be run based on the configuration command in the timing task, so that when the configuration changes, the corresponding latest changed timing task can be run. As an example, the step of running the timing task at the preset start time in the case of receiving the first mark in step S120 described above can include:

[0098] Step 4.1), in the case of receiving the first mark, adding the configuration command in the timing task.

[0099] Step 4.2), running the timing task according to the configuration command at the preset start time.

[0100] In the foregoing embodiments, on the basis of steps 4.1)-4.2) described above, step 3.1.3) described above further includes: if the inconsistency exists, deleting the added configuration command in the timing task, and terminating the running of the timing task, so that the third container starts to run the corresponding timing task.

[0101] Wherein, after the timing task of the container is started, the login process updates the first mark to the server every minute to ensure that the current container has the permission to run the corresponding timing task, and if the login process fails to update the first mark, or the current container has reached the preset closing time, the container enters the termination process.

[0102] In the termination process, if the container is terminated due to reaching the preset closing time, the login process actively releases the first mark to the server, and if it is terminated due to failure to update the first mark, this operation can be skipped. When the container is terminated, the login process first deletes the previously added timing task configuration, and after the timing task configuration is deleted, the timing task process will not run new timing tasks. Then the login process waits for the running of the unfinished timing task in the current container to end, and after all the timing tasks in the container are run or run out of time, the container is truly terminated.

[0103] In some embodiments, the life cycle of the container after starting is as follows Figure 6As shown, after the login init process of the container is started, it will first apply for the first tag from the server; if the application fails because the first tag is occupied by other containers, it will retry multiple times after a period of time (such as every minute) until the container is closed due to timeout; if the application fails due to a mismatch between the application version and the container version, the container will be terminated; after obtaining the first tag of the scheduled task to which the container belongs, the login process of the container will start the scheduled task crond process and add the configuration command of the scheduled task. Thereafter, the scheduled task process will run the scheduled task according to the configuration command. Determine whether the container has reached the preset shutdown time. If so, release the first tag to the server, delete the configuration command added to the scheduled task, wait for the unfinished scheduled task to finish running, and terminate the container; if not, obtain the first tag from the server for update. If the update is successful, update again at the preset time interval. If the update fails, delete the configuration command added to the scheduled task, wait for the unfinished scheduled task to finish running, and terminate the container.

[0104] The configuration command of the scheduled task is written into the environment variables in the scheduled task configuration when the server creates the scheduled task in the cluster management system. When the cluster management system starts the container, the scheduled task configuration is injected into the container through the container environment variables, and the container login process obtains the scheduled task configuration from the environment variables.

[0105] In some embodiments, the server may determine whether to issue a tag based on the following points to make the scheduled tasks of the container more reliable. As an example, the step of requesting the server to obtain the first tag in the above step S120 also includes:

[0106] Step 5.1) Request the server to obtain the first tag, so that the server determines whether the interval between the update time of the first tag and the preset update time exceeds the threshold; if exceeded, the first tag expires; if not exceeded, determine whether the first tag has been obtained; if not obtained, issue the first tag.

[0107] Based on the above step 5.1), as an example, the step of requesting the server to obtain the first mark in the above step S120 further includes the following steps:

[0108] In step 6.1), a request is made to the server to obtain the first tag, so that the server determines whether the first tag is obtained based on whether the container ID is consistent with the container ID for which the first tag is requested; if they are consistent, the first tag is not obtained, and the container ID of the scheduled task is set to the container ID for which the first tag is requested, and the update time of the first tag is set to the current time.

[0109] The process of the server processing the container obtaining the first tag request is as follows: Figure 7 As shown:

[0110] The server stores the application version of all timing tasks, the timing task version, the current container id obtaining the first mark, and the update time of the current first mark. The last two can determine whether the current timing task has obtained the container with the unexpired first mark.

[0111] When the container requests to obtain the first mark, it carries the version information of the timing task, the application version information, and the current container id. The server first judges whether the timing task version and the application version are consistent after receiving the request. If they are not consistent, it directly returns a failure.

[0112] If the versions are consistent, it first judges whether the first mark of the current timing task has been obtained. The judgment method is whether the server stores the container id obtaining the first mark, and whether the update time of the first mark is unexpired (such as the update time > current time-5 minutes). If the first mark of the current timing task has been obtained, the server judges whether the container id corresponding to the first mark is consistent with the requested container id. If it is consistent, it sets the update time of the first mark as the current time and returns a success result. Otherwise, it returns a failure result.

[0113] If the first mark of the current timing task has not been obtained, the server directly sets the container id of the timing task as the requested container id, sets the update time of the first mark as the current time, and returns a success result.

[0114] Figure 8 A structural schematic diagram of a timing task running device is provided. The device can be applied to a first container. As shown in Figure 8 The timing task running device 800 includes:

[0115] A receiving module 801 is configured to receive a first timing task sent by a cluster management system, wherein the first timing task is configured with a preset start time.

[0116] A running module 802 is configured to request a server to obtain a first mark, and run the first timing task at the preset start time in the case that the first mark is received.

[0117] In some embodiments, the running module 802 is further specifically configured to terminate the running of the first timing task and release the first mark when the running time of the first timing task reaches a preset time length, so that a second container requests a second mark from the server and runs a second timing task based on the second mark, wherein the cluster management system creates or invokes a container at a preset time interval, so that the second container is generated before the termination of the timing task of the current first container.

[0118] In some embodiments, the first timing task is configured with version information and application version information, and the running module 802 is further configured to submit the request information to the server, so that the server identifies whether the version of the current first container is consistent with the version information of the first timing task; the request information comprises the version ID of the current container, the version information corresponding to the first timing task, and the application version information to which the first timing task belongs; if consistent, the first mark issued by the server is obtained.

[0119] In some embodiments, the first timing task is generated by the server according to a preset condition in the cluster management system.

[0120] In some embodiments, the running module 802 is further configured to request the server to update the first mark at a preset time interval.

[0121] In some embodiments, the running module 802 is further configured to submit the request information to the server, so that the server identifies whether the version of the current first container is consistent with the version information of the first timing task; if consistent, the first mark is updated according to the mark issued by the server; if inconsistent, the first timing task is terminated, so that the third container starts to run the corresponding timing task.

[0122] In some embodiments, the running module 802 is further configured to terminate the running of the timing task if inconsistent, so that the third container starts to execute a newly configured timing task, and the third container is a temporary container created by the server in the cluster management system and taking the newly configured timing task as a template.

[0123] In some embodiments, the running module 802 is further configured to re-execute the step of requesting the server to obtain the first mark at a preset time interval if inconsistent.

[0124] In some embodiments, the receiving module 801 is further configured to add the configuration command in the first timing task in the case of receiving the first mark, and run the first timing task according to the configuration command at the preset start time.

[0125] In some embodiments, the running module 802 is further configured to delete the configuration command added in the first timing task and terminate the running of the first timing task if inconsistent, so that the third container starts to run the corresponding timing task.

[0126] In some embodiments, the running module 802 is further specifically configured to request the server to acquire the first mark, so that the server judges whether an interval between an update time of the first mark and a preset update time exceeds a threshold; if yes, the first mark is expired; if no, judges whether the first mark has been acquired; if no, issues the first mark.

[0127] In some embodiments, the running module 802 is further specifically configured to request the server to acquire the first mark, so that the server judges whether the first mark has been acquired according to whether a container ID of the first mark is consistent with a container ID of the container requesting to acquire the first mark; if yes, the first mark has not been acquired, sets the container ID of the timing task as the container ID of the container requesting to acquire the first mark, and sets an update time of the first mark as a current time.

[0128] The timing task running apparatus provided by the embodiments of the present application has the same technical features as the timing task running method provided by the above embodiments, and can solve the same technical problems and achieve the same technical effects.

[0129] As shown in Figure 9 A computer device 900 provided by the embodiments of the present application includes a memory 902, a processor 901 and a bus, the memory 902 stores machine readable instructions executable by the processor 901, when the computer device is running, the processor 901 and the memory 902 communicate through the bus, the processor 901 executes the machine readable instructions to execute the steps of the timing task running method as described above.

[0130] Specifically, the memory 902 and the processor 901 can be general memory and processor, which are not specifically limited here, and when the processor 901 runs the computer program stored in the memory 902, the above method can be executed.

[0131] Corresponding to the above method, the embodiments of the present application further provide a computer readable storage medium, the computer readable storage medium stores computer executable instructions, when the computer executable instructions are called and run by the processor, the computer executable instructions cause the processor to run the steps of the above method.

[0132] The timing task running apparatus provided in the embodiments of the present application can be specific hardware on a device or software or firmware installed on the device, etc. The apparatus provided in the embodiments of the present application has the same implementation principle and technical effects as the foregoing method embodiments, and for brief description, the apparatus embodiment part is not mentioned in the foregoing method embodiment. The skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the foregoing described system, apparatus and unit can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.

[0133] In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus embodiments described above are only schematic. For example, the division of the units is only a logical function division, and there can be another division manner in actual implementation. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed coupling or direct coupling or communication connection between the units can be indirect coupling or communication connection through some communication interfaces, and can be electrical, mechanical or other forms.

[0134] For another example, the flowcharts and block diagrams in the drawings show the possible implementation architecture, function and operation of the apparatus, method and computer program product according to the embodiments of the present application. In this regard, each block in the flowcharts or block diagrams can represent a module, a program segment or a part of code containing one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur in different order from that shown in the drawings. For example, two consecutive blocks can actually be executed substantially in parallel, and sometimes they can be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and the combination of blocks in the block diagrams and / or flowcharts, can be implemented by a dedicated hardware-based system for executing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.

[0135] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e. they can be located in one place or distributed on multiple network units. Some or all of the units can be selected to achieve the purpose of the present embodiment according to actual needs.

[0136] In addition, each of the functional units in the embodiments of the present application can be integrated in one processing unit, or each unit can exist alone physically, or two or more units can be integrated in one unit.

[0137] The functions described above can be implemented in hardware or software, and the aforementioned storage medium can be a computer-readable storage medium. Based on the understanding above, the technical solutions of the present application can be embodied in the form of a software product, and the computer software product can be stored in a storage medium, and include a number of instructions for causing 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 methods described in the various embodiments of the present application. The aforementioned storage medium includes various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0138] It should be noted that: similar reference numerals and letters represent similar items in the following drawings, therefore, once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings, in addition, the terms "first", "second", "third", etc. are only used for distinguishing description, and cannot be understood as indicating or implying relative importance.

[0139] Finally, it should be noted that: the above-described embodiments are merely specific implementations of the present application, and are used to illustrate the technical solutions of the present application, but not to limit the same, the protection scope of the present application is not limited thereto, although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any skilled person in the art can modify or easily think of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed by the present application, or make equivalent replacements to some technical features; and these modifications, changes or replacements do not make the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application. All should be covered in the protection scope of the present application.

Claims

1. A method for running a scheduled task, characterized in that: The method comprises: Starting the container in advance, before the first scheduled task starts running, receiving a first scheduled task sent by the cluster management system, wherein a preset start time is configured in the first scheduled task; the first scheduled task is a task that runs at the preset start time; Requesting a first tag from a server, and automatically running the first scheduled task at the preset start time when the first tag is received; When the running time of the first scheduled task reaches a preset duration, the running of the first scheduled task is terminated, and the first mark is released, so that the second container requests a second mark from the server and runs the second scheduled task based on the second mark, wherein the cluster management system creates or calls containers at preset time intervals so that the second container is generated before the running of the scheduled task of the current first container is terminated.

2. The method according to claim 1, characterized in that The first scheduled task is further configured with version information and version information of the application to which it belongs, and the step of requesting the server to obtain the first tag includes: Submitting a request message to the server so that the server can identify whether the version of the current first container is consistent with the version information of the first scheduled task; the request message includes the version ID of the current container, the version information corresponding to the first scheduled task, and the version information of the application to which the first scheduled task belongs; If they are consistent, the first mark sent by the server is obtained.

3. The method according to claim 1, characterized in that The first scheduled task is created and generated by the server in the cluster management system according to preset conditions.

4. The method according to claim 2, characterized in that The step of requesting the server to obtain the first mark also includes: Request the server to update the first mark at a preset time interval.

5. The method according to claim 4, characterized in that The step of requesting the server to update the first mark at a preset time interval includes: Submitting the request information to the server, so that the server identifies whether the current version of the first container is consistent with the version information of the first scheduled task; If they are consistent, updating the first mark according to the mark issued by the server; If they are inconsistent, the first scheduled task is terminated to enable the third container to start running the corresponding scheduled task.

6. The method according to claim 5, characterized in that If they are inconsistent, the step of terminating the execution of the first scheduled task so that the third container can start executing the corresponding scheduled task includes: If they are inconsistent, the first scheduled task is terminated to enable the third container to start executing the newly configured scheduled task. The third container is a temporary container created by the server in the cluster management system using the newly configured scheduled task as a template.

7. The method according to claim 2, characterized in that The step of requesting the server to obtain the first mark also includes: If they are inconsistent, the step of requesting the server to obtain the first mark is re-executed at a preset time interval.

8. The method according to claim 5, characterized in that In the case of receiving the first mark, the step of running the first scheduled task at the preset start time includes: In case of receiving the first mark, adding the configuration command in the first scheduled task; The first scheduled task is run according to the configuration command at the preset start time.

9. The method according to claim 8, characterized in that If they are inconsistent, terminating the execution of the first scheduled task so that the third container can start executing the corresponding scheduled task also includes: If they are inconsistent, the configuration command added to the first scheduled task is deleted, and the running of the first scheduled task is terminated, so that the third container starts running the corresponding scheduled task.

10. The method according to claim 2, characterized in that The step of requesting the server to obtain the first mark also includes: Requesting the server to obtain a first tag so that the server determines whether the interval between the update time of the first tag and the preset update time exceeds a threshold; if exceeded, the first tag expires; if not exceeded, determining whether the first tag has been obtained; if not obtained, issuing the first tag.

11. The method according to claim 10, characterized in that The step of requesting the server to obtain the first mark also includes: A request is made to the server to obtain a first tag, so that the server determines whether the first tag is obtained based on whether the container ID is consistent with the container ID for which the first tag is requested; if they are consistent, the first tag is not obtained, the container ID of the scheduled task is set to the container ID for which the first tag is requested, and the update time of the first tag is set to the current time.

12. A timed task running device, characterized in that: include: A receiving module, configured to start the container in advance and receive a first scheduled task sent by the cluster management system before the first scheduled task starts running, wherein a preset start time is configured in the first scheduled task; the first scheduled task is a task that runs at the preset start time; The running module requests the server to obtain a first mark, and automatically runs the first scheduled task at the preset start time when the first mark is received; The running module is further specifically configured to terminate the running of the first scheduled task and release the first mark when the running time of the first scheduled task reaches a preset duration, so that the second container requests a second mark from the server and runs the second scheduled task based on the second mark, wherein the cluster management system creates or calls containers at preset time intervals so that the second container is generated before the running of the scheduled task of the current first container is terminated.

13. A computer device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 11 are implemented.

14. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to execute the method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Resource access authorization method

    CN102546648A