diff --git a/lib/resty/healthcheck.lua b/lib/resty/healthcheck.lua index 16553aa1..cc6df3e9 100644 --- a/lib/resty/healthcheck.lua +++ b/lib/resty/healthcheck.lua @@ -33,7 +33,6 @@ local ipairs = ipairs local cjson = require("cjson.safe").new() local table_insert = table.insert local table_remove = table.remove -local worker_events = require("resty.worker.events") local resty_lock = require ("resty.lock") local re_find = ngx.re.find local bit = require("bit") @@ -43,6 +42,11 @@ local ngx_worker_pid = ngx.worker.pid local ssl = require("ngx.ssl") local resty_timer = require "resty.timer" + +local RESTY_EVENTS_VER = "0.1.0" +local RESTY_WORKER_EVENTS_VER = "0.3.3" + + local new_tab local nkeys local is_array @@ -83,6 +87,32 @@ do end end + +local worker_events +--- This function loads the worker events module received as arg. It will throw +-- error() if it is not possible to load the module. +local function load_events_module(module_name) + if module_name == "resty.worker.events" then + worker_events = require("resty.worker.events") + assert(worker_events, "could not load lua-resty-worker-events") + assert(worker_events._VERSION == RESTY_WORKER_EVENTS_VER, + "unsupported lua-resty-worker-events version") + assert(worker_events.configured(), "please configure the " .. + "'lua-resty-worker-events' module before using 'lua-resty-healthcheck'") + + elseif module_name == "resty.events" then + worker_events = require("resty.events.compat") + assert(worker_events, "could not load lua-resty-events") + assert(worker_events._VERSION == RESTY_EVENTS_VER, + "unsupported lua-resty-events version") + + else + error("unknown events module") + end + +end + + -- constants local EVENT_SOURCE_PREFIX = "lua-resty-healthcheck" local LOG_PREFIX = "[healthcheck] " @@ -1334,6 +1364,7 @@ local defaults = { name = NO_DEFAULT, shm_name = NO_DEFAULT, type = NO_DEFAULT, + events_module = "resty.worker.events", checks = { active = { type = "http", @@ -1437,8 +1468,7 @@ end -- @return checker object, or `nil + error` function _M.new(opts) - assert(worker_events.configured(), "please configure the " .. - "'lua-resty-worker-events' module before using 'lua-resty-healthcheck'") + load_events_module(opts.events_module) local active_type = (((opts or EMPTY).checks or EMPTY).active or EMPTY).type local passive_type = (((opts or EMPTY).checks or EMPTY).passive or EMPTY).type diff --git a/lua-resty-healthcheck-scm-1.rockspec b/lua-resty-healthcheck-scm-1.rockspec index ff1f299b..d9172229 100644 --- a/lua-resty-healthcheck-scm-1.rockspec +++ b/lua-resty-healthcheck-scm-1.rockspec @@ -14,7 +14,6 @@ description = { homepage = "https://github.com/Kong/lua-resty-healthcheck" } dependencies = { - "lua-resty-worker-events == 1.0.0", "penlight >= 1.9.2", "lua-resty-timer ~> 1", }