Skip to main content

定时器

定时器是一种数据类型,用于定义特定实体的过期日期/寿命。

💡 常用计时器 Usage

例如,计时器属性类型可被用来存储目录实体和属性的未来到期日期:

  • 临时开发环境;
  • 下一次健康检查倒计时;
  • 临时云资源;
  • 为资源添加临时权限;
  • 等等。

live demo 这个示例中,我们可以看到 TTL 定时器属性。

应用程序接口定义

{
"myTimerProp": {
"title": "My timer",
"icon": "My icon",
"description": "My timer property",
"type": "string",
"format": "timer",
"default": "2022-04-18T11:44:15.345Z"
}
}

Check out Port's API reference to learn more.

Terraform 定义

resource "port_blueprint" "myBlueprint" {
# ...blueprint properties
properties = {
string_props = {
"myTimerProp" = {
title = "My timer"
icon = "My icon"
description = "My timer property"
format = "timer"
default = "2022-04-18T11:44:15.345Z"
}
}
}
}

Pulumi 的定义

"""A Python Pulumi program"""

import pulumi
from port_pulumi import Blueprint,BlueprintPropertiesArgs,BlueprintPropertiesStringPropsArgs

blueprint = Blueprint(
"myBlueprint",
identifier="myBlueprint",
title="My Blueprint",
properties=BlueprintPropertiesArgs(
string_props={
"myTimerProp": BlueprintPropertiesStringPropsArgs(
title="My timer",
format="timer",
required=True,
)
}
),
relations={}
)

示例

下面是一个 timerExample 蓝图的实体,它有一个标识符为 timer 的定时器属性。

在示例实体中,指定了过期日期:

"identifier": "entityIdentifier",
"title": "Timer Example",
"icon": "Microservice",
"blueprint": "timerExample",
"properties": {
"timer": "2022-12-01T16:50:00+02:00"
},
"relations": {}

查看 Port 的用户界面,可以看到我们创建的计时器将在 2 小时后过期:

Timer entity

2 小时后,属性状态将变为 "已过期","定时器已过期 "事件将被发送到更改日志:

Timer entity expired

计时器过期事件也会出现在 Port 的审核日志中:

Timer Audit log

为了通知定时器到期,以下通知正文将被发送到在蓝图的 "changelogDestination "中配置的 Webhook/Kafka 主题:

{
"context": {
"blueprint": "timerExample",
"entity": "entityIdentifier"
},
"action": "TIMER_EXPIRED",
"trigger": {
"at": "2022-12-01T16:50:00+02:00",
"by": {
"byPort": true,
"orgId": "org_example"
},
"origin": "API"
},
"resourceType": "entity",
"status": "SUCCESS"
}