1# @ohos.WorkSchedulerExtensionAbility (Deferred Task Scheduling Callbacks)
2
3The WorkSchedulerExtensionAbility module provides callbacks for deferred task scheduling. You can override the APIs provided by this module. When a deferred task is triggered, the system calls back the application through the APIs and processes the task logic in the callback.
4
5>  **NOTE**
6>
7>  - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9>  - The APIs of this module can be used only in the stage model.
10
11## Modules to Import
12
13```ts
14import { WorkSchedulerExtensionAbility } from '@kit.BackgroundTasksKit';
15```
16
17## WorkSchedulerExtensionContext<sup>10+</sup>
18
19type WorkSchedulerExtensionContext = _WorkSchedulerExtensionContext
20
21**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
22
23| Type| Description|
24| -------- |  -------- |
25| [_WorkSchedulerExtensionContext](js-apis-inner-application-WorkSchedulerExtensionContext.md)|  Context of the WorkSchedulerExtensionAbility.|
26
27## WorkSchedulerExtensionAbility
28
29### Properties
30
31**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
32
33| Name| Type| Readable| Writable| Description|
34| -------- | -------- | -------- | -------- | -------- |
35| context<sup>10+</sup> | [WorkSchedulerExtensionContext](js-apis-inner-application-WorkSchedulerExtensionContext.md)  | Yes| No| Context of the WorkSchedulerExtensionAbility. This context inherits from **ExtensionContext**.|
36
37### onWorkStart
38
39onWorkStart(work: workScheduler.WorkInfo): void
40
41Called when the system starts scheduling the deferred task.
42
43**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
44
45**Parameters**
46
47| Name | Type                                      | Mandatory  | Description            |
48| ---- | ---------------------------------------- | ---- | -------------- |
49| work | [workScheduler.WorkInfo](js-apis-resourceschedule-workScheduler.md#workinfo) | Yes   | Deferred task that starts.|
50
51**Example**
52
53  ```ts
54  import { workScheduler } from '@kit.BackgroundTasksKit';
55
56  export default class MyWorkSchedulerExtensionAbility extends WorkSchedulerExtensionAbility {
57    onWorkStart(workInfo: workScheduler.WorkInfo) {
58        console.log('MyWorkSchedulerExtensionAbility onWorkStart' + JSON.stringify(workInfo));
59    }
60  }
61  ```
62
63### onWorkStop
64
65onWorkStop(work: workScheduler.WorkInfo): void
66
67Called when the system stops scheduling the deferred task.
68
69**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
70
71**Parameters**
72
73| Name | Type                                      | Mandatory  | Description            |
74| ---- | ---------------------------------------- | ---- | -------------- |
75| work | [workScheduler.WorkInfo](js-apis-resourceschedule-workScheduler.md#workinfo) | Yes   | Deferred task that stops.|
76
77
78**Example**
79
80  ```ts
81  import { workScheduler } from '@kit.BackgroundTasksKit';
82
83  export default class MyWorkSchedulerExtensionAbility extends WorkSchedulerExtensionAbility {
84    onWorkStop(workInfo: workScheduler.WorkInfo) {
85        console.log('MyWorkSchedulerExtensionAbility onWorkStop' + JSON.stringify(workInfo));
86    }
87  }
88  ```
89