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## Attributes
18
19**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
20
21| Name | Type | Readable | Writable | Description |
22| -------- | -------- | -------- | -------- | -------- |
23| context<sup>10+</sup> | [WorkSchedulerExtensionContext](js-apis-inner-application-WorkSchedulerExtensionContext.md)  | Yes | No | Context of the **WorkSchedulerExtension**. This context is inherited from **ExtensionContext**. |
24
25## WorkSchedulerExtensionAbility.onWorkStart
26
27onWorkStart(work: workScheduler.WorkInfo): void
28
29Called when the system starts scheduling the deferred task.
30
31**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
32
33**Parameters**
34
35| Name | Type                                      | Mandatory  | Description            |
36| ---- | ---------------------------------------- | ---- | -------------- |
37| work | [workScheduler.WorkInfo](js-apis-resourceschedule-workScheduler.md#workinfo) | Yes   | Deferred task that starts. |
38
39**Example**
40
41  ```ts
42  import { workScheduler } from '@kit.BackgroundTasksKit';
43
44  export default class MyWorkSchedulerExtensionAbility extends WorkSchedulerExtensionAbility {
45    onWorkStart(workInfo: workScheduler.WorkInfo) {
46        console.log('MyWorkSchedulerExtensionAbility onWorkStart' + JSON.stringify(workInfo));
47    }
48  }
49  ```
50
51## WorkSchedulerExtensionAbility.onWorkStop
52
53onWorkStop(work: workScheduler.WorkInfo): void
54
55Called when the system stops scheduling the deferred task.
56
57**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
58
59**Parameters**
60
61| Name | Type                                      | Mandatory  | Description            |
62| ---- | ---------------------------------------- | ---- | -------------- |
63| work | [workScheduler.WorkInfo](js-apis-resourceschedule-workScheduler.md#workinfo) | Yes   | Deferred task that stops. |
64
65
66**Example**
67
68  ```ts
69  import { workScheduler } from '@kit.BackgroundTasksKit';
70
71  export default class MyWorkSchedulerExtensionAbility extends WorkSchedulerExtensionAbility {
72    onWorkStop(workInfo: workScheduler.WorkInfo) {
73        console.log('MyWorkSchedulerExtensionAbility onWorkStop' + JSON.stringify(workInfo));
74    }
75  }
76  ```
77