我正在使用"npm install"来下载和编译我编写的一个小node.js应用程序的所有依赖项.我使用的"package.json"文件是正确的,包含所有需要的信息.
其中一个要安装的软件包有"node-gyp"作为依赖项,所以我之前安装了"python2"软件包.
现在,在某个时刻我开始收到错误消息:
> node-gyp rebuild
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack at failNoPython (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:103:14)
gyp ERR! stack at /usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:42:11
gyp ERR! stack at F (/usr/lib/node_modules/npm/node_modules/which/which.js:40:25)
gyp ERR! stack at E (/usr/lib/node_modules/npm/node_modules/which/which.js:43:29)
gyp ERR! stack at /usr/lib/node_modules/npm/node_modules/which/which.js:54:16
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:99:15)
gyp ERR! System Linux 3.18.9-200.fc21.x86_64
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /srv/visitor/node_modules/phantom/node_modules/dnode/node_modules/weak
gyp ERR! node -v …Run Code Online (Sandbox Code Playgroud) 我已经从Dockerfile创建了一个Docker镜像,并且我希望在基于此镜像的容器运行时定期执行cronjob.我的Dockerfile就是这个(相关部分):
FROM l3iggs/archlinux:latest
COPY source /srv/visitor
WORKDIR /srv/visitor
RUN pacman -Syyu --needed --noconfirm \
&& pacman -S --needed --noconfirm make gcc cronie python2 nodejs phantomjs \
&& printf "*/2 * * * * node /srv/visitor/visitor.js \n" >> cronJobs \
&& crontab cronJobs \
&& rm cronJobs \
&& npm install -g node-gyp \
&& PYTHON=/usr/sbin/python2 && export PYTHON \
&& npm install
EXPOSE 80
CMD ["/bin/sh", "-c"]
Run Code Online (Sandbox Code Playgroud)
创建映像后,我运行一个容器并验证确实已添加了cronjob:
crontab -l
*/2 * * * * node /srv/visitor/visitor.js
Run Code Online (Sandbox Code Playgroud)
现在,问题是cronjob永远不会被执行.当然,我测试了从控制台手动运行时"node /srv/visitor/visitor.js"正确执行.
有任何想法吗?
我找到了以下代码实现了一个异步消息队列(实际上没有队列,只有文件)与ZeroMQ和Node.js
setInterval(function() {
var value = { id: i++, date: new Date() };
WriteFile(value.id + ".dat", value);
client.send(value, function(result) {
console.log(value, result);
DeleteFile(value.id + ".dat");
});
}, 10000);
Run Code Online (Sandbox Code Playgroud)
代码来自这里.
"WriteFile"和"DeleteFile"函数稍后在代码中定义,但没有什么特别之处.
函数"client.send"也在另一个文件中定义,其中定义了回调.很明显,当消息传输成功时,ZeroMQ提供了一个回调.
现在我想做这样的事情,但为了简单起见,使用Redis pubsub而不是ZeroMQ.据我了解,node_redis模块的"发布"功能没有回调.
我的问题是,有没有办法实现这样的东西?我非常喜欢编写文件然后在传输完成时删除它们的想法,但我希望它能在Redis中完成.我知道我正在抓稻草,但如果有人有任何想法,我会很乐意听.