ngx.timer.every

96 views
Skip to first unread message

Brent Tucker

unread,
Nov 7, 2021, 7:47:23 PM11/7/21
to openresty-en
Hi,

I am trying to use ngx.timer.every to poll a database table for records and then post the results to redis. I found this code from the opm application that I am using as a reference for the db polling. Do I also need to use locking to coordinate between  workers so the same results are not sent to redis more than once?

The workflow I am after is 
1. Select records from db table
2. Push results to redis
3. Delete the records from table

Thanks in advance.
Brent

xiao_cang

unread,
Nov 8, 2021, 1:33:58 AM11/8/21
to openresty-en
Hi Brent,

Regarding the code you referenced, there's one important logic missing here: https://github.com/openresty/opm/blob/master/web/lua/opmserver/init.lua#L50

This means that an openresty instance will only have one process (privileged agent) to execute the timer.

Brent Tucker

unread,
Nov 8, 2021, 7:22:23 AM11/8/21
to openre...@googlegroups.com
Thanks very much for the explaination

--
You received this message because you are subscribed to a topic in the Google Groups "openresty-en" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openresty-en/naWlH4-7mhE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openresty-en...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openresty-en/3eeeca93-1d96-47f3-975f-02ac741c56abn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages