[go: up one dir, main page]

CN116610429A - Processing method and device of delay task, computer equipment and storage medium - Google Patents

Processing method and device of delay task, computer equipment and storage medium Download PDF

Info

Publication number
CN116610429A
CN116610429A CN202310626247.3A CN202310626247A CN116610429A CN 116610429 A CN116610429 A CN 116610429A CN 202310626247 A CN202310626247 A CN 202310626247A CN 116610429 A CN116610429 A CN 116610429A
Authority
CN
China
Prior art keywords
task
delayed
processing
executed
tasks
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310626247.3A
Other languages
Chinese (zh)
Inventor
黄扬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Industrial Bank Co Ltd
CIB Fintech Services Shanghai Co Ltd
Original Assignee
Industrial Bank Co Ltd
CIB Fintech Services Shanghai Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Industrial Bank Co Ltd, CIB Fintech Services Shanghai Co Ltd filed Critical Industrial Bank Co Ltd
Priority to CN202310626247.3A priority Critical patent/CN116610429A/en
Publication of CN116610429A publication Critical patent/CN116610429A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • G06F9/4887Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues involving deadlines, e.g. rate based, periodic
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本申请涉及一种延时任务的处理方法、装置、计算机设备、存储介质和计算机程序产品。所述方法包括:接收延时任务,确定所述延时任务的延时时间单位;在响应于所述延时时间单位为第一级别的情况下,利用消息队列执行对所述延时任务的处理操作,生成所述延时任务的处理结果;在响应于所述延时时间单位为第二级别的情况下,利用定时任务执行对所述延时任务的处理操作,生成所述延时任务的处理结果。采用本方法能够针对不同级别的延时任务灵活采用不同的任务处理方式,从而实现在保障延时任务的延时精确性的同时降低延时任务处理时对数据库的轮询压力。

The present application relates to a processing method, device, computer equipment, storage medium and computer program product for delayed tasks. The method includes: receiving a delayed task, determining a delay time unit of the delayed task; in response to the condition that the delay time unit is the first level, using a message queue to execute the delayed task A processing operation, generating a processing result of the delayed task; in response to the fact that the delayed time unit is the second level, using a timing task to perform a processing operation on the delayed task, and generating the delayed task processing results. By adopting the method, different task processing methods can be flexibly adopted for different levels of delayed tasks, so as to ensure the delay accuracy of the delayed tasks and reduce the polling pressure on the database during the delayed task processing.

Description

延时任务的处理方法、装置、计算机设备、存储介质Processing method, device, computer equipment, and storage medium for delayed tasks

技术领域technical field

本申请涉及任务处理技术领域,特别是涉及一种延时任务的处理方法、装置、计算机设备、存储介质和计算机程序产品。The present application relates to the technical field of task processing, and in particular to a processing method, device, computer equipment, storage medium and computer program product for delayed tasks.

背景技术Background technique

在一些场景下,应用系统中新创建的任务并不需要立即执行。因此,出现了延时任务。目前常用的延时任务处理方式一般是数据库轮询方式:通过将新建的延时任务存储在数据库中定时向数据库发起轮询,以拉取延时完毕待执行任务并加入任务队列中执行。In some scenarios, newly created tasks in the application system do not need to be executed immediately. Therefore, there is a delayed task. At present, the commonly used delayed task processing method is generally the database polling method: by storing the newly created delayed tasks in the database, polling is regularly initiated to the database to pull the delayed tasks to be executed and add them to the task queue for execution.

然而,采用上述数据库轮询方式来处理延时任务时,在应用系统中的数据库轮询任务数量较多的情况下,频繁扫描数据库会对数据库性能造成影响。而采用增加数据库轮询频率的方式来减少数据库轮询任务数量时,又容易导致部分延时任务执行的时间存在比较大的误差。However, when the above-mentioned database polling method is used to process delayed tasks, in the case of a large number of database polling tasks in the application system, frequently scanning the database will affect the performance of the database. However, when the number of database polling tasks is reduced by increasing the database polling frequency, it is easy to cause relatively large errors in the execution time of some delayed tasks.

因此,亟需一种能够兼顾数据库性能和延时任务执行精度的处理方法。Therefore, there is an urgent need for a processing method that can balance database performance and delay task execution accuracy.

发明内容Contents of the invention

基于此,有必要针对上述技术问题,提供一种不影响数据库性能并且延时任务执行精度较高的延时任务的处理方法、装置、计算机设备、计算机可读存储介质和计算机程序产品。Based on this, it is necessary to address the above technical problems and provide a processing method, device, computer equipment, computer readable storage medium and computer program product of a delayed task that does not affect the performance of the database and can perform the delayed task with high precision.

第一方面,本申请提供了一种延时任务的处理方法。所述方法包括:In a first aspect, the present application provides a method for processing delayed tasks. The methods include:

接收延时任务,确定所述延时任务的延时时间单位;receiving a delayed task, and determining the delay time unit of the delayed task;

在响应于所述延时时间单位为第一级别的情况下,利用消息队列执行对所述延时任务的处理操作,生成所述延时任务的处理结果;In response to the case where the delay time unit is the first level, use a message queue to execute a processing operation on the delay task, and generate a processing result of the delay task;

在响应于所述延时时间单位为第二级别的情况下,利用定时任务执行对所述延时任务的处理操作,生成所述延时任务的处理结果。In response to the condition that the delayed time unit is the second level, the timing task is used to execute the processing operation on the delayed task, and a processing result of the delayed task is generated.

在其中一个实施例中,所述利用消息队列执行对所述延时任务的处理操作,生成所述延时任务的处理结果,包括:In one of the embodiments, the processing operation on the delayed task is performed by using the message queue, and the processing result of the delayed task is generated, including:

利用所述消息队列启动拉取线程,采用所述拉取线程查询待执行任务;Use the message queue to start a pull thread, and use the pull thread to query tasks to be executed;

当存在多个所述待执行任务时,根据每个所述待执行任务对应的执行时间进行排序,确定每个所述待执行任务对应的处理顺序;When there are multiple to-be-executed tasks, sort according to the execution time corresponding to each of the to-be-executed tasks, and determine the processing sequence corresponding to each of the to-be-executed tasks;

利用所述拉取线程根据所述处理顺序依次拉取每个所述待执行任务,并根据所述处理顺序依次处理每个所述待执行任务,生成所述处理结果。Each of the to-be-executed tasks is sequentially pulled by the pulling thread according to the processing sequence, and each of the to-be-executed tasks is sequentially processed according to the processing sequence to generate the processing result.

在其中一个实施例中,在所述根据所述处理顺序依次处理每个所述待执行任务,生成所述处理结果之前,还包括:In one of the embodiments, before said sequentially processing each of said to-be-executed tasks according to said processing order and generating said processing result, it further includes:

获取每个所述待执行任务的任务标识;Obtaining a task identifier of each task to be executed;

确定不存在携带同一所述任务标识的已执行记录。It is determined that there is no executed record carrying the same task identifier.

在其中一个实施例中,所述利用所述定时任务执行对所述延时任务的处理操作,生成所述延时任务的处理结果,包括:In one of the embodiments, using the timing task to execute the processing operation on the delayed task to generate the processing result of the delayed task includes:

根据所述定时任务的预设执行频率轮询定时任务配置表,以周期性拉取待执行任务;Polling the timing task configuration table according to the preset execution frequency of the timing task to periodically pull tasks to be executed;

执行对所述待执行任务的处理操作,生成所述处理结果。Execute processing operations on the to-be-executed tasks to generate the processing results.

在其中一个实施例中,在所述执行对所述待执行任务的处理操作,生成所述处理结果之后,还包括:In one of the embodiments, after performing the processing operation on the to-be-executed task and generating the processing result, it further includes:

将所述待执行任务在所述定时任务配置表中的处理状态更新为已执行状态;updating the processing status of the to-be-executed task in the timing task configuration table to an executed status;

在预设时刻下,执行对所述定时任务配置表的数据迁移操作,以将所述定时任务配置表中处理状态为已执行状态的延时任务迁移至定时任务配置历史表。At a preset time, perform a data migration operation on the scheduled task configuration table, so as to migrate the delayed tasks whose processing status is executed in the scheduled task configuration table to the scheduled task configuration history table.

在其中一个实施例中,所述第一级别和所述第二级别根据所述延时任务的延时时长决定;In one of the embodiments, the first level and the second level are determined according to the delay duration of the delayed task;

所述第一级别对应的延时时长小于所述第二级别对应的延时时长。The delay time corresponding to the first level is shorter than the delay time corresponding to the second level.

第二方面,本申请还提供了一种延时任务的处理装置。所述装置包括:In a second aspect, the present application also provides a device for processing delayed tasks. The devices include:

单位确定模块,用于接收延时任务,确定所述延时任务的延时时间单位;A unit determination module, configured to receive a delayed task and determine the delayed time unit of the delayed task;

消息处理模块,用于在响应于所述延时时间单位为第一级别的情况下,利用消息队列执行对所述延时任务的处理操作,生成所述延时任务的处理结果;A message processing module, configured to use a message queue to perform a processing operation on the delayed task and generate a processing result of the delayed task in response to the delay time unit being the first level;

定时处理模块,用于在响应于所述延时时间单位为第二级别的情况下,利用定时任务执行对所述延时任务的处理操作,生成所述延时任务的处理结果。The timing processing module is configured to use a timing task to perform a processing operation on the delayed task and generate a processing result of the delayed task in response to the condition that the delay time unit is the second level.

第三方面,本申请还提供了一种计算机设备。所述计算机设备包括存储器和处理器,所述存储器存储有计算机程序,所述处理器执行所述计算机程序时实现上述第一方面任一项实施例所述的延时任务的处理方法。In a third aspect, the present application also provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the method for processing a delayed task described in any one embodiment of the first aspect above is implemented.

第四方面,本申请还提供了一种计算机可读存储介质。所述计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现上述第一方面任一项实施例所述的延时任务的处理方法。In a fourth aspect, the present application also provides a computer-readable storage medium. The computer-readable storage medium has a computer program stored thereon, and when the computer program is executed by a processor, the method for processing a delayed task described in any one embodiment of the first aspect above is implemented.

第五方面,本申请还提供了一种计算机程序产品。所述计算机程序产品,包括计算机程序,该计算机程序被处理器执行时实现上述第一方面任一项实施例的延时任务的处理方法。In a fifth aspect, the present application also provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, implements the delayed task processing method in any one embodiment of the first aspect above.

上述延时任务的处理方法、装置、计算机设备、存储介质和计算机程序产品,通过接收延时任务,确定延时任务的延时时间单位,在响应于延时时间单位为第一级别的情况下,利用消息队列执行对延时任务的处理操作,生成延时任务的处理结果,在响应于延时时间单位为第二级别的情况下,利用定时任务执行对延时任务的处理操作,生成延时任务的处理结果,能够针对不同级别的延时任务灵活采用不同的任务处理方式,从而实现在保障延时任务的延时精确性的同时降低延时任务处理时对数据库的轮询压力。In the processing method, device, computer equipment, storage medium and computer program product of the above-mentioned delayed task, the delay time unit of the delayed task is determined by receiving the delayed task, and in the case that the response delay time unit is the first level , use the message queue to execute the processing operation on the delayed task, generate the processing result of the delayed task, and use the timing task to execute the processing operation on the delayed task to generate the processing result of the delayed It can flexibly adopt different task processing methods for different levels of delayed tasks, so as to ensure the delay accuracy of delayed tasks and reduce the polling pressure on the database during delayed task processing.

附图说明Description of drawings

图1为一个实施例中延时任务的处理方法的应用场景图;Fig. 1 is an application scenario diagram of a processing method for a delayed task in an embodiment;

图2为一个实施例中延时任务的处理方法的流程示意图;Fig. 2 is a schematic flow chart of a processing method for a delayed task in an embodiment;

图3为一个实施例中消息队列处理步骤的流程示意图;Fig. 3 is a schematic flow chart of message queue processing steps in an embodiment;

图4为一个实施例中定时任务处理步骤的流程示意图;Fig. 4 is a schematic flow chart of the timing task processing steps in an embodiment;

图5为另一个实施例中延时任务的处理方法的流程示意图;FIG. 5 is a schematic flow diagram of a processing method for a delayed task in another embodiment;

图6为一个实施例中延时任务的处理装置的结构框图;Fig. 6 is a structural block diagram of a processing device for a delayed task in an embodiment;

图7为一个实施例中计算机设备的内部结构图。Figure 7 is an internal block diagram of a computer device in one embodiment.

具体实施方式Detailed ways

为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。In order to make the purpose, technical solution and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described here are only used to explain the present application, and are not intended to limit the present application.

需要说明的是,本申请所涉及的用户信息(包括但不限于用户设备信息、用户个人信息等)和数据(包括但不限于用于分析的数据、存储的数据、展示的数据等),均为经用户授权或者经过各方充分授权的信息和数据。It should be noted that the user information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all Information and data authorized by the user or fully authorized by all parties.

本申请实施例提供的延时任务的处理方法,可以应用于如图1所示的应用场景中。其中,终端110可以与服务器100通过网络进行通信。具体地,服务器100可以接收终端110发送的延时任务112。读取延时任务112的延时时间,从而确定延时任务112所属的延时时间单位。在响应于延时时间单元为第一级别的情况下,将延时任务112发送至消息队列102处理,利用消息队列102执行对延时任务112的处理操作,生成延时任务112的处理结果。或者,在响应于延时时间单元为第二级别的情况下,利用定时任务104对数据库发起轮询以获取延时任务112,利用定时任务104执行对延时任务112的处理操作,生成延时任务112的处理结果。其中,终端110可以但不限于是各种个人计算机、笔记本电脑、智能手机、平板电脑、物联网设备和便携式可穿戴设备,物联网设备可为智能音箱、智能电视、智能空调、智能车载设备等。便携式可穿戴设备可为智能手表、智能手环、头戴设备等。服务器100可以用独立的服务器或者是多个服务器组成的服务器集群来实现。The method for processing a delayed task provided in the embodiment of the present application may be applied to the application scenario shown in FIG. 1 . Wherein, the terminal 110 may communicate with the server 100 through a network. Specifically, the server 100 may receive the delayed task 112 sent by the terminal 110 . The delay time of the delay task 112 is read, so as to determine the delay time unit to which the delay task 112 belongs. In response to the case where the delay time unit is the first level, the delayed task 112 is sent to the message queue 102 for processing, and the message queue 102 is used to execute processing operations on the delayed task 112 to generate a processing result of the delayed task 112 . Or, when the delay time unit is the second level, use the timing task 104 to initiate polling to the database to obtain the delay task 112, and use the timing task 104 to perform processing operations on the delay task 112 to generate a delay The processing result of task 112. Among them, the terminal 110 can be, but not limited to, various personal computers, notebook computers, smart phones, tablet computers, Internet of Things devices and portable wearable devices, and the Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart vehicle-mounted devices, etc. . Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, and the like. The server 100 can be implemented by an independent server or a server cluster composed of multiple servers.

在一个实施例中,如图2所示,提供了一种延时任务的处理方法,以该方法应用于图1中的服务器100为例进行说明,包括以下步骤:In one embodiment, as shown in FIG. 2 , a method for processing a delayed task is provided. The application of the method to the server 100 in FIG. 1 is used as an example for illustration, including the following steps:

步骤S202,接收延时任务,确定延时任务的延时时间单位。Step S202, receiving the delayed task, and determining the delay time unit of the delayed task.

其中,延时时间单位可以包括但不仅限于秒、分钟、小时、天、周等。Wherein, the delay time unit may include but not limited to seconds, minutes, hours, days, weeks and so on.

具体地,服务器在接收到终端提交的延时任务后,可以对延时任务进行解析得到对应的延时时长。对延时时长进行合法性校验,譬如校验延时时长是否为负数,或者校验延时时长是否超过最大延时阈值等,将合法性校验通过的延时任务存储至服务器的任务列表中。遍历任务列表中的每个延时任务,根据延时任务的延时时长确定延时任务对应的延时时间单位。Specifically, after receiving the delayed task submitted by the terminal, the server may analyze the delayed task to obtain the corresponding delayed duration. Check the validity of the delay time, such as checking whether the delay time is a negative number, or checking whether the delay time exceeds the maximum delay threshold, etc., and storing the delayed tasks that pass the legality check in the server's task list middle. Each delayed task in the task list is traversed, and the delay time unit corresponding to the delayed task is determined according to the delay duration of the delayed task.

步骤S204,在响应于延时时间单位为第一级别的情况下,利用消息队列执行对延时任务的处理操作,生成延时任务的处理结果。Step S204, in response to the condition that the delay time unit is the first level, use the message queue to execute the processing operation on the delayed task, and generate a processing result of the delayed task.

其中,第一级别可以用于表征延时时间单位较小的级别,譬如秒对应的级别。Wherein, the first level may be used to represent a level with a smaller delay time unit, such as a level corresponding to seconds.

具体地,服务器可以在响应于延时时间单位为第一级别的情况下,将延时任务投递到消息队列kafka(一种高吞吐量的分布式发布订阅消息系统)的延时主题中。其中,延时主题可以用于临时存储未达到延时时长的延时任务。Specifically, the server may post the delayed task to the delayed topic of the message queue kafka (a high-throughput distributed publish-subscribe message system) when the response delay time unit is the first level. Among them, the delay topic can be used to temporarily store the delay tasks that have not reached the delay time.

利用消息队列kafka从延时主题中实时拉取达到延时时长的需要即刻执行的延时任务至任务主题。采用消息队列kafka作为消息消费者对任务主题下的延时任务信息进行消费处理,生成延时任务的处理结果。其中,处理结果可以包括处理成功或处理失败。Use the message queue kafka to pull the delayed tasks that need to be executed immediately to the task topic in real time. The message queue kafka is used as the message consumer to consume and process the delayed task information under the task topic, and generate the processing result of the delayed task. Wherein, the processing result may include processing success or processing failure.

步骤S206,在响应于延时时间单位为第二级别的情况下,利用定时任务执行对延时任务的处理操作,生成延时任务的处理结果。Step S206, in response to the condition that the delay time unit is the second level, use the timing task to perform processing operations on the delay task, and generate a processing result of the delay task.

其中,第二级别可以用于表征延时时间单位较大的级别,譬如分钟、小时或天对应的级别。Wherein, the second level may be used to represent a level with a larger delay time unit, such as a level corresponding to minutes, hours, or days.

具体地,服务器可以在响应于延时时间单位为第二级别的情况下,将延时任务存储至数据库中的定时任务配置表中,并将延时任务的处理请求投递到定时任务quartz(一种任务调度框架)中。Specifically, the server may store the delayed task in the timing task configuration table in the database in response to the fact that the delay time unit is the second level, and deliver the processing request of the delayed task to the timing task quartz (a A task scheduling framework).

利用定时任务quartz每隔预设周期扫描一次数据库中的定时任务配置表,也即每隔预设周期向数据库发起轮询,以将数据库中达到延时时长的需要即刻执行的延时任务拉取并存储至定时任务的任务队列中。采用定时任务quartz对任务队列下的延时任务进行处理,生成延时任务的处理结果。Use the scheduled task quartz to scan the scheduled task configuration table in the database every preset period, that is, initiate a poll to the database every preset period, so as to pull the delayed tasks that need to be executed immediately after reaching the delay time in the database And store it in the task queue of the scheduled task. The timed task quartz is used to process the delayed tasks under the task queue, and generate the processing results of the delayed tasks.

上述延时任务的处理方法中,通过接收延时任务,确定延时任务的延时时间单位,在响应于延时时间单位为第一级别的情况下,利用消息队列执行对延时任务的处理操作,生成延时任务的处理结果,在响应于延时时间单位为第二级别的情况下,利用定时任务执行对延时任务的处理操作,生成延时任务的处理结果,能够针对不同级别的延时任务灵活采用不同的任务处理方式,从而实现在保障延时任务的延时精确性的同时降低延时任务处理时对数据库的轮询压力。In the above method for processing delayed tasks, the delay time unit of the delayed task is determined by receiving the delayed task, and in the case that the response delay time unit is the first level, the message queue is used to execute the processing of the delayed task Operation, to generate the processing result of the delayed task, in response to the delay time unit being the second level, use the timing task to execute the processing operation on the delayed task, and generate the processing result of the delayed task, which can be used for different levels Delayed tasks flexibly adopt different task processing methods, so as to ensure the delay accuracy of delayed tasks and reduce the polling pressure on the database during delayed task processing.

在一个实施例中,如图3所示,步骤S204,在响应于延时时间单位为第一级别的情况下,利用消息队列执行对延时任务的处理操作,生成延时任务的处理结果,包括:In one embodiment, as shown in FIG. 3 , in step S204, in response to the fact that the delay time unit is the first level, use the message queue to execute the processing operation on the delayed task, and generate the processing result of the delayed task, include:

步骤S302,利用消息队列启动拉取线程,采用拉取线程查询待执行任务。Step S302, using the message queue to start a pull thread, and using the pull thread to query tasks to be executed.

其中,待执行任务可以用于表征等待时间已经达到延时时长,需要即刻执行的任务。Among them, the task to be executed can be used to represent the task whose waiting time has reached the delay time and needs to be executed immediately.

具体地,服务器在响应于延时时间单位为第一级别的情况下,可以在消息队列中启动拉取线程。利用拉取线程实时查询消息队列kafka中的延时主题,以确定延时主题内是否存在已达到延时时长的待执行任务。Specifically, the server may start a pull thread in the message queue in response to the delay time unit being the first level. Use the pull thread to query the delay topic in the message queue kafka in real time to determine whether there are tasks to be executed that have reached the delay time in the delay topic.

步骤S304,当存在多个待执行任务时,根据每个待执行任务对应的执行时间进行排序,确定每个待执行任务对应的处理顺序。Step S304, when there are multiple tasks to be executed, sort according to the execution time corresponding to each task to be executed, and determine the processing sequence corresponding to each task to be executed.

其中,执行时间可以用于表征待执行任务需要被执行的时刻。Wherein, the execution time may be used to represent the moment when the task to be executed needs to be executed.

具体地,当服务器确定延时主题内存在多个待执行任务时,可以利用拉取线程根据每个待执行任务对应的执行时间进行排序,譬如可以将执行时间与当前时刻的时间差最小的延时任务确定为排序中的首位,从而得到每个待执行任务对应的处理顺序。Specifically, when the server determines that there are multiple tasks to be executed in the delay topic, it can use the pull thread to sort according to the execution time corresponding to each task to be executed, for example, the delay time with the smallest time difference between the execution time and the current moment can be The task is determined as the first in the sorting, so as to obtain the processing sequence corresponding to each task to be executed.

步骤S306,利用拉取线程根据处理顺序依次拉取每个待处理的延时任务,并根据处理顺序处理每个待执行任务,生成处理结果。Step S306, using the pulling thread to sequentially pull each delayed task to be processed according to the processing sequence, and process each pending task according to the processing sequence to generate a processing result.

具体地,服务器可以利用拉取线程按照处理顺序,依次将每个待处理的延时任务拉取至待处理任务存储的任务主题中。利用消息队列kafka根据处理顺序依次执行对每个待执行任务的处理操作,并生成与每个待处理的延时任务对应的处理结果。Specifically, the server may use the pull thread to sequentially pull each pending delayed task into the task topic stored in the pending task according to the processing order. Use the message queue kafka to sequentially execute the processing operations on each pending task according to the processing order, and generate the processing results corresponding to each pending delayed task.

本实施例中,通过采用消息队列对延时任务进行实时处理,能够提高延时任务处理的延时精度。In this embodiment, by using the message queue to process the delayed task in real time, the delay accuracy of the delayed task processing can be improved.

在一个实施例中,在步骤S306,根据处理顺序依次执行处理每个待执行任务,生成处理结果之前,还包括:获取每个待执行任务的任务标识,确定不存在携带同一任务标识的已执行记录。In one embodiment, in step S306, each to-be-executed task is processed sequentially according to the processing order, and before generating the processing result, it further includes: obtaining the task identifier of each to-be-executed task, and determining that there is no executed task carrying the same task identifier. Record.

具体地,服务器的关系型数据库中可以存储有延时任务信息表。延时任务信息表中可以记录有延时任务的详情数据,譬如延时时长、处理状态、延时任务的任务标识等。在利用消息队列处理待执行任务之前,可以获取每个待执行任务的任务标识。根据每个待执行任务的任务标识,在延时任务信息表中查询是否存在携带同一任务标识且任务执行状态为已执行的延时任务处理记录。Specifically, a delayed task information table may be stored in the relational database of the server. The delayed task information table can record the detailed data of the delayed task, such as the delay time, processing status, and the task identification of the delayed task. Before using the message queue to process the pending tasks, the task ID of each pending task can be obtained. According to the task identifier of each task to be executed, query whether there is a delayed task processing record with the same task identifier and the task execution status as executed in the delayed task information table.

当服务器确定不存在携带同一任务标识的已执行记录时,可以按照处理顺序依次对多个待执行任务进行处理。并在待执行任务处理成功后更新延时任务信息表中记录的与当前处理成功的待执行任务对应的任务执行状态为已执行。When the server determines that there is no executed record carrying the same task identifier, multiple tasks to be executed may be processed sequentially according to the processing order. And after the task to be executed is successfully processed, the execution state of the task corresponding to the task to be executed that is currently successfully processed and recorded in the delayed task information table is updated as executed.

可选地,在一些实施例中,当服务器确定存在携带同一任务标识的已执行记录时,可以将当前判断的待执行任务移除,以避免待执行任务被重复执行。Optionally, in some embodiments, when the server determines that there is an executed record carrying the same task identifier, the currently judged to-be-executed task may be removed, so as to avoid repeated execution of the to-be-executed task.

可选地,在一些实施例中,服务器还可以对消息队列配置延时任务的保存期限。当消息队列内存储的延时任务过期后会自动清除。从而降低消息队列中的数据存储量,保障消息队列处于一个较高的处理效率。Optionally, in some embodiments, the server may also configure a retention period for the delayed task on the message queue. When the delayed tasks stored in the message queue expire, they will be cleared automatically. Thereby reducing the amount of data storage in the message queue and ensuring a high processing efficiency of the message queue.

本实施例中,通过查询延时任务信息表中是否存在与待执行任务携带同一任务标识的已执行记录,能够避免对待执行任务的重复处理。In this embodiment, by querying whether there is an executed record carrying the same task ID as the task to be executed in the delayed task information table, repeated processing of the task to be executed can be avoided.

在一个实施例中,如图4所示,步骤S206,在响应于延时时间单位为第二级别的情况下,利用定时任务执行对延时任务的处理操作,生成延时任务的处理结果,包括:In one embodiment, as shown in FIG. 4, in step S206, in response to the fact that the delay time unit is the second level, use the timing task to execute the processing operation on the delay task, and generate the processing result of the delay task, include:

步骤S402,根据定时任务的预设执行频率轮询定时任务配置表,以周期性拉取待执行任务。Step S402, polling the timing task configuration table according to the preset execution frequency of the timing task, so as to periodically fetch tasks to be executed.

具体地,服务器的数据库中可以存储有定时任务配置表。根据定时任务的预设执行频率轮询定时任务配置表,检测定时任务配置表内的延时任务中是否存在已达到延时时长的待执行任务。从而实现对定时任务配置表中的待执行任务的周期性拉取。可选地,在一些实施例中,预设执行频率可以为一分钟轮询一次、三小时轮询一次或一天轮询一次等。Specifically, a scheduled task configuration table may be stored in the database of the server. The scheduled task configuration table is polled according to the preset execution frequency of the scheduled task to detect whether there is a task to be executed that has reached the delay time in the delayed tasks in the scheduled task configuration table. In this way, periodic fetching of tasks to be executed in the scheduled task configuration table is realized. Optionally, in some embodiments, the preset execution frequency may be polling once a minute, polling once every three hours, or polling once a day.

步骤S404,执行对待执行任务的处理操作,生成处理结果。Step S404, execute the processing operation of the task to be executed, and generate the processing result.

步骤S406,将待执行任务在定时任务配置表中的处理状态更新为已执行状态。Step S406, updating the processing status of the task to be executed in the scheduled task configuration table to the executed status.

具体地,服务器可以利用定时任务执行对拉取的待执行任务的处理操作,生成与待执行任务对应的处理结果。在处理结果为处理成功的情况下,可以将当前处理成功的待执行任务在定时任务配置表的处理状态更新为已执行状态。Specifically, the server may use the timed task to perform a processing operation on the fetched task to be executed, and generate a processing result corresponding to the task to be executed. When the processing result is that the processing is successful, the processing status of the task to be executed that is currently processed successfully in the scheduled task configuration table may be updated to the executed state.

可选地,在一些实施例中,当定时任务从定时任务配置表中拉取多个待执行任务时,也可以根据每个待执行任务对应的执行时间进行排序,并根据排序后得到的处理顺序依次执行对每个待执行任务的处理操作。Optionally, in some embodiments, when the scheduled task pulls multiple tasks to be executed from the scheduled task configuration table, it can also be sorted according to the execution time corresponding to each task to be executed, and according to the processing obtained after sorting Sequentially execute the processing operations on each task to be executed sequentially.

步骤S408,在预设时刻下,执行对定时任务配置表的数据迁移操作,以将定时任务配置表中处理状态为已执行状态的待执行任务迁移至定时任务配置历史表。Step S408, at a preset time, perform a data migration operation on the scheduled task configuration table, so as to migrate the pending tasks whose processing status is executed in the scheduled task configuration table to the scheduled task configuration history table.

具体地,服务器可以在定时任务配置表中新增一条定时任务配置,以使得定时任务在预设时刻下执行对定时任务配置表的数据迁移操作:获取定时任务配置表中处理状态为已执行状态的延时任务,将已执行状态的延时任务从定时任务配置表中迁移至定时任务配置历史表中。Specifically, the server can add a new timed task configuration in the timed task configuration table, so that the timed task performs the data migration operation on the timed task configuration table at a preset time: obtain the processing status in the timed task configuration table as the executed state Delayed tasks in the executed state are migrated from the scheduled task configuration table to the scheduled task configuration history table.

可选地,在一些实施例中,预设时刻可以设置为每天凌晨十二点。Optionally, in some embodiments, the preset time can be set to twelve o'clock in the morning every day.

本实施例中,通过采用定时任务处理第二级别的延时任务,并在预设时刻下执行对定时任务配置表的数据迁移操作,能够减轻数据库的轮询压力,从而保障数据库的性能。In this embodiment, by using the scheduled task to process the second-level delayed task, and executing the data migration operation on the scheduled task configuration table at a preset time, the polling pressure of the database can be reduced, thereby ensuring the performance of the database.

在一个实施例中,第一级别和第二级别可以根据延时任务的延时时长决定。第一级别对应的延时时长小于第二级别对应的延时时长。In an embodiment, the first level and the second level may be determined according to the delay time of the delayed task. The delay time corresponding to the first level is shorter than the delay time corresponding to the second level.

可选地,在一些实施例中,当延时任务的延时时长为X秒时,可以确定延时任务的延时时间单位为第一级别,也即此时第一级别为秒级。当延时任务的延时时长为Y分钟或Z小时或D天时,可以确定延时任务的延时时间单位为第二级别,也即此时第二级别包括分钟级、小时级或天级中的任一种。Optionally, in some embodiments, when the delay duration of the delayed task is X seconds, it may be determined that the delay time unit of the delayed task is the first level, that is, the first level at this time is the second level. When the delay time of the delayed task is Y minutes or Z hours or D days, it can be determined that the delay time unit of the delayed task is the second level, that is, the second level includes minute level, hour level or day level of any kind.

本实施例中,通过根据延时任务的延时时长确定延时任务属于第一级别或第二级别,能够有助于后续灵活采用不同的处理方式执行延时任务。In this embodiment, by determining whether the delayed task belongs to the first level or the second level according to the delay duration of the delayed task, it is helpful to flexibly adopt different processing methods to execute the delayed task.

在一个实施例中,如图5所示,提供了一种延时任务的处理方法,包括:In one embodiment, as shown in FIG. 5 , a method for processing delayed tasks is provided, including:

步骤S502,接收延时任务,确定延时任务的延时时间单位。Step S502, receiving the delayed task, and determining the delay time unit of the delayed task.

具体地,服务器可以接收延时任务,将延时任务存储对应的列表中。获取延时任务的详情数据,从而确定延时任务的延时时间单位。Specifically, the server may receive the delayed task, and store the delayed task in a corresponding list. Obtain the detailed data of the delayed task, so as to determine the delayed time unit of the delayed task.

当延时时间单位为秒级时,确定延时任务的延时时间单位为第一级别。在响应于延时时间单位为第一级别的情况下,执行步骤S504~S506。When the delay time unit is second level, it is determined that the delay time unit of the delayed task is the first level. In the case that the response delay time unit is the first level, execute steps S504-S506.

当延时时间单位为分钟级、小时级或天级时,确定延时任务的延时时间单元为第二级别。在响应于延时时间单位为第二级别的情况下,执行步骤S508~S510。When the delay time unit is minute level, hour level or day level, determine the delay time unit of the delayed task as the second level. In the case that the response delay time unit is the second level, execute steps S508-S510.

步骤S504,利用消息队列启动拉取线程查询待执行任务,根据待执行任务对应的执行时间确定待执行任务对应的处理顺序。Step S504, using the message queue to start the pull thread to query the tasks to be executed, and determine the processing sequence corresponding to the tasks to be executed according to the execution time corresponding to the tasks to be executed.

具体地,服务器可以利用消息队列启动拉取线程来查询延时主题下已达到延时时长的待执行任务。当待执行任务存在多个时,可以根据每个待执行任务的执行时间进行排序,得到每个待执行任务的处理顺序。Specifically, the server can use the message queue to start a pull thread to query tasks to be executed under the delay topic that have reached the delay time. When there are multiple tasks to be executed, they can be sorted according to the execution time of each task to be executed to obtain the processing order of each task to be executed.

步骤S506,当不存在与待执行任务携带同一任务标识的已执行记录时,根据处理顺序依次拉取并处理每个待执行任务,生成每个待执行任务的处理结果。Step S506, when there is no executed record carrying the same task ID as the task to be executed, each task to be executed is sequentially fetched and processed according to the processing order, and a processing result of each task to be executed is generated.

具体地,在服务器数据库的延时任务信息表中查询是否存在与当前查询到的待执行任务携带同一任务标识的已执行记录。当不存在与待执行任务携带同一任务标识的已执行记录时,根据处理顺序依次拉取并处理每个待执行任务,生成每个待执行任务的处理结果。并在处理结果为成功的情况下,更新延时任务信息表中对应的处理状态。Specifically, it is queried in the delayed task information table of the server database whether there is an executed record carrying the same task identifier as the currently queried task to be executed. When there is no executed record carrying the same task identifier as the task to be executed, each task to be executed is sequentially pulled and processed according to the processing sequence, and the processing result of each task to be executed is generated. And if the processing result is successful, update the corresponding processing status in the delayed task information table.

步骤S508,根据定时任务的预设执行频率轮询数据库中的定时任务配置表,以周期性拉取待执行任务并处理,得到待执行任务的处理结果。Step S508, polling the timing task configuration table in the database according to the preset execution frequency of the timing task, to periodically fetch and process the tasks to be executed, and obtain the processing results of the tasks to be executed.

具体地,服务器可以根据定时任务的预设执行频率轮询数据库中的定时任务配置表,查询定时任务配置表内是否存在待执行任务。当待执行任务存在多个时,根据每个待执行任务的执行时间确定对应的处理顺序。根据处理顺序依次拉取并处理待执行任务,得到待执行任务的处理结果。并在处理结果为处理成功的情况下,更新待执行任务在定时任务配置表记录的处理状态为已执行。Specifically, the server may poll the scheduled task configuration table in the database according to the preset execution frequency of the scheduled task, and query whether there is a task to be executed in the scheduled task configuration table. When there are multiple tasks to be executed, the corresponding processing sequence is determined according to the execution time of each task to be executed. According to the processing sequence, the tasks to be executed are pulled and processed sequentially, and the processing results of the tasks to be executed are obtained. And when the processing result is successful, the processing status recorded in the scheduled task configuration table of the task to be executed is updated as executed.

步骤S510,利用定时任务在预设时刻下,将定时任务配置表中处理状态为已执行状态的延时任务迁移至定时任务配置历史表。Step S510, using the timed task to migrate the delayed tasks whose processing status is executed in the timed task configuration table to the timed task configuration history table at a preset time.

具体地,服务器可以利用定时任务在预设时刻下,查询定时任务配置表中处理状态为已执行状态的延时任务。并将查询到的延时任务迁移至定时任务配置历史表中。其中,定时任务配置历史表不参与定时任务的数据库轮询流程。Specifically, the server may use the scheduled task to query the delayed task whose processing status is in the executed state in the scheduled task configuration table at a preset time. And migrate the queried delayed tasks to the scheduled task configuration history table. Among them, the scheduled task configuration history table does not participate in the database polling process of the scheduled task.

本实施例中,通过对延时时长为秒级的延时任务,采用消息队列进行实时拉取处理,能够提高延时任务处理的延时精度。通过在消息队列处理待执行任务之前,查询是否存在待执行任务的已执行记录,能够避免待执行任务的重复处理,从而减少消息队列的数据处理量。通过对延时时长为分钟级、小时级或天级的延时任务,采用定时任务进行数据库轮询拉取,能够减少对数据库的轮询次数,从而保障数据库的性能。通过定时任务在预设时刻对定时任务配置表进行数据迁移,能够减少定时任务配置表的数据量,从而降低数据库轮询压力。In this embodiment, by using the message queue to perform real-time pull processing on the delayed tasks whose delay duration is at the second level, the delay accuracy of the delayed task processing can be improved. By querying whether there is an executed record of the task to be executed before the message queue processes the task to be executed, repeated processing of the task to be executed can be avoided, thereby reducing the data processing amount of the message queue. By using scheduled tasks for database polling and pulling for delay tasks with a delay time of minutes, hours, or days, the number of polls to the database can be reduced, thereby ensuring the performance of the database. By performing data migration on the scheduled task configuration table at a preset time by the scheduled task, the amount of data in the scheduled task configuration table can be reduced, thereby reducing the database polling pressure.

应该理解的是,虽然如上所述的各实施例所涉及的流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,这些步骤可以以其他的顺序执行。而且,如上所述的各实施例所涉及的流程图中的至少一部分步骤可以包括多个步骤或者多个阶段,这些步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,这些步骤或者阶段的执行顺序也不必然是依次进行,而是可以与其他步骤或者其他步骤中的步骤或者阶段的至少一部分轮流或者交替地执行。It should be understood that although the steps in the flow charts involved in the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed sequentially in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least some of the steps in the flow charts involved in the above-mentioned embodiments may include multiple steps or stages, and these steps or stages are not necessarily executed at the same time, but may be performed at different times For execution, the execution sequence of these steps or stages is not necessarily performed sequentially, but may be performed in turn or alternately with other steps or at least a part of steps or stages in other steps.

基于同样的发明构思,本申请实施例还提供了一种用于实现上述所涉及的延时任务的处理方法的延时任务的处理装置。该装置所提供的解决问题的实现方案与上述方法中所记载的实现方案相似,故下面所提供的一个或多个延时任务的处理装置实施例中的具体限定可以参见上文中对于延时任务的处理方法的限定,在此不再赘述。Based on the same inventive concept, an embodiment of the present application further provides a delayed task processing apparatus for implementing the above-mentioned delay task processing method. The solution to the problem provided by the device is similar to the implementation described in the above method, so the specific limitations in the embodiment of the processing device for one or more delayed tasks provided below can be referred to above for delayed tasks The limitation of the processing method will not be repeated here.

在一个实施例中,如图6所示,提供了一种延时任务的处理装置600,包括:单位确定模块602、消息处理模块604和定时处理模块606,其中:In one embodiment, as shown in FIG. 6 , a delay task processing device 600 is provided, including: a unit determination module 602, a message processing module 604, and a timing processing module 606, wherein:

单位确定模块602,用于接收延时任务,确定延时任务的延时时间单位。The unit determining module 602 is configured to receive a delayed task and determine a delayed time unit of the delayed task.

消息处理模块604,用于在响应于延时时间单位为第一级别的情况下,利用消息队列执行对延时任务的处理操作,生成延时任务的处理结果。The message processing module 604 is configured to use the message queue to execute a processing operation on the delayed task and generate a processing result of the delayed task in response to the condition that the delayed time unit is the first level.

定时处理模块606,用于在响应于延时时间单位为第二级别的情况下,利用定时任务执行对延时任务的处理操作,生成延时任务的处理结果。The timing processing module 606 is configured to use the timing task to perform a processing operation on the delayed task and generate a processing result of the delayed task in response to the condition that the delay time unit is the second level.

在一个实施例中,消息处理模块604,包括:线程查询单元,用于利用消息队列启动拉取线程,采用拉取线程查询待执行任务;顺序确定单元,用于当存在多个待执行任务时,根据每个待执行任务对应的执行时间进行排序,确定每个待执行任务对应的处理顺序;线程拉取单元,用于利用拉取线程根据处理顺序依次拉取每个待执行任务,并根据处理顺序依次处理每个待执行任务,生成处理结果。In one embodiment, the message processing module 604 includes: a thread query unit, configured to use a message queue to start a pull thread, and use the pull thread to query tasks to be executed; a sequence determination unit, configured to when there are multiple tasks to be executed , sort according to the execution time corresponding to each to-be-executed task, and determine the processing sequence corresponding to each to-be-executed task; the thread pulling unit is used to use the pulling thread to sequentially pull each to-be-executed task according to the processing order, and according to The processing sequence processes each task to be executed sequentially and generates a processing result.

在一个实施例中,消息处理模块604,还包括:记录查询单元,用于获取每个待执行任务的任务标识,确定不存在携带同一任务标识的已执行记录。In one embodiment, the message processing module 604 further includes: a record query unit, configured to obtain a task identifier of each task to be executed, and determine that there is no executed record carrying the same task identifier.

在一个实施例中,定时处理模块606,包括:数据库轮询单元,用于根据定时任务的预设执行频率轮询定时任务配置表,以周期性拉取待执行任务,任务处理单元,用于执行对待执行任务的处理操作,生成处理结果。In one embodiment, the timing processing module 606 includes: a database polling unit, configured to poll the timing task configuration table according to the preset execution frequency of the timing task, to periodically pull tasks to be executed, and a task processing unit for Execute the processing operation of the task to be executed, and generate the processing result.

在一个实施例中,定时处理模块606,还包括:状态更新单元,用于将待执行任务在定时任务配置表中的处理状态更新为已执行状态,数据迁移单元,用于在预设时刻下,执行对定时任务配置表的数据迁移操作,以将定时任务配置表中处理状态为已执行状态的延时任务迁移至定时任务配置历史表。In one embodiment, the timing processing module 606 further includes: a status update unit, configured to update the processing status of the task to be executed in the timing task configuration table to an executed status, and a data migration unit, configured to , perform a data migration operation on the scheduled task configuration table, so as to migrate the delayed tasks whose processing status is executed in the scheduled task configuration table to the scheduled task configuration history table.

在一个实施例中,第一级别和第二级别根据延时任务的延时时长决定。第一级别对应的延时时长小于第二级别对应的延时时长。In one embodiment, the first level and the second level are determined according to the delay duration of the delayed task. The delay time corresponding to the first level is shorter than the delay time corresponding to the second level.

上述延时任务的处理装置中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各模块可以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行以上各个模块对应的操作。Each module in the above-mentioned device for processing delayed tasks may be fully or partially implemented by software, hardware or a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, and can also be stored in the memory of the computer device in the form of software, so that the processor can invoke and execute the corresponding operations of the above-mentioned modules.

在一个实施例中,提供了一种计算机设备,该计算机设备可以是服务器,其内部结构图可以如图7所示。该计算机设备包括通过系统总线连接的处理器、存储器和网络接口。其中,该计算机设备的处理器用于提供计算和控制能力。该计算机设备的存储器包括非易失性存储介质和内存储器。该非易失性存储介质存储有操作系统、计算机程序和数据库。该内存储器为非易失性存储介质中的操作系统和计算机程序的运行提供环境。该计算机设备的数据库用于存储延时时长。该计算机设备的网络接口用于与外部的终端通过网络连接通信。该计算机程序被处理器执行时以实现一种延时任务的处理方法。In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure may be as shown in FIG. 7 . The computer device includes a processor, memory and a network interface connected by a system bus. Wherein, the processor of the computer device is used to provide calculation and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, computer programs and databases. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database of the computer device is used to store the delay duration. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a delayed task processing method is realized.

本领域技术人员可以理解,图7中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备的限定,具体的计算机设备可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。Those skilled in the art can understand that the structure shown in Figure 7 is only a block diagram of a part of the structure related to the solution of this application, and does not constitute a limitation to the computer equipment on which the solution of this application is applied. The specific computer equipment can be More or fewer components than shown in the figures may be included, or some components may be combined, or have a different arrangement of components.

在一个实施例中,还提供了一种计算机设备,包括存储器和处理器,存储器中存储有计算机程序,该处理器执行计算机程序时实现上述各方法实施例中的步骤。In one embodiment, there is also provided a computer device, including a memory and a processor, where a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.

在一个实施例中,还提供了一种计算机可读存储介质,其上存储有计算机程序,计算机程序被处理器执行时实现上述各方法实施例中的步骤。In one embodiment, there is also provided a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps in the foregoing method embodiments are implemented.

在一个实施例中,提供了一种计算机程序产品,包括计算机程序,该计算机程序被处理器执行时实现上述各方法实施例中的步骤。In one embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in the foregoing method embodiments are implemented.

本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可以存储于一非易失性计算机可读取存储介质中,该计算机程序在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的各实施例中所使用的对存储器、数据库或其他介质的任何引用,均可包括非易失性和易失性存储器中的至少一种。非易失性存储器可包括只读存储器(Read-OnlyMemory,ROM)、磁带、软盘、闪存、光存储器、高密度嵌入式非易失性存储器、阻变存储器(ReRAM)、磁变存储器(Magnetoresistive Random Access Memory,MRAM)、铁电存储器(Ferroelectric Random Access Memory,FRAM)、相变存储器(Phase Change Memory,PCM)、石墨烯存储器等。易失性存储器可包括随机存取存储器(Random Access Memory,RAM)或外部高速缓冲存储器等。作为说明而非局限,RAM可以是多种形式,比如静态随机存取存储器(Static Random Access Memory,SRAM)或动态随机存取存储器(Dynamic RandomAccess Memory,DRAM)等。本申请所提供的各实施例中所涉及的数据库可包括关系型数据库和非关系型数据库中至少一种。非关系型数据库可包括基于区块链的分布式数据库等,不限于此。本申请所提供的各实施例中所涉及的处理器可为通用处理器、中央处理器、图形处理器、数字信号处理器、可编程逻辑器、基于量子计算的数据处理逻辑器等,不限于此。Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be implemented through computer programs to instruct related hardware, and the computer programs can be stored in a non-volatile computer-readable memory In the medium, when the computer program is executed, it may include the processes of the embodiments of the above-mentioned methods. Wherein, any reference to storage, database or other media used in the various embodiments provided in the present application may include at least one of non-volatile and volatile storage. Non-volatile memory can include read-only memory (Read-Only Memory, ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive variable memory (ReRAM), magnetic variable memory (Magnetoresistive Random Access Memory, MRAM), Ferroelectric Random Access Memory (FRAM), Phase Change Memory (Phase Change Memory, PCM), graphene memory, etc. The volatile memory may include random access memory (Random Access Memory, RAM) or external cache memory. As an illustration and not a limitation, RAM can be in various forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (Dynamic Random Access Memory, DRAM). The databases involved in the various embodiments provided in this application may include at least one of a relational database and a non-relational database. The non-relational database may include a blockchain-based distributed database, etc., but is not limited thereto. The processors involved in the various embodiments provided by this application can be general-purpose processors, central processing units, graphics processors, digital signal processors, programmable logic devices, data processing logic devices based on quantum computing, etc., and are not limited to this.

以上实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。The technical features of the above embodiments can be combined arbitrarily. To make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be It is considered to be within the range described in this specification.

以上所述实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对本申请专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以作出若干变形和改进,这些都属于本申请的保护范围。因此,本申请的保护范围应以所附权利要求为准。The above-mentioned embodiments only express several implementation modes of the present application, and the description thereof is relatively specific and detailed, but should not be construed as limiting the patent scope of the present application. It should be noted that those skilled in the art can make several modifications and improvements without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application should be determined by the appended claims.

Claims (10)

1.一种延时任务的处理方法,其特征在于,所述方法包括:1. A processing method for a delayed task, characterized in that the method comprises: 接收延时任务,确定所述延时任务的延时时间单位;receiving a delayed task, and determining the delay time unit of the delayed task; 在响应于所述延时时间单位为第一级别的情况下,利用消息队列执行对所述延时任务的处理操作,生成所述延时任务的处理结果;In response to the case where the delay time unit is the first level, use a message queue to execute a processing operation on the delay task, and generate a processing result of the delay task; 在响应于所述延时时间单位为第二级别的情况下,利用定时任务执行对所述延时任务的处理操作,生成所述延时任务的处理结果。In response to the condition that the delayed time unit is the second level, the timing task is used to execute the processing operation on the delayed task, and a processing result of the delayed task is generated. 2.根据权利要求1所述的方法,其特征在于,所述利用消息队列执行对所述延时任务的处理操作,生成所述延时任务的处理结果,包括:2. The method according to claim 1, wherein the processing operation of the delayed task by using a message queue to generate a processing result of the delayed task comprises: 利用所述消息队列启动拉取线程,采用所述拉取线程查询待执行任务;Use the message queue to start a pull thread, and use the pull thread to query tasks to be executed; 当存在多个所述待执行任务时,根据每个所述待执行任务对应的执行时间进行排序,确定每个所述待执行任务对应的处理顺序;When there are multiple to-be-executed tasks, sort according to the execution time corresponding to each of the to-be-executed tasks, and determine the processing sequence corresponding to each of the to-be-executed tasks; 利用所述拉取线程根据所述处理顺序依次拉取每个所述待执行任务,并根据所述处理顺序依次处理每个所述待执行任务,生成所述处理结果。Each of the to-be-executed tasks is sequentially pulled by the pulling thread according to the processing sequence, and each of the to-be-executed tasks is sequentially processed according to the processing sequence to generate the processing result. 3.根据权利要求2所述的方法,其特征在于,在所述根据所述处理顺序依次处理每个所述待执行任务,生成所述处理结果之前,还包括:3. The method according to claim 2, characterized in that, before said sequentially processing each of said to-be-executed tasks according to said processing sequence and generating said processing result, further comprising: 获取每个所述待执行任务的任务标识;Obtaining a task identifier of each task to be executed; 确定不存在携带同一所述任务标识的已执行记录。It is determined that there is no executed record carrying the same task identifier. 4.根据权利要求1所述的方法,其特征在于,所述利用所述定时任务执行对所述延时任务的处理操作,生成所述延时任务的处理结果,包括:4. The method according to claim 1, wherein the processing operation of the delayed task by using the timing task to generate the processing result of the delayed task comprises: 根据所述定时任务的预设执行频率轮询定时任务配置表,以周期性拉取待执行任务;Polling the timing task configuration table according to the preset execution frequency of the timing task to periodically pull tasks to be executed; 执行对所述待执行任务的处理操作,生成所述处理结果。Execute processing operations on the to-be-executed tasks to generate the processing results. 5.根据权利要求4所述的方法,其特征在于,在所述执行对所述待执行任务的处理操作,生成所述处理结果之后,还包括:5. The method according to claim 4, characterized in that, after performing the processing operation on the task to be executed and generating the processing result, further comprising: 将所述待执行任务在所述定时任务配置表中的处理状态更新为已执行状态;updating the processing status of the to-be-executed task in the timing task configuration table to an executed status; 在预设时刻下,执行对所述定时任务配置表的数据迁移操作,以将所述定时任务配置表中处理状态为已执行状态的延时任务迁移至定时任务配置历史表。At a preset time, perform a data migration operation on the scheduled task configuration table, so as to migrate the delayed tasks whose processing status is executed in the scheduled task configuration table to the scheduled task configuration history table. 6.根据权利要求1~5中任一项所述的方法,其特征在于,所述第一级别和所述第二级别根据所述延时任务的延时时长决定;6. The method according to any one of claims 1 to 5, wherein the first level and the second level are determined according to the delay duration of the delayed task; 所述第一级别对应的延时时长小于所述第二级别对应的延时时长。The delay time corresponding to the first level is shorter than the delay time corresponding to the second level. 7.一种延时任务的处理装置,其特征在于,所述装置包括:7. A processing device for delayed tasks, characterized in that the device comprises: 单位确定模块,用于接收延时任务,确定所述延时任务的延时时间单位;A unit determination module, configured to receive a delayed task and determine the delayed time unit of the delayed task; 消息处理模块,用于在响应于所述延时时间单位为第一级别的情况下,利用消息队列执行对所述延时任务的处理操作,生成所述延时任务的处理结果;A message processing module, configured to use a message queue to perform a processing operation on the delayed task and generate a processing result of the delayed task in response to the delay time unit being the first level; 定时处理模块,用于在响应于所述延时时间单位为第二级别的情况下,利用定时任务执行对所述延时任务的处理操作,生成所述延时任务的处理结果。The timing processing module is configured to use a timing task to perform a processing operation on the delayed task and generate a processing result of the delayed task in response to the condition that the delay time unit is the second level. 8.一种计算机设备,包括存储器和处理器,所述存储器存储有计算机程序,其特征在于,所述处理器执行所述计算机程序时实现权利要求1至6中任一项所述的方法的步骤。8. A computer device, comprising a memory and a processor, the memory stores a computer program, wherein the processor implements the method according to any one of claims 1 to 6 when executing the computer program step. 9.一种计算机可读存储介质,其上存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现权利要求1至6中任一项所述的方法的步骤。9. A computer-readable storage medium, on which a computer program is stored, wherein when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are realized. 10.一种计算机程序产品,包括计算机程序,其特征在于,该计算机程序被处理器执行时实现权利要求1至6中任一项所述的方法的步骤。10. A computer program product, comprising a computer program, characterized in that, when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
CN202310626247.3A 2023-05-30 2023-05-30 Processing method and device of delay task, computer equipment and storage medium Pending CN116610429A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310626247.3A CN116610429A (en) 2023-05-30 2023-05-30 Processing method and device of delay task, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310626247.3A CN116610429A (en) 2023-05-30 2023-05-30 Processing method and device of delay task, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116610429A true CN116610429A (en) 2023-08-18

Family

ID=87677914

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310626247.3A Pending CN116610429A (en) 2023-05-30 2023-05-30 Processing method and device of delay task, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116610429A (en)

Similar Documents

Publication Publication Date Title
CN114217954B (en) Job scheduling method, device, computer equipment, and storage medium
US20120102168A1 (en) Communication And Coordination Between Web Services In A Cloud-Based Computing Environment
CN114416324A (en) Task triggering method, apparatus, computer equipment and storage medium
CN111953569B (en) State information reporting method, device, equipment and medium
CN111858234A (en) A task execution method, apparatus, device and medium
CN116610429A (en) Processing method and device of delay task, computer equipment and storage medium
US20240305576A1 (en) Techniques for sequential data enrichment
CN116383228B (en) Data processing method, device, computer equipment and storage medium
CN115809311B (en) Knowledge graph data processing method and device and computer equipment
CN115357352A (en) Distributed asynchronous task scheduling method, device, computer equipment, storage medium
CN112435000B (en) Pending order notification method and device, computer equipment and storage medium
CN116541137A (en) Transaction processing method, apparatus, computer device, storage medium, and program product
CN115293908A (en) Method, device, computer equipment and storage medium for identifying abnormal transaction events
CN115422006A (en) Alarm processing method, device, equipment and storage medium
CN115098232A (en) Method, apparatus and device for task scheduling
CN114168329A (en) Distributed batch optimization method, electronic device and computer-readable storage medium
CN116932779B (en) Knowledge graph data processing method and device
CN119383104B (en) Task inspection method, device, equipment and medium
CN116244256B (en) Data warehousing method and device, storage medium and electronic equipment
CN119557102A (en) Task processing method, device, equipment, readable storage medium and program product
CN116975063A (en) Vector data processing method, vector data processing device, computer equipment and storage medium
CN120111022A (en) Delayed message sending method, device, computer equipment and storage medium
CN115865857A (en) Response data push method, device, computer equipment and storage medium
CN119066068A (en) Method, device, equipment and readable storage medium for table operation of business data
CN118535355A (en) Output auxiliary method, device, computer equipment, readable storage medium and program product applied to large models

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination