Skip to content

Commit 7897d08

Browse files
committed
✨ Cloud.enqueue
1 parent 70a3a6f commit 7897d08

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

API.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ new AV.Cloud.Error(message: string, options?)
7575
运行已定义的云函数,与 JavaScript SDK 中会发起 HTTP 请求不同,在云引擎中默认变成直接调用指定的函数。
7676
7777
```javascript
78-
AV.Cloud.run(name: string, data: object, options?: object): Promise
78+
AV.Cloud.run(name: string, params: object, options?: object): Promise
7979
```
8080
8181
`options` 的属性包括:
@@ -91,6 +91,26 @@ AV.Cloud.run(name: string, data: object, options?: object): Promise
9191
9292
兼容 JavaScript SDK 的同名函数,是 `AV.Cloud.run` 的一个别名。
9393
94+
### AV.Cloud.enqueue
95+
96+
在队列中运行云函数。
97+
98+
```javascript
99+
AV.Cloud.run(name: string, params: object, options?: object): Promise<TaskInfo>
100+
```
101+
102+
`options` 的属性包括:
103+
104+
* `attempts?: number`:最大重试次数,默认 `3`.
105+
* `backoff?: number`:重试间隔(毫秒),默认 `60000`.
106+
* `delay?: number`:延时执行(毫秒)。
107+
* `notify?: string`: 将执行结果通知到指定云函数。
108+
* `retryTimeout?: boolean`: 将超时视作失败来进行重试,默认 `true`.
109+
110+
`TaskInfo` 的属性包括:
111+
112+
- `uniqueId`:任务的唯一 Id,会包含在日志中。
113+
94114
### 定义 Class Hook
95115
96116
* AV.Cloud.beforeSave

leanengine.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ export namespace Cloud {
6565
req?: Request
6666
}
6767

68+
interface EnqueueOptions {
69+
attempts?: number,
70+
backoff?: number,
71+
delay?: number,
72+
notify?: string,
73+
retryTimeout?: boolean,
74+
}
75+
76+
interface TaskInfo {
77+
uniqueId: string
78+
}
79+
6880
interface MiddlewareOptions {
6981
framework?: string
7082
}
@@ -107,6 +119,7 @@ export namespace Cloud {
107119

108120
export function run(name: string, params: Object, options?: RunOptions): Promise<any>;
109121
export function rpc(name: string, params: Object, options?: RunOptions): Promise<any>;
122+
export function enqueue(name: string, params: Object, options?: EnqueueOptions): Promise<TaskInfo>;
110123

111124
export function beforeSave(className: string, handler: ClassHookFunction): void;
112125
export function afterSave(className: string, handler: ClassHookFunction): void;

lib/cloud.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ Cloud.rpc = function(name, data, options) {
9090
}
9191
};
9292

93+
Cloud.enqueue = function(name, params, options) {
94+
options = options || {};
95+
96+
if (!options.prod && !AV.Cloud.__prod) {
97+
options.prod = 0;
98+
}
99+
100+
return AV.request({
101+
method: 'POST',
102+
path: '/engine/cloud-queue/enqueue',
103+
data: _.extend({
104+
function: name,
105+
params: params
106+
}, options),
107+
authOptions: {useMasterKey: true}
108+
});
109+
}
110+
93111
Cloud.beforeSave = function(nameOrClass, func) {
94112
defineClassHook(className(nameOrClass), '__before_save_for_', func);
95113
};

0 commit comments

Comments
 (0)