---
name: "syncTimerTask"
mode: "kit"
versionRequirements:
  - { name: "DeviceKit", version: "1.2.6" }
  - { name: "@ray-js/ray", version: "0.6.23" }
platform:
  - "iOS"
  - "Android"
async: true
title: "syncTimerTask - 同步定时任务"
---

## syncTimerTask

> [VERSION] DeviceKit >= 1.2.6 | @ray-js/ray >= 0.6.23

> [PLATFORM] iOS, Android

> ⚡ **支持 Promise 调用** — 不传 success / fail / complete 回调时，该方法返回 Promise。

### 描述

同步定时任务

### 参数

| 属性 | 类型 | 必填 | 默认值 | 最低版本 | 描述 |
| --- | --- | --- | --- | --- | --- |
| `deviceId` | `string` | 否 | - | `1.2.6` | deviceId 设备 id ，deviceId 和 groupId 至少传一个 |
| `groupId` | `string` | 否 | - | `1.2.6` | groupId 群组 id ，deviceId 和 groupId 至少传一个 |
| `category` | `string` | 是 | - | `1.2.6` | category 定时分类 |
| `complete` | `() => void` | 否 | - | - | 接口调用结束的回调函数（调用成功、失败都会执行） |
| `success` | `(params: Object) => void` ↓见下方 | 否 | - | - | 接口调用成功的回调函数 |
| `fail` | `(params: Object) => void` ↓见下方 | 否 | - | - | 接口调用失败的回调函数 |

#### success 回调参数

| 属性 | 类型 | 最低版本 | 描述 |
| --- | --- | --- | --- |
| `timers` | `TimerModel[]` | `3.3.0` | timers 定时列表 |

#### fail 回调参数

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `errorMsg` | `string` | 错误信息 |
| `errorCode` | `string \| number` | 错误码 |
| `innerError` | `Object` | 错误扩展 |

##### fail(params).innerError 的属性

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `errorCode` | `string \| number` | 错误扩展码 |
| `errorMsg` | `string` | 错误扩展信息 |


### 引用对象

##### `interface` TimerModel

| 属性 | 类型 | 最低版本 | 描述 |
| --- | --- | --- | --- |
| `timerId` | `string` | `3.3.0` | timerId 定时器 id |
| `date` | `string` | `3.3.0` | date 日期 |
| `time` | `string` | `3.3.0` | time 定时器运行的时间 |
| `status` | `boolean` | `3.3.0` | status 状态 |
| `loops` | `string` | `3.3.0` | loops 七位数字字符串，"1000000" 代表周日，"0100000" 代表周一 |
| `dps` | `Record<string, Record<string, any>>` | `3.3.0` | dps dp 点数据，示例： {     "1": true,     "2": false } |
| `timezoneId` | `string` | `3.3.0` | timezoneId 时区 |
| `aliasName` | `string` | `3.3.0` | aliasName 别名 |
| `isAppPush` | `boolean` | `3.3.0` | isAppPush 是否发送执行通知 |
| `id` | `string` | `3.3.0` | id 任务 id |


### 示例代码

#### 基础调用

```tsx
import { device } from '@ray-js/ray'

const { syncTimerTask } = device;

syncTimerTask({
  category: 'example',
  success: (result) => {
    console.log('syncTimerTask success', result);
  },
  fail: (error) => {
    console.log('syncTimerTask fail', error.errorMsg);
  },
});
```
