edgex: 调度(Scheduling)
本帖最后由 keer_zu 于 2020-12-18 10:22 编辑参考
概述:
调度微服务包括清除事件的Scrubber微服务和读取已经导出到网关的数据(用于核心数据)。可选地,还可以配置Scrubber微服务来删除未导出的过期事件/读取数据。删除过期事件/读取数据使网关继续运营与静态存储,而系统继续收集新的数据从设备和传感器在不操作的情况下,出口设施或操作不够快跟上数据收集。
导出记录和陈旧记录的删除都按照可配置的时间表进行。默认情况下,Scrubber每30分钟清理一次数据。
Scrubber微服务并不直接从EdgeX Foundry的持久存储本身删除数据,而是调用Core data删除记录。Core Data充当持久化事件/读取数据的单一访问点。Scrubber微服务是一个独立的服务,没有任何客户端。也就是说,没有调用Scrubber的API。洗涤器按时间触发器工作。
调度器使用一个数据存储来持久保存时间间隔和间隔动作。持久性是通过位于EdgeX当前配置数据库中的调度器DB来实现的。
Data Dictionary
Class Name Description
Interval An object defining a specific “period” in time.
IntervalAction The action taken by a Service when the Interval occurs.
本帖最后由 keer_zu 于 2020-12-18 10:45 编辑
EDGEX FOUNDRY配置参数 --- support-scheduler
support-scheduler是主要是EDGEX系统中的提醒服务,support-scheduler使用介绍如下,他有2个启动参数可以配置:
[*]registry是一个bool量,True表示support-scheduler的配置参数是从consul拉取,False表示从本地配置文件载入。
[*]profile本地配置文件的路径, 即便registry=True, 该参数也必须要指明一个配置文件,因为连接consul服务所需的host,port等参数必须从本地的配置文件中获取
Usage: %s
Server Options:
-r, --registry Indicates service should use Registry
-p, --profile <name> Indicate configuration profile other than default
Common Options:
-h, --help Show this message
Table of Contents
support-scheduler的配置文件WritableClientsDatabasesLoggingRegistryServiceIntervalsIntervalActions
static/image/hrline/1.gif
support-scheduler的配置文件
ScheduleIntervalTime = 500
LogLevel = 'INFO'
BootTimeout = 30000
ClientMonitor = 15000
CheckInterval = '10s'
Host = 'localhost'
Port = 48085
Protocol = 'http'
ReadMaxLimit = 100
StartupMsg = 'This is the Support Scheduler Microservice'
Timeout = 5000
Host = 'localhost'
Port = 8500
Type = 'consul'
EnableRemote = false
File = './logs/edgex-support-scheduler.log'
Protocol = 'http'
Host = 'localhost'
Port = 48061
Host = 'localhost'
Name = 'scheduler'
Password = ''
Port = 27017
Username = ''
Timeout = 5000
Type = 'mongodb'
Name = 'midnight'
Start = '20180101T000000'
Frequency = 'P1D'
Name = 'scrub-pushed-events'
Host = 'localhost'
Port = 48080
Protocol = 'http'
Method = 'DELETE'
Target = 'core-data'
Path = '/api/v1/event/scrub'
Interval = 'midnight'
Name = 'scrub-aged-events'
Host = 'localhost'
Port = 48080
Protocol = 'http'
Method = 'DELETE'
Target = 'core-data'
Path = '/api/v1/event/removeold/age/604800000'
Interval = 'midnight'
如上是项目自带的support-scheduler的配置文件 ,主要分8部分,support-scheduler启动后会将配置文件的信息导入如下结构中,若registry=True则根据Registry中的信息连接consul并拉取相应的配置信息覆盖之前从本地配置文件中读取到的信息。
// Configuration V2 for the Support Scheduler Service
type ConfigurationStruct struct {
Writable WritableInfo
Clients mapconfig.ClientInfo
Databases mapconfig.DatabaseInfo
Logging config.LoggingInfo
Registry config.RegistryInfo
Service config.ServiceInfo
Intervals mapconfig.IntervalInfo
IntervalActions mapconfig.IntervalActionInfo
}
Writable
type WritableInfo struct {
ScheduleIntervalTime int
LogLevel string
}
support-scheduler有2个参数可以在运行时被修改
ScheduleIntervalTime 内部定时器间隔触发时间,单位:毫秒
LogLevel 日志等级
Clients
// ClientInfo provides the host and port of another service in the eco-system.
type ClientInfo struct {
// Host is the hostname or IP address of a service.
Host string
// Port defines the port on which to access a given service
Port int
// Protocol indicates the protocol to use when accessing a given service
Protocol string
}
Host 微服务的地址
Port 微服务的端口
Protocol 微服务所使用的协议,目前仅支持http
support-scheduler运行时需要使用其他微服务提供的功能,Client便是连接其他微服务所必须的参数,这是一个map参数,key值便是其他微服务的名字,value便是client的具体参数信息, support-scheduler正常运行一般需要使用logging微服务。
Databases
type DatabaseInfo struct {
Type string
Timeoutint
Host string
Port int
Username string
Password string
Name string
}
Type 数据库类型,目前仅支持 mongodb
Timeout数据库连接超时,单位:s
Host 数据库地址
Port 数据库端口
Username 数据库登录用户名
Password 数据库登录密码
Name 数据库名字
support-scheduler当前支持两种Primary数据库mongodb和redisdb。
Logging
// LoggingInfo provides basic parameters related to where logs should be written.
type LoggingInfo struct {
EnableRemote bool
File string
}
EnableRemote True: log于support-logging微服务持久化(support-logging的连接参数由Clients字段提供), False:log于本地文件持久化
File log本地持久化时日志文件的路径
Registry
// RegistryInfo defines the type and location (via host/port) of the desired service registry (e.g. Consul, Eureka)
type RegistryInfo struct {
Host string
Port int
Type string
}
consul连接参数
Service同support-loggingIntervals
type IntervalInfo struct {
// Name of the schedule must be unique?
Name string
// Start time in ISO 8601 format YYYYMMDD'T'HHmmss
Start string
// End time in ISO 8601 format YYYYMMDD'T'HHmmss
End string
// Periodicity of the schedule
Frequency string
// Cron style regular expression indicating how often the action under schedule should occur.Use either runOnce, frequency or cron and not all.
Cron string
// Boolean indicating that this schedules runs one time - at the time indicated by the start
RunOnce bool
}
Interval是触发的描述结构,support-scheduler会周期性的检查Interval数组并将满足触发条件的Interval过滤出来,执行下挂在其下的所有触发动作。Interval的来源主要有三处:
1,support-scheduler使用的数据库,support-scheduler启动时会从数据库load已经存在的Interval
2,配置文件,support-scheduler会载入配置文件中的Interval并将其写入数据库持久化,值得注意的是support-scheduler不支持重名的 Interval,因此当配置文件的Interval的Name与数据库中的相应Interval的Name相同时会优先使用数据库中的Interval而放弃配置文件中的Interval
3,support-scheduler提供的restful API接口支持动态更新Interval信息
Name 触发 名字
Start 触发开始时间 ISO 8601 format YYYYMMDD'T'HHmmss
End 触发结束时间 ISO 8601 format YYYYMMDD'T'HHmmss
Frequency 周期性触发时的触发频率
Cron Cron 风格的触发表达式
RunOnce 是否仅仅触发一次
IntervalActions
type IntervalActionInfo struct {
// Host is the hostname or IP address of a service.
Host string
// Port defines the port on which to access a given service
Port int
// Protocol indicates the protocol to use when accessing a given service
Protocol string
// Action name
Name string
// Action http method *const prob*
Method string
// Acton target name
Target string
// Action target parameters
Parameters string
// Action target API path
Path string
// Associated Schedule for the Event
Interval string
}
触发动作的执行最终都表现为访问一个外部服务(外部指的是support-scheduler微服务的外部),可以是core-data等其他微服务,也可以是其他接口兼容的服务。Host 外部服务主机名
Port 外部服务端口
Protocol 外部服务协议,目前仅支持http
Name 触发动作的名字
Method http方法,GET,POST等等
Target 外部服务的名字
Parameters http参数,目前源码不支持该字段
Path 外部服务path 如/api/v1/event/removeold/age/604800000
Interval 绑定的Interval名字,非常关键,如果该字段在support-scheduler中没有对应的Interval也就意味着该触发动作永远不会被执行
出处:原文
设置定时任务
页:
[1]