• Home
Name
Date
Size
#Lines
LOC

..--

frameworks/12-May-2024-2,0081,427

interfaces/kits/js/12-May-2024-2,1051,365

sa_profile/12-May-2024-6951

services/12-May-2024-5,0953,836

utils/12-May-2024-1,100771

LICENSED12-May-202410.1 KiB177150

OAT.xmlD12-May-20245.7 KiB8534

README.mdD12-May-20245 KiB9868

README_ZH.mdD12-May-20244.4 KiB9768

bundle.jsonD12-May-20242.2 KiB6362

workscheduler.gniD12-May-20241 KiB3121

README.md

1# Work Scheduler
2
3-   [Introduction](#section11660541593)
4-   [Directory Structure](#section161941989596)
5-   [Work Scheduler](#section1312121216216)
6    -   [Available APIs](#section114564657874)
7    -   [Usage Guidelines](#section129654513264)
8        -   [Restrictions on Using Work Scheduler](#section1551164914237)
9
10-   [Repositories Involved](#section1371113476307)
11
12## Introduction<a name="section11660541593"></a>
13
14When an application needs to perform tasks that do not require high real-time performance, such as data learning when the device is idle, the work scheduler can be used. When the application setting conditions are met, the mechanism will uniformly decide the scheduling time according to the current state of the system, such as memory, power consumption, heat, etc.
15
16## Directory Structure<a name="section161941989596"></a>
17
18```
19
20├── frameworks       # Frameworks
21├── interfaces
22│   └── kits         # External APIs
23├── sa_profile       # SA profile
24├── services         # Services
25└── utils            # Utilities
26
27```
28## Work Scheduler<a name="section1312121216216"></a>
29
30### Available APIs<a name="section114564657874"></a>
31
321. The members of WorkInfo
33
34 API                                                          | Description | Type
35  ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------
36workId | The id of work(required)|number
37bundleName | The bundle name(required)|string
38abilityName | The ability name(required)|string
39networkType | The type of network | NetworkType
40isCharging | Is charging. | bool
41chargerType | The charging type. | ChargingType
42batteryLevel | The  battery | number
43batteryStatus| The battery status |	BatteryStatus
44storageRequest|The storage status|	StorageRequest
45isRepeat|Is repeating work |	boolean
46repeatCycleTime | The repeating cycle time|	number
47repeatCount	| The repeating cycle count| number
48
49
502. The api of work scheduler for starting, stopping and querying.
51
52 API                                                          | Description
53 ------------------------------------------------------------ | ------------------------------------------------------------
54 function startWork(work: WorkInfo): boolean;                 | work scheduler application
55 function stopWork(work: WorkInfo, needCancel?: boolean): boolean; | work scheduler cancel
56 function getWorkStatus(workId: number, callback: AsyncCallback<WorkInfo>): void; | get the status of work(Callback form)
57 function getWorkStatus(workId: number): Promise<WorkInfo>;   | get the status of work(Promise form)
58 function obtainAllWorks(callback: AsyncCallback<void>): Array<WorkInfo>; | get all works(Callback form)
59 function obtainAllWorks(): Promise<Array<WorkInfo>>;         | get all works(Promise form)
60 function stopAndClearWorks(): boolean;                       | stop and clear work
61 function isLastWorkTimeOut(workId: number, callback: AsyncCallback<void>): boolean; | Get whether the last task has timed out(For repeat work. Callback form)
62 function isLastWorkTimeOut(workId: number): Promise<boolean>; | Get whether the last task has timed out(For repeat work. Promise form)
63
643. Callback api of work scheduler
65
66API                                                          | Description
67 ------------------------------------------------------------ | ------------------------------------------------------------
68 function onWorkStart(work: WorkInfo): void;                 | Callback when work starts.
69 function onWorkStop(work: WorkInfo): void;                 | Callback when work stops.
70
71### Usage Guidelines<a name="section129654513264"></a>
72
73When an application needs to perform tasks with low real-time performance, work scheduler  can be used. When the conditions set by the application are met, the mechanism will make a unified decision and scheduling time based on the current state of the system, such as memory, power consumption, and heat.
74
75#### Restrictions on Using Work Scheduler<a name="section1551164914237"></a>
76
77Adhere to the following constraints and rules when using work scheduler:
78
79- **Timeout**:The longest running time is 120s each time.
80- **Restrict to WorkInfo**:
81
82(1) WorkId, bundleName and abilityName are required.
83
84(2) At least one condition must be set.
85
86(3) Repeatcycletime should be at least 20 minutes. When setting repeatcycletime, you must select one of isrepeat and repeatcount.
87
88## Repositories Involved<a name="section1371113476307"></a>
89
90Resource Schedule subsystem
91
92**work\_scheduler**
93
94notification_ces_standard
95
96appexecfwk_standard
97
98powermgr_battery_manager

README_ZH.md

1# 延迟任务调度
2
3-   [简介](#section11660541593)
4-   [目录](#section161941989596)
5-   [延迟任务调度](#section1312121216216)
6    -   [接口说明](#section114564657874)
7    -   [使用说明](#section129654513264)
8        -   [延迟任务调度使用约束](#section1551164914237)
9
10-   [相关仓](#section1371113476307)
11
12## 简介<a name="section11660541593"></a>
13
14在资源调度子系统中,延迟任务调度部件给应用提供一个可以执行实时性不高的任务的机制。当满足设定条件时,会被放入可执行队列,系统根据设备情况,延迟触发可执行队列内的任务。
15
16## 目录<a name="section161941989596"></a>
17
18```
19
20├── frameworks       # 客户端模块
21├── interfaces
22│   └── kits         # 对外接口模块
23├── sa_profile       # 组件服务配置
24├── services         # 服务端模块
25└── utils            # 工具类、可维可测模块
26
27```
28## 延迟任务调度<a name="section1312121216216"></a>
29
30### 接口说明<a name="section114564657874"></a>
311、延迟任务WorkInfo成员接口
32
33接口名|接口描述|类型
34---------------------------------------------------------|-----------------------------------------|---------------------------------------------------------
35workId | 延迟任务Id(必填)|number
36bundleName | 延迟任务包名(必填)|string
37abilityName | 延迟任务回调通知的组件名(必填)|string
38networkType | 网络条件 | NetworkType
39isCharging | 是否充电 | bool
40chargerType | 充电类型 | ChargingType
41batteryLevel | 电量| number
42batteryStatus| 电池状态|	BatteryStatus
43storageRequest|存储状态|	StorageRequest
44isRepeat|是否循环任务|	boolean
45repeatCycleTime |循环间隔|	number
46repeatCount	|循环次数| number
47
48
492、延迟任务注册、取消、查询等相关接口
50
51接口名                                                    |     接口描述
52---------------------------------------------------------|-----------------------------------------
53function startWork(work: WorkInfo): boolean; | 延迟调度任务申请
54function stopWork(work: WorkInfo, needCancel?: boolean): boolean;        | 延迟调度任务取消
55function getWorkStatus(workId: number, callback: AsyncCallback<WorkInfo>): void;| 获取延迟调度任务状态(Callback形式)
56function getWorkStatus(workId: number): Promise<WorkInfo>; | 获取延迟调度任务状态(Promise形式)
57function obtainAllWorks(callback: AsyncCallback<void>): Array<WorkInfo>;| 获取所有延迟调度任务(Callback形式)
58function obtainAllWorks(): Promise<Array<WorkInfo>>;| 获取所有延迟调度任务(Promise形式)
59function stopAndClearWorks(): boolean;| 停止并清除任务
60function isLastWorkTimeOut(workId: number, callback: AsyncCallback<void>): boolean;| 获取上次任务是否超时(针对RepeatWork,Callback形式)
61function isLastWorkTimeOut(workId: number): Promise<boolean>;| 获取上次任务是否超时(针对RepeatWork,Promise形式)
62
633、延迟任务回调接口
64
65接口名                                                    |     接口描述
66---------------------------------------------------------|-----------------------------------------
67function onWorkStart(work: WorkInfo): void; | 延迟调度任务回调开始
68function onWorkStop(work: WorkInfo): void; | 延迟调度任务回调结束
69
70
71### 使用说明<a name="section129654513264"></a>
72应用要执行对实时性要求不高的任务的时候,比如设备空闲时候做一次数据学习等场景,可以使用延迟调度任务,该机制在满足应用设定条件的时候,会根据系统当前状态,如内存、功耗、热等统一决策调度时间。
73
74#### 延迟调度任务使用约束<a name="section1551164914237"></a>
75
76延迟调度任务的使用需要遵从如下约束和规则:
77
78- **超时**:每次最长运行120s。
79- **WorkInfo参数约束**
80
81(1) workId、bundleName、abilityName为必填项
82
83(2)至少要设置一个满足条件
84
85(3)repeatCycleTime至少20分钟,当设置repeatCycleTime时,必须选填isRepeat和repeatCount中的一个。
86
87## 相关仓<a name="section1371113476307"></a>
88
89资源调度子系统
90
91**work\_scheduler**
92
93notification_ces_standard
94
95appexecfwk_standard
96
97powermgr_battery_manager