Skip to content

Conversation

rinfx
Copy link
Collaborator

@rinfx rinfx commented May 9, 2024

支持 wasm-go-sdk 支持注册多个 ontick 函数以实现对多个定时任务的支持

插件代码示例:

func main() {
	wrapper.SetTickPeriod(1000)
	wrapper.RegisteTickFunc(1, func() { proxywasm.LogInfo("onTick 1 s") })
	wrapper.RegisteTickFunc(5, func() { proxywasm.LogInfo("onTick 5 s") })
	wrapper.RegisteTickFunc(3, func() { proxywasm.LogInfo("onTick 3 s") })
	wrapper.SetCtx(
		"hello-world",
		wrapper.ProcessRequestHeadersBy(onHttpRequestHeaders),
	)
}

wrapper.SetTickPeriodwrapper.RegisteTickFunc之间顺序无要求,wrapper.SetCtx需要在main函数最后执行

@rinfx rinfx requested review from johnlanni and WeixinX as code owners May 9, 2024 07:38
var globalOnTickFuncs []TickFuncEntry = []TickFuncEntry{}

// Registe multiple onTick functions. Parameters include:
// 1) tickPeriod: the execution period of tickFunc;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

介绍下我们默认的轮询间隔是100毫秒,tickPeriod最好设置为100毫秒的整数倍

@johnlanni johnlanni merged commit 5c77369 into alibaba:main May 13, 2024
@rinfx rinfx deleted the support-multi-ontick branch November 5, 2024 01:47
VinceCui pushed a commit to VinceCui/higress that referenced this pull request May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants