定时器
定时器是一种数据类型,用于定义特定实体的过期日期/寿命。
💡 常用计时器 Usage
例如,计时器属性类型可被用来存储目录实体和属性的未来到期日期:
- 临时开发环境;
- 下一次健康检查倒计时;
- 临时云资源;
- 为资源添加临时权限;
- 等等。
在live demo 这个示例中,我们可以看到 TTL
定时器属性。
应用程序接口定义
- Basic
{
"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 定义
- Basic
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 的定义
- Basic
- Python
- TypeScript
- JavaScript
- GO
"""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={}
)
import * as pulumi from "@pulumi/pulumi";
import * as port from "@port-labs/port";
export const blueprint = new port.Blueprint("myBlueprint", {
identifier: "myBlueprint",
title: "My Blueprint",
properties: {
stringProps: {
myTimerProp: {
title: "My timer",
format: "timer",
required: true,
},
},
},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new port.Blueprint("myBlueprint", {
title: "My Blueprint",
identifier: "myBlueprint",
properties: {
stringProps: {
myTimerProp: {
title: "My timer",
format: "timer",
required: true,
},
},
},
relations: {},
});
exports.title = entity.title;
package main
import (
"github.com/port-labs/pulumi-port/sdk/go/port"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
blueprint, err := port.NewBlueprint(ctx, "myBlueprint", &port.BlueprintArgs{
Identifier: pulumi.String("myBlueprint"),
Title: pulumi.String("My Blueprint"),
Properties: port.BlueprintPropertiesArgs{
StringProps: port.BlueprintPropertiesStringPropsMap{
"myTimerProp": &port.BlueprintPropertiesStringPropsArgs{
Title: pulumi.String("My timer"),
Format: pulumi.String("timer"),
Required: pulumi.Bool(true),
},
},
},
})
ctx.Export("blueprint", blueprint.Title)
if err != nil {
return err
}
return nil
})
}
示例
下面是一个 timerExample
蓝图的实体,它有一个标识符为 timer
的定时器属性。
在示例实体中,指定了过期日期:
"identifier": "entityIdentifier",
"title": "Timer Example",
"icon": "Microservice",
"blueprint": "timerExample",
"properties": {
"timer": "2022-12-01T16:50:00+02:00"
},
"relations": {}
查看 Port 的用户界面,可以看到我们创建的计时器将在 2 小时后过期:
2 小时后,属性状态将变为 "已过期","定时器已过期 "事件将被发送到更改日志:
计时器过期事件也会出现在 Port 的审核日志中:
为了通知定时器到期,以下通知正文将被发送到在蓝图的 "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"
}