rework based on https://github.com/zhhchen/lua-resty-gearman