You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/04/02 03:11:46 UTC

[GitHub] [apisix] kevinw66 opened a new issue #6786: help request: is there any way to trigger a timer when a plugin is enabled and cancel timer when plugin is disabled?

kevinw66 opened a new issue #6786:
URL: https://github.com/apache/apisix/issues/6786


   ### Description
   
   I want to trigger a timer when it's enabled, but the init phase will execute whatever it's enabled or not.
   And canceled the timer when plugin is disabled, But I haven't found any API to cancel a timer created by `ngx.timer.every`
   
   ### Environment
   
   - APISIX version (run `apisix version`):2.10.2
   - Operating system (run `uname -a`):
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
   - etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`):
   - APISIX Dashboard version, if relevant:
   - Plugin runner version, for issues related to plugin runners:
   - LuaRocks version, for installation issues (run `luarocks --version`):
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on issue #6786: help request: is there any way to trigger a timer when a plugin is enabled and cancel timer when plugin is disabled?

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #6786:
URL: https://github.com/apache/apisix/issues/6786#issuecomment-1086673583


   > But when I write my plugin, and before I enable it in dashboard as `global_plugin`, the init function is still triggered
   
   `init` function in plugins is only called when the plugin is enabled. see: https://github.com/apache/apisix/blob/6559ac731c7984e647132e8107480633f6f62221/apisix/plugin.lua#L152-L154
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on issue #6786: help request: is there any way to trigger a timer when a plugin is enabled and cancel timer when plugin is disabled?

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #6786:
URL: https://github.com/apache/apisix/issues/6786#issuecomment-1086613624


   > the interval cannot set by user, It's always 1 seconds If I remember it correctly.
   
   You can enhance it to support custom intervals.
   
   > there is no such phase like `plugin_enable` and `plugin_disable`
   
   How to know when a plugin is enabled and disabled?
   
   When the plugin is disabled, the `destroy` function of this plugin is called.
   
   When a plugin is enabled, would load plugin's code.
   
   so, APISIX knows exactly when to enable and disable plugins.
   
   > the `init` phase will trigger whatever my plugin is enabled or not
   
   yes, you can try using `register_timer` on other phase.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass edited a comment on issue #6786: help request: is there any way to trigger a timer when a plugin is enabled and cancel timer when plugin is disabled?

Posted by GitBox <gi...@apache.org>.
tzssangglass edited a comment on issue #6786:
URL: https://github.com/apache/apisix/issues/6786#issuecomment-1086774493


   > So, should we add such a phase like `enable` or `disable` and receive `conf, ctx` like other phase?
   
   If we want to mark `enable` or `disable` phase of plugin, we need to refactor APISIX's plugin operation mechanism, so that when APISIX synchronises data from etcd, it can find out which plugin are new by comparing old and new data. and call the `enable` function for those plugins. It is also necessary to know which plugins are removed and to call the `disable` function.
   
   IMO, I don't like this improvement, it makes things more complicated, and there is no need to implement this now. To achieve similar functionality, I think it could be done with the `init` and `destroy` functions under the existing architecture.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass edited a comment on issue #6786: help request: is there any way to trigger a timer when a plugin is enabled and cancel timer when plugin is disabled?

Posted by GitBox <gi...@apache.org>.
tzssangglass edited a comment on issue #6786:
URL: https://github.com/apache/apisix/issues/6786#issuecomment-1086673583


   > But when I write my plugin, and before I enable it in dashboard as `global_plugin`, the init function is still triggered
   
   `init` function in plugins is called on `init_worker_by_lua` phase, see: https://github.com/apache/apisix/blob/6559ac731c7984e647132e8107480633f6f62221/apisix/plugin.lua#L152-L154
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on issue #6786: help request: is there any way to trigger a timer when a plugin is enabled and cancel timer when plugin is disabled?

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #6786:
URL: https://github.com/apache/apisix/issues/6786#issuecomment-1086774493


   > So, should we add such a phase like `enable` or `disable` and receive `conf, ctx` like other phase?
   
   If we want to mark `enable` or `disable` phase of plugin, we need to refactor APISIX's plugin operation mechanism, so that when APISIX synchronises data from etcd, it can find out which plugin are new by comparing old and new data. and call the `enable` function for those plugins. It is also necessary to know which plugins are removed and to call the disable function.
   
   As it stands, we don't need such improvements.
   
   IMO, I don't like this improvement, it makes things more complicated, and there is no need to implement this now. To achieve similar functionality, I think it could be done with the `init` and `destroy` functions under the existing architecture.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] kevinw66 commented on issue #6786: help request: is there any way to trigger a timer when a plugin is enabled and cancel timer when plugin is disabled?

Posted by GitBox <gi...@apache.org>.
kevinw66 commented on issue #6786:
URL: https://github.com/apache/apisix/issues/6786#issuecomment-1086617953


   > > the interval cannot set by user, It's always 1 seconds If I remember it correctly.
   > 
   > You can enhance it to support custom intervals.
   > 
   > > there is no such phase like `plugin_enable` and `plugin_disable`
   > 
   > How to know when a plugin is enabled and disabled?
   > 
   > When the plugin is disabled, the `destroy` function of this plugin is called.
   > 
   > When a plugin is enabled, would load plugin's code.
   > 
   > so, APISIX knows exactly when to enable and disable plugins.
   > 
   > > the `init` phase will trigger whatever my plugin is enabled or not
   > 
   > yes, you can try using `register_timer` on other phase.
   
   But when I write my plugin, and before I enable it in dashboard as `global_plugin`, the init function is still triggered


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] kevinw66 commented on issue #6786: help request: is there any way to trigger a timer when a plugin is enabled and cancel timer when plugin is disabled?

Posted by GitBox <gi...@apache.org>.
kevinw66 commented on issue #6786:
URL: https://github.com/apache/apisix/issues/6786#issuecomment-1086595572


   > 
   
   I have check into this code, but this cannot fit my needs.
   
   1、the interval cannot set by user, It's always 1 seconds If I remember it correctly.
   2、there is no such phase like `plugin_enable` and `plugin_disable`,the `init` phase will trigger whatever my plugin is enabled or not


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on issue #6786: help request: is there any way to trigger a timer when a plugin is enabled and cancel timer when plugin is disabled?

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #6786:
URL: https://github.com/apache/apisix/issues/6786#issuecomment-1086672981


   sorry, I said this incorrectly: `yes, you can try using register_timer on other phase.`
   
   register_timer cannot be used in phases such as `access`, otherwise every request will trigger the creation of a timer.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] kevinw66 commented on issue #6786: help request: is there any way to trigger a timer when a plugin is enabled and cancel timer when plugin is disabled?

Posted by GitBox <gi...@apache.org>.
kevinw66 commented on issue #6786:
URL: https://github.com/apache/apisix/issues/6786#issuecomment-1086770245


   > > But when I write my plugin, and before I enable it in dashboard as `global_plugin`, the init function is still triggered
   > 
   > `init` function in plugins is called on `init_worker_by_lua` phase, see:
   > 
   > https://github.com/apache/apisix/blob/6559ac731c7984e647132e8107480633f6f62221/apisix/plugin.lua#L152-L154
   
   So, should we add such a phase like `enable` or `disable` and receive `conf, ctx` like other phase?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on issue #6786: help request: is there any way to trigger a timer when a plugin is enabled and cancel timer when plugin is disabled?

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #6786:
URL: https://github.com/apache/apisix/issues/6786#issuecomment-1086594653


   you can use `local timers = require("apisix.timers")`, see:
   
   https://github.com/apache/apisix/blob/97bcb565075e59372842973844216c129af5d812/apisix/plugins/log-rotate.lua#L301-L308
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] kevinw66 edited a comment on issue #6786: help request: is there any way to trigger a timer when a plugin is enabled and cancel timer when plugin is disabled?

Posted by GitBox <gi...@apache.org>.
kevinw66 edited a comment on issue #6786:
URL: https://github.com/apache/apisix/issues/6786#issuecomment-1086595572


   > you can use `local timers = require("apisix.timers")`, see:
   > 
   > https://github.com/apache/apisix/blob/97bcb565075e59372842973844216c129af5d812/apisix/plugins/log-rotate.lua#L301-L308
   
   I have check into this code, but this cannot fit my needs.
   
   1、the interval cannot set by user, It's always 1 seconds If I remember it correctly.
   2、there is no such phase like `plugin_enable` and `plugin_disable`,the `init` phase will trigger whatever my plugin is enabled or not


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] kevinw66 edited a comment on issue #6786: help request: is there any way to trigger a timer when a plugin is enabled and cancel timer when plugin is disabled?

Posted by GitBox <gi...@apache.org>.
kevinw66 edited a comment on issue #6786:
URL: https://github.com/apache/apisix/issues/6786#issuecomment-1086595572


   > you can use `local timers = require("apisix.timers")`, see:
   > 
   > https://github.com/apache/apisix/blob/97bcb565075e59372842973844216c129af5d812/apisix/plugins/log-rotate.lua#L301-L308
   
   @tzssangglass I have check into this code, but this cannot fit my needs.
   
   1、the interval cannot set by user, It's always 1 seconds If I remember it correctly.
   2、there is no such phase like `plugin_enable` and `plugin_disable`,the `init` phase will trigger whatever my plugin is enabled or not


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org