怎样自动启动定时器?

111 views
Skip to first unread message

Dan Liu

unread,
Nov 3, 2018, 4:44:43 AM11/3/18
to openresty
有个定时任务需要访问redis并使用resty.http,如果在init_worker_by_lua_file里启动定时器,会报以下错误:
init_worker_by_lua_file error: /usr/local/openresty/lualib/resty/redis.lua:59: API disabled in the context of init_worker_by_lua*
init_worker_by_lua_file error: /usr/local/openresty/site/lualib/resty/http.lua:123: API disabled in the context of init_worker_by_lua*

我现在在nginx.conf写了个location,放在content_by_lua_file里,手工或者在crontab里用curl调用api来启动定时器。请问大家有什么简单、优雅的方法吗?

------------------
  此致
祝好

刘丹

 

Kwanhur Huang

unread,
Nov 4, 2018, 8:31:13 PM11/4/18
to open...@googlegroups.com
hello,

在init_worker_by_lua*里结合ngx.timer.at启动定时器即可




Kwanhur Huang
TL;DR

--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html

Reply all
Reply to author
Forward
0 new messages