Task processing method and device, electronic equipment and storage medium
By inserting special priority tasks into the download task queue and grouping, the problem of disorderly execution of download tasks is solved, timely downloading of important resources and reasonable resource allocation are achieved, and user experience and download efficiency are improved.
Patent Information
- Application Number
- CN202510359300.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-25
- Publication Date
- 2025-07-11
AI Technical Summary
During the resource download process in the prior art, important resources cannot be downloaded in time, resulting in poor user experience and unorderly execution of download tasks, resulting in unreasonable resource allocation.
By inserting special priority download tasks into the head of the download task queue and grouping them according to the task priority and attributes, we ensure that important resources are downloaded in a timely manner and the download order is reasonably arranged.
Improve the execution efficiency and user experience of download tasks, ensure that important resources can be downloaded quickly, and avoid resource delays caused by congestion in message channels.
Smart Images

Figure CN120295689A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of data processing, and in particular, to a task processing method, apparatus, electronic device, and storage medium. Background Art
[0002] When a user starts an application for the first time, a large number of resources need to be downloaded. To prevent the application from becoming unresponsive during the download process and ensure the stability of the program, the current measure is to assign the resource download task to an independent process for execution to reduce interference with the main process;
[0003] However, in the actual process of processing the download task, if a large number of resource download tasks are directly assigned to the download process, the download process will download resources disorderly, resulting in some important resources not being downloaded in time, thus affecting the overall user experience.
[0004] Therefore, it is urgent to develop a task processing method, apparatus, electronic device, and storage medium to solve one or more of the above problems. Summary of the Invention
[0005] In view of this, to solve the above technical problems or some of the technical problems, embodiments of the present invention provide a task processing method, apparatus, electronic device, and storage medium.
[0006] This application provides a task processing method, the method comprising:
[0007] Obtain a plurality of download tasks received within a preset time period, and the task priority corresponding to each download task;
[0008] When there is a download task with a target priority among the plurality of download tasks, insert the download task with the target priority to the head of the download task queue to complete the sequential update of the download task queue;
[0009] When the download process completes the current download task, retrieve the download task with the target priority from the head of the updated download task queue and perform the download operation.
[0010] In a possible implementation manner, the method further comprises:
[0011] When there is a download task with a non-target priority among the plurality of download tasks, insert the download task with the non-target priority to the corresponding position in the download task queue to complete the sequential update of the download task queue, where the non-target priority includes a plurality of level identifiers, and the download tasks corresponding to different level identifiers of the non-target priority are in different positions in the download task queue;
[0012] When the download process completes the current download task, retrieve the download tasks sequentially from the updated download task queue and perform the download operation.
[0013] In a possible implementation, the target priority is the highest priority, and the download tasks with the target priority include at least one first download subtask;
[0014] Inserting the download tasks with the target priority to the head of the download task queue includes:
[0015] Obtain the reception time of at least one first download subtask included in the download task;
[0016] Based on the reception time, perform sorting and combination processing on all the first download subtasks included in the download task to obtain a first download group;
[0017] Insert the first download group to the head of the download task queue.
[0018] In a possible implementation, inserting the download tasks with the non-target priority to the corresponding position in the download task queue includes:
[0019] Determine whether there is a download subtask with a preset priority in the download tasks with the non-target priority, and the level identifier of the preset priority is the target level identifier;
[0020] When there is a download subtask with a preset priority in the download task, insert the download subtask with the preset priority to the corresponding position in the download task queue, and re-perform the step of determining whether there is a download subtask with a preset priority on the remaining download tasks with the non-target priority;
[0021] When there is no download subtask with a preset level in the download task, insert the download subtasks with non-preset priorities to the corresponding positions in the download task queue according to their respective priority levels.
[0022] In a possible implementation, inserting the download subtasks with the preset priority to the corresponding position in the download task queue includes:
[0023] Perform sorting and combination processing on the download subtasks with the preset priority to obtain a second download group;
[0024] Determine whether there is a first download group in the download task queue;
[0025] When there is a first download group in the download task queue, insert the second download group after the first download group in the download task queue, so that after the task retrieval of the first download group is completed, the task retrieval of the second download group is sequentially executed;
[0026] When there is no first download group in the download task queue, insert the second download group at the head of the download task queue.
[0027] In a possible implementation manner, the inserting the download subtasks with non-preset priorities into the corresponding positions in the download task queue according to their respective priority levels includes:
[0028] According to the level identifier of the non-preset priority, determine at least one level of task sub-priorities included in the non-preset priority;
[0029] Determine the single-group task volume according to the pre-set download configuration information;
[0030] Based on the reception time of the download subtasks included in each level of task sub-priority and the single-group task volume, perform sorting and combination processing on the download subtasks included in each level of task sub-priority to obtain a third download sub-group set corresponding to each level of task sub-priority;
[0031] According to the priority level of each third download sub-group included in the third download sub-group set, insert each third download sub-group included in the third download sub-group set into the corresponding position in the respective download task queue.
[0032] In a possible implementation manner, before the download operation is executed, the method further includes:
[0033] Determine the current callback task, where the callback task is the download task that is currently performing task scheduling in the download task queue;
[0034] In the case where the scheduling result is normal download, add the current callback task to the download process to complete the download operation of the current callback task;
[0035] In the case where the scheduling result is waiting for download, predict the download waiting duration, and after the waiting duration, re-add the current callback task to the download task queue and re-execute the task scheduling of the current callback task to complete the re-download of the current callback task.
[0036] In a first aspect, the present application provides a task processing device, and the device includes:
[0037] An acquisition module, configured to acquire a plurality of download tasks received within a preset time period, and the task priority corresponding to each download task;
[0038] A first insertion module, configured to, when there is a download task with a target priority among a plurality of the download tasks, insert the download task with the target priority to the head of a download task queue, so as to complete the sequential update of the download task queue;
[0039] An extraction module, configured to, when a download process completes a current download task, extract the download task with the target priority from the head of the updated download task queue, and perform a download operation.
[0040] In a second aspect, the present application provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, steps of the task processing method according to any one of the embodiments in the first aspect are implemented.
[0041] In a fourth aspect, the present application further provides a computer storage medium, on which a computer program is stored. When the computer program is executed by a processor, steps of the task processing method according to any one of the embodiments in the first aspect are implemented.
[0042] The above technical solutions provided by the embodiments of the present application have the following advantages compared with the prior art: In the method provided by the embodiments of the present application, a download task with a special priority is inserted to the head of the download task queue, so that the download task can be preferentially scheduled and executed, ensuring that important resources can be downloaded in time and improving the execution efficiency of important download tasks; at the same time, the download tasks are grouped, and the grouped download tasks are inserted to corresponding positions in the download task queue according to the task priority and task attributes, refining the execution order of the download tasks, ensuring that the download tasks are executed in a reasonable order, thereby improving the execution effect of the download tasks and the user experience. Description of the Drawings
[0043] The drawings here are incorporated into the description and form a part of this description, showing embodiments consistent with the present invention and, together with the description, used to explain the principles of the present invention.
[0044] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can also be obtained based on these drawings without creative efforts.
[0045] One or more embodiments are exemplarily illustrated by the pictures in the corresponding drawings. These exemplary illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are represented as similar elements, unless otherwise stated, and the drawings in the drawings do not constitute a proportional limitation.
[0046] Figure 1 A schematic flowchart of a task processing method provided by an embodiment of the present application;
[0047] Figure 2 A schematic flowchart of another task processing method provided by an embodiment of the present application;
[0048] Figure 3 A schematic flowchart of a method for inserting a target priority download task into a download task queue provided by an embodiment of the present application;
[0049] Figure 4 A schematic flowchart of a method for inserting a non-target priority download task into a download task queue provided by an embodiment of the present application;
[0050] Figure 5 A schematic flowchart of a method for inserting a preset priority download task into a download task queue provided by an embodiment of the present application;
[0051] Figure 6 A schematic flowchart of a method for inserting a non-preset priority download task into a download task queue provided by an embodiment of the present application;
[0052] Figure 7 A flowchart block diagram of a task processing method provided by an embodiment of the present application;
[0053] Figure 8 A flowchart of steps of a task processing method provided by an embodiment of the present application;
[0054] Figure 9 A schematic structural diagram of a task processing device provided by an embodiment of the present application;
[0055] Figure 10 A schematic structural diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0056] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some but not all of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the protection scope of the present application.
[0057] The following disclosure provides many different embodiments or examples for implementing different structures of the present invention. To simplify the disclosure of the present invention, the components and settings of specific examples are described below. Of course, they are only examples and are not intended to limit the present invention. In addition, the present invention may repeat reference numerals and / or letters in different examples. This repetition is for the purpose of simplification and clarity and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0058] To solve the technical problem that in the prior art, during task download processing, the message channel is consumed due to excessive data objects being transmitted in a short period of time, resulting in message blocking, which causes the download process to perform resource downloads disorderly, causing some important resources to not be downloaded in time, thus affecting the overall user experience, this application provides a task processing method, device, electronic device, and storage medium. By inserting a download task with a special priority to the head of the download task queue, the download task can be scheduled and executed preferentially, thereby ensuring that important resources can be downloaded in time. At the same time, the download tasks are grouped, and the grouped download tasks are inserted into the corresponding positions in the download task queue according to the task priority and task attributes, refining the execution order of the download tasks and improving the execution effect of the download tasks and the user experience.
[0059] Figure 1 It is a schematic flowchart of a task processing method provided by an embodiment of this application. As Figure 1 shown, the method specifically includes:
[0060] S101. Obtain a plurality of download tasks received within a preset time period, and the task priority corresponding to each download task;
[0061] In this embodiment, the system needs to monitor the channels for receiving download tasks in real time. These channels may include network interfaces (such as interfaces corresponding to protocols such as HTTP, FTP, etc.), message queues, specific application program interfaces (APIs), etc. During the receiving process, the monitoring program continuously monitors these channels. Once a new download task request arrives, it performs preliminary identification and recording. For example, when a new file download request is sent to the server through the HTTP interface, the monitoring program will immediately capture the request and accurately record its receiving time. Then, all received download tasks are collected, download task objects are established, and the download task fields are encapsulated. Important fields include, for example: priority, download url, resource size, storage path, business ID, for subsequent processing and management.
[0062] It should be noted that the storage task uses a data structure queue implemented by the class LinkedList to store and operate on data. The head of the queue is the dequeue position, and the tail of the queue is the enqueue position. The first-in, first-out principle is adopted to ensure the execution order of the download tasks. At the same time, the data structure queue has the ability to dynamically expand to adapt to different numbers of download tasks.
[0063] Specifically, a unified interface for adding download tasks is provided externally to implement the unified management of all in-app business downloads within the framework. Among them, considering the need for a group of task downloads in many business scenarios, the system provides two interfaces. One is the interface for adding a single download task, and the other is the interface for adding a group of download tasks. During the process of receiving download tasks, the business side only needs to construct a download task object and call the above interfaces according to the requirements, which is beneficial for the receiver to accurately and quickly process the download requests.
[0064] S102. When there is a download task with the target priority among the multiple download tasks, insert the download task with the target priority to the head of the download task queue to complete the sequential update of the download task queue.
[0065] In this embodiment, for download tasks with the target priority level (special priority level), the priority queue queuing is generally directly ignored, and they are directly inserted into the head of the pending scheduling queue. The download will be executed immediately in the next scheduling, effectively arranging resources to ensure that high-priority tasks can be processed in a timely manner and improving the user experience.
[0066] Specifically, considering that in some cases, users may trigger some functions that require immediate offline of resources. For the requirements of this specific scenario, it is necessary to ensure that the task downloads are executed with the highest priority. For this reason, a special priority level is set, and tasks with this special priority can be processed in a timely manner, avoiding the situation where users wait for a long time without response after clicking the button, ensuring the smoothness of the user experience and the response speed of the system, thereby improving user satisfaction and operation efficiency.
[0067] It should be noted that this embodiment defines a type of task with special priority. This special priority task needs to be triggered by manual clicking and is placed in a separate LinkedList (linked list) after being triggered to form an independent group, so that the special priority tasks are not restricted by the number of ordinary groups, thereby ensuring that important resources can obtain the right to be downloaded first and guaranteeing the efficiency of the download process and the rationality of resource allocation.
[0068] S103. When the download process completes the current download task, retrieve the download task with the target priority from the head of the updated download task queue and perform the download operation.
[0069] In this embodiment, by retrieving the download task to view the task status, the current status of each task can be intuitively understood, such as downloading, paused, completed, download failed, etc. For example, when downloading a large software or file, the user can view the download progress at any time to know how much time is still needed to complete the download, so as to reasonably arrange the time.
[0070] Specifically, for tasks in the target priority level, first take 3 of them and add them to the download process through IPC for task download. After a single task is downloaded and completed, take the head task from the queue and call IPC to add it to the download process for download; for newly added special priority tasks during the download process, they will be added to the download process through IPC after the download process calls back that a certain task has been downloaded and completed, aiming to ensure the high-priority download of such tasks.
[0071] It should be noted that the number of download tasks added to the download process in this embodiment is calculated according to the configuration. The number of configured groups is usually related to the number of tasks to be downloaded when the App is started, that is, the number of tasks to be downloaded is different under different services and can be set according to business requirements; among them, the size of each group of tasks can be calculated according to Math.max(CPU number / 2 - 1, 2).
[0072] For example, if the current tasks to be downloaded are 30 and the CPU of the mobile device is 8, it is calculated that each group of tasks is 3. When the tasks to be downloaded first need to be divided into 10 groups, the number of download tasks added to the download process at one time is 3.
[0073] The task processing method provided by the embodiment of the present application inserts the download tasks with special priorities to the forefront of the download task queue, ensuring that the download tasks with special priorities can obtain the priority scheduling and execution rights, so that important resource files can be quickly downloaded to the local, thereby significantly improving the execution efficiency of the download tasks and greatly improving the overall user experience.
[0074] Figure 2 It is a schematic flowchart of another task processing method provided by the embodiment of the present application, as Figure 2 shown. This method specifically includes:
[0075] S201. When there are download tasks with non-target priorities among the multiple download tasks, insert the download tasks with non-target priorities to the corresponding positions in the download task queue to complete the sequential update of the download task queue, where the non-target priorities include multiple level identifiers, and the download tasks corresponding to different level identifiers of non-target priorities are in different positions in the download task queue;
[0076] In this embodiment, for those download tasks that do not belong to the target priority level, that is, the normal priority level, a grouping strategy based on the priority of the task download object is adopted, and the corresponding number of non-target priority levels are created. The download tasks in these levels are grouped according to their respective priorities, and then, according to the priority level differences among the download task groups, they are inserted into the appropriate positions in the download task queue, ensuring that the download task groups of each priority level can be executed in a certain order, thus effectively managing the execution process of the download tasks.
[0077] S202. When the download process completes the current download task, sequentially retrieve the download tasks from the updated download task queue and perform the download operation.
[0078] In this embodiment, after the download process successfully completes the current download task, automatically select the next download task to be executed in sequence from the updated and refreshed download task queue. When it reaches the priority level corresponding to the non-target priority, sequentially perform the task retrieval operation for the non-target priority download tasks.
[0079] The task processing method provided in the embodiment of the present application, for the download tasks with normal priority, through a reasonable grouping strategy and priority sorting, inserts the download tasks into the appropriate positions in the download task queue according to their respective priorities and attributes, thus ensuring that the download tasks can be executed in a certain order, not only improving the execution efficiency of the download tasks, but also avoiding the problem that important resources cannot be downloaded in time due to message channel congestion, and further enhancing the user's download experience.
[0080] In an alternative solution of the embodiment of the present invention, the target priority is the highest priority, and the download tasks with the target priority include at least one first download subtask;
[0081] In this embodiment, the target priority is set to the highest priority, and the download tasks with the target priority will obtain the highest allocation of system resources. To ensure that these tasks can be completed efficiently and preferentially, the download tasks with the target priority will be further divided into at least one first download subtask according to their reception time, and processed sequentially or in parallel to ensure the smooth and efficient progress of the entire download process.
[0082] Figure 3 It is a schematic flowchart of a method for inserting a target priority download task into a download task queue provided in the embodiment of the present application, as Figure 3 shown. The method specifically includes:
[0083] S301. Obtain the reception time of at least one first download subtask included in the download task;
[0084] In this embodiment, in order to ensure precise monitoring and management of the execution process of the download task, the reception time of at least one first download subtask included is acquired, and the reception moment of each subtask is traced.
[0085] S302. Based on the reception time, perform sorting and combination processing on all the first download subtasks included in the download task to obtain a first download group;
[0086] In this embodiment, the download subtasks are sorted based on the reception time of all the first download subtasks included in the download task, ensuring that the download subtasks can be combined into an ordered first download group in the order of reception. Then, taking the first download group as a whole not only simplifies the complexity of task management but also improves the flexibility and efficiency of task execution, enabling users to obtain the resources they need faster.
[0087] S303. Insert the first download group to the head of the download task queue.
[0088] In this embodiment, the entire first download group is inserted to the very front of the download task queue, ensuring that the first download subtasks can be scheduled and executed sequentially and quickly, thereby further improving the execution efficiency of the download task and the user experience.
[0089] A method for inserting a target-priority download task into a download task queue provided by an embodiment of the present application, by dividing the target-priority download task into multiple first download subtasks, sorting and combining them according to the reception time to obtain an ordered first download group, and then inserting the group as a whole to the very front of the download task queue, not only simplifies the task management process but also improves the efficiency and flexibility of task execution. By preferentially executing the first download group, it is ensured that users can obtain important resources faster, thereby enhancing user satisfaction and experience.
[0090] Figure 4 The flowchart of a method for inserting a non-target-priority download task into a download task queue provided by an embodiment of the present application is as Figure 4 shown, and the method specifically includes:
[0091] S401. Determine whether there is a download subtask with a preset priority in the non-target-priority download task, and the level identifier of the preset priority is a target level identifier;
[0092] Set an independent special priority for non-target priorities, that is, the preset priority. Store the data with this special priority separately in a LinkedList as an independent group, without being restricted by the number of groups. The purpose of doing this is to ensure the priority download of important resources (not triggered by manual clicks).
[0093] For example, for files that are not triggered by manual clicks but are very important. Such as the playback kernel so library of the App, it must be downloaded with the highest priority after the App starts to ensure the experience of the app function. Set the task priority for downloading such resources as an independent special priority, that is, the preset priority, to ensure its high-priority download. Considering that there will not be too many such tasks and their importance, the storage queue uses a special queue and does not limit its length.
[0094] In this embodiment, corresponding priorities should be set in advance for critical files so that when a download task is received, the urgency of the task can be quickly identified and distinguished. The data with the preset priority usually affects the normal operation of the system or the data of the page function. When a download task with a non-target priority is received, use the level identifier corresponding to the preset priority to make a judgment to effectively identify whether the download task contains a subtask that matches the preset priority, that is, the download subtask whose level identifier conforms to the target level identifier.
[0095] S402. When there is a download subtask with a preset priority in the download task, insert the download subtask with the preset priority into the corresponding position in the download task queue, and re-execute the step of judging whether there is a download subtask with a preset priority for the remaining non-target priority download tasks;
[0096] In this embodiment, during the execution of the download task, if it is found that there is a download subtask with a preset priority, the download subtask with the preset priority will be inserted into the appropriate position in the download task queue according to the established priority order. Subsequently, the remaining download subtasks that have not been inserted into the download task queue re-execute the judgment step of the preset priority to ensure that the remaining non-target priority download tasks no longer contain download subtasks with the preset priority, so as to separate the download subtasks with the preset priority and the non-preset priority for processing to ensure that the entire download process can be carried out efficiently and orderly.
[0097] S403. When there is no download subtask with a preset level in the download task, insert the non-preset priority download subtasks into the corresponding positions in the download task queue according to their respective priority levels.
[0098] In this embodiment, in order to ensure the efficient execution of the download task, it is necessary to insert the download subtasks without pre-set priorities into the corresponding positions in the download task queue according to their respective priority levels.
[0099] Specifically, the task insertion process involves the evaluation of task priorities and the queue so that they will not be delayed by low-priority tasks. In actual operation, through an intelligent scheduling algorithm, the status of the task queue is monitored in real time, and the task order can be intelligently rearranged according to the urgency of the tasks and resource requirements, which not only improves the download efficiency but also optimizes the resource allocation, ensuring the smoothness and efficiency of the entire download process.
[0100] The method for inserting non-target-priority download tasks into the download task queue provided by the embodiment of the present application can flexibly set the level identifier and target level identifier of the preset priority according to actual needs by setting a preset priority for key files to adapt to the download requirements in different scenarios, and perform intelligent identification and scheduling during the download process to ensure that these key files can be quickly downloaded and completed, thus ensuring the timely activation of the application program function and the smoothness of the user experience. In addition, the method also effectively avoids the problem that important resources cannot be downloaded in time due to message channel congestion by dynamically adjusting the task order in the task queue, further improving the execution efficiency of the download task and the user's satisfaction.
[0101] Figure 5 FIG. is a schematic flowchart of a method for inserting a preset-priority download task into a download task queue provided by an embodiment of the present application. As Figure 5 shown, the method specifically includes:
[0102] S501. Perform sorting and combination processing on the download subtasks with the preset priority to obtain a second download group;
[0103] In this embodiment, when performing sorting and combination processing on the download subtasks with the preset priority, ensure that each task can be reasonably arranged according to its importance and urgency, ensuring that users can obtain the most needed data at the fastest speed.
[0104] S502. Determine whether there is a first download group in the download task queue;
[0105] In this embodiment, after sorting the download subtasks with the preset priority to obtain a second download group, it is also necessary to determine whether there is already a first download group with the target priority in the download task queue to determine the insertion position of the second download group in the queue.
[0106] S503. When there is a first download group in the download task queue, insert the second download group at the position after the first download group in the download task queue, so that after the task retrieval of the first download group is completed, the task retrieval of the second download group is sequentially executed;
[0107] In this embodiment, if there is a task in the first download group in the download task queue, since this group has the highest priority, it is necessary to ensure that the tasks in the first download group can be retrieved and executed first when processing the download tasks; therefore, in order to maintain the sequential execution of tasks, the tasks of the second download group are inserted into the queue to ensure that the second task group is located after the tasks of the first download group, so that after the tasks of the first download group are completely processed, the system will automatically retrieve and execute the tasks in the second download group according to the queue order, ensuring the priority and sequentiality of task execution.
[0108] S504. When there is no first download group in the download task queue, insert the second download group at the head of the download task queue.
[0109] In this embodiment, if there is no task in the first download group in the download task queue, at this time, the second download group is the download task with the highest priority in the download task queue. Insert the second download group at the head of the download task queue so that the download subtasks in the second download group perform download processing prior to other non-target subtasks, thereby ensuring that the key functions of the application can be enabled in a timely manner and improving the user experience.
[0110] The method for inserting a preset priority download task into the download task queue provided by the embodiment of the present application, through a reasonable sorting and grouping strategy, arranges and combines the download subtasks with preset priorities in an orderly manner, ensuring that key resources can be quickly downloaded and used; at the same time, according to the current state of the download task queue, determine the insertion position of the second download group in the queue, which not only ensures the priority of task execution but also maintains the sequentiality of task execution, avoiding problems such as resource download delay or conflict caused by improper task scheduling; this method also effectively improves the execution efficiency of download tasks and the utilization rate of resources by dynamically adjusting the task order in the task queue, further enhancing user satisfaction and experience.
[0111] Figure 6 FIG. is a schematic flowchart of a method for inserting a non-preset priority download task into a download task queue provided by an embodiment of the present application. As Figure 6 shown, the method specifically includes:
[0112] S601. According to the level identifier of the non-preset priority, determine at least one-level task sub-priority included in the non-preset priority;
[0113] In this embodiment, according to the level identifier of the non - preset priority, at least one level of task sub - priorities actually covered by the preset priority is determined. The sub - priorities help to further refine and clarify the execution order and importance of tasks.
[0114] It should be noted that in this embodiment, the establishment of task sub - priorities is automatically assigned based on the characteristics of the task itself and user requirements to ensure that each task can be properly processed. When the user receives a download sub - task, the corresponding task sub - priority can be directly obtained.
[0115] S602. Determine the single - group task volume according to the pre - set download configuration information;
[0116] In this embodiment, when planning the file download task, according to the pre - set download configuration information, the specific download volume of each group of tasks is determined. The number of configured groups is usually related to the number of tasks to be downloaded when the App starts. That is, the number of tasks to be downloaded is different under different services and can be set according to business requirements. The size of each group of tasks can be calculated according to Math.max(CPU number / 2 - 1, 2); for example: if the current number of tasks to be downloaded is 30 and the CPU of the mobile device is 8, it can be calculated that each group of tasks is 3, and then 10 groups need to be divided.
[0117] Specifically, multiple factors such as network conditions, the server's bearing capacity, and the user's download requirements need to be considered to ensure that the allocation of each group of tasks is both reasonable and efficient, guarantee the smooth progress of the download task, avoid resource waste or task delay caused by too large or too small task volume, improve the download efficiency, and greatly optimize the user's download experience.
[0118] In addition, this embodiment sets the default file size according to the file download type (such as zip, mp4, jpeg) to balance the number of tasks in each group of download tasks as much as possible.
[0119] S603. Based on the reception time of the download sub - tasks included in each level of task sub - priority and the single - group task volume, perform sorting and combination processing on the download sub - tasks included in each level of task sub - priority to obtain a third download sub - grouping set corresponding to each level of task sub - priority;
[0120] In this embodiment, when processing the download task, first consider the reception time of the download sub - tasks included in each level of task sub - priority and the specific situation of the single - group task volume, and then perform detailed sorting and combination processing on the download sub - tasks included in each level of task sub - priority, effectively classifying the download sub - tasks according to the priority to obtain a third download sub - grouping set corresponding to each level of task sub - priority, so as to manage the download task more efficiently and ensure that high - priority tasks can be processed in a timely manner.
[0121] Taking the single - group task volume of 3 as an example, during the process of downloading the sub - task combination, the added tasks find their corresponding queue positions according to the priorities of the tasks, and are inserted at the end of the queue positions corresponding to their priorities. Each queue only supports adding 3 tasks. If it exceeds, the tail element of the queue needs to be moved to the next queue. If the next queue also exceeds, continue to move the tail element of the next queue to the queue behind it, and so on until no element exceeds, achieving a relative balance in the number of queue tasks and not causing a certain queue to be too long due to the addition of tasks, thus affecting the scheduling strategy.
[0122] S604. According to the priority levels of each third download sub - group included in the third download sub - group set, insert each third download sub - group included in the third download sub - group set into the corresponding positions in their respective download task queues.
[0123] In this embodiment, when executing the download task, first analyze the priority levels of each third download sub - group included in the third download sub - group set, and then insert each third download sub - group into the download task queue in an orderly manner according to the priority levels, ensuring that the download tasks are executed in order of importance, thus optimizing the user experience, reducing the waiting time for important resources, and improving the overall download efficiency.
[0124] The method for inserting non - preset - priority download tasks into the download task queue provided by the embodiment of the present application, through task sub - priority division and sorting combination, schedules the non - preset - priority download tasks in an orderly manner. According to the level identifiers of the non - preset priorities, clarify the task sub - priorities of each level, ensuring the refinement and accuracy of task execution. Then, according to the pre - set download configuration information, determine the specific download volume of each group of tasks, ensuring the rationality and efficiency of task allocation. Further, in combination with the reception time of the download sub - tasks included in each level of task sub - priority and the single - group task volume, perform sorting and combination processing on the download sub - tasks to obtain the third download sub - group set corresponding to each level of task sub - priority. Finally, according to the priority levels of each group in the third download sub - group set, insert them into the download task queue in an orderly manner, realizing the intelligent scheduling and efficient execution of the download tasks, and enhancing the user's satisfaction and experience.
[0125] In an alternative solution of the embodiment of the present invention, before the execution of the download operation, the method further includes:
[0126] Determine the current callback task, where the callback task is the download task that is currently performing task scheduling in the download task queue;
[0127] When the scheduling result is normal download, add the current callback task to the download process to complete the download operation of the current callback task;
[0128] When the scheduling result is waiting for download, predict the download waiting duration, and after the waiting duration, add the current callback task to the download task queue again, and re - execute the task scheduling of the current callback task to complete the re - download of the current callback task.
[0129] In this embodiment, before performing the download operation on the task, clarify the currently executing task scheduling. When the scheduling result indicates that the download operation is proceeding normally, add the current callback task to the download process to complete the download part of this current callback task. When the scheduling result indicates waiting for download, estimate a download waiting time length, and after the waiting time, re - place the current callback task into the download task queue, and then execute the task scheduling again to complete the download process of the current callback task.
[0130] Specifically, taking the single - group task volume of 3 as an example, during the callback process, for the download tasks of the target priority, first take 3 of them (according to the configuration) and add them to the download process through IPC for task download. After a single task is downloaded and completed, take the head task from the queue and call IPC to add it to the download process for download; if there are newly added special - priority tasks during the download process, they will be added to the download process through IPC after a certain task download in the download process is completed to ensure the high - priority download of this type of task.
[0131] For the download tasks of non - target priority, add the first group of download tasks (this first group of download tasks is the first group of tasks executed in non - target - priority order rather than the above - mentioned first download group, and the same applies to the following download task groups) to the download process through IPC, and record the current time. Calculate the download speed V based on the download callback time of the first task in the first group and the size or estimated size of this file. At the same time, when the first task in the first group is called back, add the second group of tasks to the download process queue for download and calculate the longest estimated completion time T1 of this group of tasks based on this download speed; for the second group of tasks, if there is a callback indicating that a task is completed within the T1 time, add the third group of tasks to the download process and calculate the longest estimated completion time T2 of this group of tasks based on this download speed V. If there is no callback indicating that a task is completed within the T1 time, still add the third group of tasks to the download process at the T1 time (waiting timeout time) and calculate the longest estimated completion time T2 of this group of tasks based on this download speed V. Repeat the above operations until all tasks are completely scheduled.
[0132] It should be noted that the download progress of a single download task is monitored regularly. After the task is added to the download process, the task progress is detected every 2 seconds (reading the task scheduling policy configuration). If the task progress is still 0, the task needs to be retried once and added to the download process again for downloading. In addition, according to the task scheduling policy configuration read, the retry count limit for a single task is set to avoid infinite retries due to resource unavailability for download.
[0133] Further, after the download process receives the main process task, it parses the data and calls the download method for downloading; specifically, after the download process receives the main process task, since the data may be compressed and passed to the same object, it needs to be parsed and split into individual tasks according to the agreed rules, and then the download method is called for each task to download concurrently and the download progress is called back for subsequent UI rendering.
[0134] Figure 7 It is a flowchart of a task processing method provided by an embodiment of the present application, as Figure 7 shown, Service A, Service B, and Service C submit download tasks to the framework respectively. The service tasks will then be added to the task queue within the framework. Among them, the task queue consists of multiple nodes (Q1 to Qn). The submitted tasks will wait for processing in the task queue. The tasks are placed in the appropriate position in the queue. After being processed by the task queue, the tasks will be transferred to the download process queue. The download process queue in the figure contains three processing units, T1, T2, and T3, which are responsible for executing the download tasks and task callbacks. After the download process completes the download task, it will call back the result, thus completing the entire download task processing flow.
[0135] Figure 8 It is a flowchart of the process steps of a task processing method provided by an embodiment of the present application, as Figure 8 shown, the method specifically includes the following steps:
[0136] Initialization and data acquisition: First, initialize the framework, and then obtain the configuration data to prepare for subsequent processing.
[0137] Task processing and judgment: After obtaining the data, process the download task, and then judge whether it is the first time to process the addition of the download task; if it is the first time, the download tasks will be sorted according to the priority, then the download tasks will be grouped, and then the download task queue will be determined; if it is not the first time, it will directly enter the waiting for the addition of the download task.
[0138] Task scheduling and execution: During the waiting process, if there is a downloadable task to be scheduled, the download task will be scheduled according to the established policy, the task will be transmitted and added to the download process, then the download process will execute the download task, and finally the download process will call back the download result to end the process; if there is no schedulable task, it will continue to wait for the addition of new tasks.
[0139] Figure 9 A schematic structural diagram of a task processing device provided by an embodiment of the present application is as follows Figure 8 shown, and the device specifically includes:
[0140] An acquisition module 901, configured to acquire a plurality of download tasks received within a preset time period, and the task priority corresponding to each download task;
[0141] A first insertion module 902, configured to insert the download task with the target priority to the head of the download task queue when there is a download task with the target priority among the plurality of download tasks, so as to complete the sequential update of the download task queue;
[0142] An invocation module 903, configured to, when the download process completes the current download task, invoke the download task with the target priority from the head of the updated download task queue, and perform a download operation.
[0143] In a possible implementation manner, the device further includes a second insertion module 904 (not shown in the figure), configured to insert the download task with the non-target priority to the corresponding position in the download task queue when there is a download task with the non-target priority among the plurality of download tasks, so as to complete the sequential update of the download task queue, where the non-target priority includes a plurality of level identifiers, and the download tasks corresponding to different level identifiers of the non-target priority are in different positions in the download task queue; when the download process completes the current download task, sequentially invoke the download tasks from the updated download task queue, and perform a download operation.
[0144] In a possible implementation manner, the first insertion module 902 is further configured to acquire the reception time of at least one first download subtask included in the download task; based on the reception time, perform a sorting and combining process on all the first download subtasks included in the download task, obtain a first download group; and insert the first download group to the head of the download task queue.
[0145] In a possible implementation manner, the second insertion module 904 is further configured to determine whether there is a download subtask with a preset priority in the download task with the non-target priority, and the level identifier of the preset priority is the target level identifier; when there is a download subtask with the preset priority in the download task, insert the download subtask with the preset priority to the corresponding position in the download task queue, and re-execute the step of determining whether there is a download subtask with the preset priority for the remaining download tasks with the non-target priority; when there is no download subtask with the preset level in the download task, insert the download subtasks with the non-preset priority to the corresponding positions in the download task queue according to their respective priority levels.
[0146] In a possible implementation, the second insertion module 904 is further configured to perform sorting and combining processing on the download subtasks with the preset priority to obtain a second download group; determine whether there is a first download group in the download task queue; when there is a first download group in the download task queue, insert the second download group into the position after the first download group in the download task queue, so that after the task retrieval of the first download group is completed, the task retrieval of the second download group is sequentially executed; when there is no first download group in the download task queue, insert the second download group into the head of the download task queue.
[0147] In a possible implementation, the second insertion module 904 is further configured to determine at least one-level task sub-priority included in the non-preset priority according to the level identifier of the non-preset priority; determine the single-group task volume according to the pre-set download configuration information; based on the reception time of the download subtasks included in each level of task sub-priority and the single-group task volume, perform sorting and combining processing on the download subtasks included in each level of task sub-priority to obtain a set of third download sub-groups corresponding to each level of task sub-priority; insert each third download sub-group included in the set of third download sub-groups into the corresponding position in the respective download task queues according to the priority level of each third download sub-group included in the set of third download sub-groups.
[0148] In a possible implementation, the retrieval module 903 is further configured to determine a current callback task, where the callback task is a download task that is currently performing task scheduling in the download task queue; in the case where the scheduling result is normal download, add the current callback task to the download process to complete the download operation of the current callback task; in the case where the scheduling result is waiting for download, predict the download waiting duration, and after the waiting duration, add the current callback task to the download task queue again, and re-execute the task scheduling of the current callback task to complete the re-download of the current callback task.
[0149] The task processing device provided in this embodiment may be a task processing device as shown in Figure 9 and can execute all steps of task processing as shown in Figure 1-8 to achieve the technical effects of task processing as shown in Figure 1-8 For specific reference, please refer to Figure 1-8 the relevant description. For the sake of concise description, it will not be elaborated here.
[0150] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0151] Figure 10 The following is a schematic structural diagram of an electronic device provided by an embodiment of the present application. As Figure 10 shown, an embodiment of the present application provides an electronic device, including a processor 1001, a communication interface 1002, a memory 1003, and a communication bus 1004. Among them, the processor 1001, the communication interface 1002, and the memory 1003 communicate with each other through the communication bus 1004; the memory 1003 is used to store a computer program; when the processor 1001 executes the program stored in the memory 1003, it implements the steps of task processing provided by any one of the foregoing method embodiments:
[0152] Obtain a plurality of download tasks received within a preset time period, and the task priority corresponding to each download task; when there is a download task with a target priority among the plurality of download tasks, insert the download task with the target priority to the head of the download task queue to complete the sequential update of the download task queue; when the download process completes the current download task, retrieve the download task with the target priority from the head of the updated download task queue and execute the download operation.
[0153] In a possible implementation manner, when there is a download task with a non-target priority among the plurality of download tasks, insert the download task with the non-target priority to the corresponding position in the download task queue to complete the sequential update of the download task queue, where the non-target priority includes multiple level identifiers, and the download tasks corresponding to different non-target priorities with level identifiers are in different positions in the download task queue; when the download process completes the current download task, sequentially retrieve the download tasks from the updated download task queue and execute the download operation.
[0154] In a possible implementation manner, obtain the reception time of at least one first download subtask included in the download task; based on the reception time, perform sorting and combination processing on all the first download subtasks included in the download task to obtain a first download group; insert the first download group to the head of the download task queue.
[0155] In a possible implementation, determine whether there is a download subtask with a preset priority in the download tasks with non-target priorities, where the level identifier of the preset priority is the target level identifier; when there is a download subtask with a preset priority in the download tasks, insert the download subtask with the preset priority into the corresponding position in the download task queue, and re-execute the step of determining whether there is a download subtask with a preset priority for the remaining download tasks with non-target priorities; when there is no download subtask with a preset priority in the download tasks, insert the download subtasks with non-preset priorities into the corresponding positions in the download task queue according to their respective priority levels.
[0156] In a possible implementation, perform sorting and grouping processing on the download subtasks with the preset priority to obtain a second download group; determine whether there is a first download group in the download task queue; when there is a first download group in the download task queue, insert the second download group into the position after the first download group in the download task queue, so that after the tasks of the first download group are retrieved, the tasks of the second download group are retrieved sequentially; when there is no first download group in the download task queue, insert the second download group into the head of the download task queue.
[0157] In a possible implementation, according to the level identifier of the non-preset priority, determine at least one level of task sub-priority included in the non-preset priority; determine the single-group task quantity according to the pre-set download configuration information; based on the reception time of the download subtasks included in each level of task sub-priority and the single-group task quantity, perform sorting and grouping processing on the download subtasks included in each level of task sub-priority to obtain a set of third download sub-groups corresponding to each level of task sub-priority; insert each third download sub-group included in the set of third download sub-groups into the corresponding position in the respective download task queues according to the priority level of each third download sub-group included in the set of third download sub-groups.
[0158] In a possible implementation, determine the current callback task, where the callback task is the download task that is currently performing task scheduling in the download task queue; in the case where the scheduling result is normal download, add the current callback task to the download process to complete the download operation of the current callback task; in the case where the scheduling result is waiting for download, predict the download waiting duration, and after the waiting duration, add the current callback task to the download task queue again and re-execute the task scheduling of the current callback task to complete the re-download of the current callback task.
[0159] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the essence of the above technical solution, or the part that contributes to the related technology, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0160] It should be understood that the terms used herein are for the purpose of describing specific example embodiments only and are not intended to be limiting. Unless the context clearly indicates otherwise, as used herein, the singular forms "a", "an", and "the" may also include the plural forms. The terms "include", "comprise", "contain", and "have" are inclusive and thus specify the presence of the stated features, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, steps, operations, elements, components, and / or their combinations. The method steps, processes, and operations described herein are not to be construed as necessarily requiring them to be performed in the particular order described or illustrated, unless the order of performance is explicitly stated. It should also be understood that additional or alternative steps may be used.
[0161] The above are only specific embodiments of the present invention, enabling those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to these embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A task processing method, characterized in that, Including: Obtaining a plurality of download tasks received within a preset time period, and the task priority corresponding to each download task; When there is a download task with a target priority among the plurality of download tasks, inserting the download task with the target priority to the head of the download task queue to complete the sequential update of the download task queue; When the download process completes the current download task, retrieving the download task with the target priority from the head of the updated download task queue and performing a download operation.
2. The method according to claim 1, characterized in that, The method further includes: When there is a download task with a non-target priority among the plurality of download tasks, inserting the download task with the non-target priority to the corresponding position in the download task queue to complete the sequential update of the download task queue, where the non-target priority includes a plurality of level identifiers, and the download tasks corresponding to different level identifiers of the non-target priority are in different positions in the download task queue; When the download process completes the current download task, sequentially retrieving download tasks from the updated download task queue and performing a download operation.
3. The method according to claim 1, wherein The target priority is the highest priority, and the download task with the target priority includes at least one first download subtask; The inserting the download task with the target priority to the head of the download task queue includes: Obtaining the reception time of at least one first download subtask included in the download task; Based on the reception time, performing a sorting and combining process on all the first download subtasks included in the download task to obtain a first download group; Inserting the first download group to the head of the download task queue.
4. The method according to claim 2, characterized in that, The inserting the download task with the non-target priority to the corresponding position in the download task queue includes: Determining whether there is a download subtask with a preset priority in the download task with the non-target priority, where the level identifier of the preset priority is the target level identifier; When there is a download subtask with a preset priority in the download task, inserting the download subtask with the preset priority to the corresponding position in the download task queue, and re-performing the step of determining whether there is a download subtask with a preset priority on the remaining download tasks with the non-target priority; When there is no download subtask with a preset level in the download task, inserting the download subtasks with non-preset priorities to the corresponding positions in the download task queue according to their respective priority levels.
5. The method according to claim 3 or 4, characterized in that, The inserting the download subtask with the preset priority to the corresponding position in the download task queue includes: Performing a sorting and combining process on the download subtasks with the preset priority to obtain a second download group; Determining whether there is a first download group in the download task queue; When there is a first download group in the download task queue, inserting the second download group to the position after the first download group in the download task queue, so that after the tasks of the first download group are retrieved, the tasks of the second download group are sequentially retrieved; When there is no first download group in the download task queue, inserting the second download group to the head of the download task queue.
6. The method according to claim 4, characterized in that, Inserting the download subtasks with non - preset priorities into corresponding positions in the download task queue according to their respective priority levels includes: Determining at least one - level task sub - priority included in the non - preset priority according to the level identifier of the non - preset priority; Determining the single - group task quantity according to the pre - set download configuration information; Performing sorting and combination processing on the download subtasks included in each level of task sub - priority based on the reception time of the download subtasks included in each level of task sub - priority and the single - group task quantity, to obtain a third download sub - group set corresponding to each level of task sub - priority; Inserting each third download sub - group included in the third download sub - group set into the corresponding position in the respective download task queue according to the priority level of each third download sub - group included in the third download sub - group set.
7. The method according to claim 1, wherein Before performing the download operation, the method further includes: Determining the current callback task, where the callback task is the download task that is performing task scheduling in the download task queue; In the case where the scheduling result is normal download, adding the current callback task to the download process to complete the download operation of the current callback task; In the case where the scheduling result is waiting for download, predicting the download waiting duration, and after the waiting duration, re - adding the current callback task to the download task queue and re - executing the task scheduling of the current callback task to complete the re - download of the current callback task.
8. A task processing device, characterized in that, Including: An acquisition module, configured to acquire a plurality of download tasks received within a preset time period, and the task priority corresponding to each download task; A first insertion module, configured to, when there is a download task with a target priority among the plurality of download tasks, insert the download task with the target priority to the head of the download task queue to complete the sequential update of the download task queue; An extraction module, configured to, when the download process completes the current download task, extract the download task with the target priority from the head of the updated download task queue and perform the download operation.
9. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the task processing method according to any one of claims 1 - 7.
10. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the task processing method according to any one of claims 1 - 7.