class Retry extends Object
重试记录
示例代码 && 测试结果如下:
1、执行过程中,状态被修改为 RETRYING;
2、执行一次后,第一条数据执行成功,并且被删除;第二条数据重试;
3、执行第二次后,第二条数据状态被改为 FAILED。
import bropen.toolkit.api.Response
import bropen.framework.plugins.retry.Retry
// 定义一个重试的接口服务及方法
class MyService {
Response test(String data) {
println data
sleep 5000
def succ = (data == "1")
return Response.create(succ ? 0 : 1, succ ? null : "error")
}
}
// 如果是在 console 里运行的,使用下面的代码注册服务
//BeanUtils.registerBean("myService", MyService, null, true)
// 创建重试数据
new Retry(service: "myService.test", interval: 1, max: 2, data: "1", nextDate: new Date()).save()
new Retry(service: "myService.test", interval: 1, max: 2, data: "{x: 2}", nextDate: new Date()).save()
| Type | Name and description |
|---|---|
static Object |
constraints |
Integer |
counts重试次数 |
String |
dataJSON 格式的、用于重试的数据 |
Date |
dateCreated创建时间 |
Integer |
interval重试间隔,单位为分钟 |
Date |
lastDate上次重试的时间 |
String |
lastResp上次重试失败的返回值 |
static Object |
mapping |
Integer |
max最多重试次数 |
Date |
nextDate下次重试的时间 |
String |
service服务接口 |
String |
status是否重试最终失败了 |
| Type | Name and description |
|---|---|
Object |
beforeValidate() |
static void |
bootStrapInit() |
| Methods inherited from class | Name |
|---|---|
class Object |
Object#wait(long, int), Object#wait(long), Object#wait(), Object#equals(Object), Object#toString(), Object#hashCode(), Object#getClass(), Object#notify(), Object#notifyAll() |
重试次数
JSON 格式的、用于重试的数据
创建时间
重试间隔,单位为分钟
上次重试的时间
上次重试失败的返回值
最多重试次数
下次重试的时间
服务接口
形式为 service.method 接口,接口参数为字符串 data、返回结果为封装为 Response 的响应对象。
是否重试最终失败了