[英]How do I successfully notify Airbrake of a deployment when using capistrano to deploy a Node.js project?
This is a bit of an oddball question. 这有点奇怪的问题。
Capistrano 2.14.2 Capistrano 2.14.2
I'm using capistrano to deploy a couple of Node.js projects, and this works fine (from within the same rvm and gemset Ruby installation). 我正在使用capistrano来部署一些Node.js项目,这很好(从同一个rvm和gemset Ruby安装中)。 However, I'd like to have Airbrake be notified of these deployments. 但是,我希望Airbrake得到有关这些部署的通知。
Using the 'airbrake' Node.js module, and calling 使用'airbrake'Node.js模块,并调用
airbrake.trackDeployment({repo: '...'});
works, but not sure how to reliably call this just once at deploy time. 工作,但不知道如何在部署时可靠地调用它一次。 If I call it within my server, then Airbrake is notified of a "deployment" every time my server starts, which is obviously not correct. 如果我在我的服务器内调用它,那么每次我的服务器启动时Airbrake都会收到“部署”的通知,这显然是不正确的。
Adding 添加
require 'airbrake/capistrano'
to deploy.rb definitely does not work. deploy.rb肯定不起作用。
How do others successfully use 其他人如何成功使用
airbrake.trackDeployment
? ?
You could create a simple js file you'd run locally (on your machine for example) that notifies airbrake as a last deploy task. 您可以创建一个简单的js文件,您可以在本地运行(例如在您的计算机上),通知airbrake作为最后一次部署任务。 You could for example use the backtick operator to run a task: 例如,您可以使用反引号运算符来运行任务:
deploy.task :notify_airbrake do
`node notify_airbrake.js`
end
If you don't have node installed locally, you could also pick one of the servers to run the notification script through ssh: 如果您没有在本地安装节点,您还可以选择其中一个服务器通过ssh运行通知脚本:
deploy.task :notify_airbrake do
`ssh youserver "node notify_airbrake.js"`
end
Based on this solution http://dwradcliffe.com/2011/09/26/using-airbrake-with-node.html (which is clearly embedded in a Rails app.), I came up with the following, which depends solely on Javascript: 基于这个解决方案http://dwradcliffe.com/2011/09/26/using-airbrake-with-node.html (显然嵌入在Rails应用程序中),我提出了以下内容,这完全取决于使用Javascript:
In my Node.js root directory, create a deploy.js file, like so: 在我的Node.js根目录中,创建一个deploy.js文件,如下所示:
var airbrake = require('airbrake').createClient("AIRBRAKE_API_KEY");
var deployment = {rev: process.argv[2],
repo: process.argv[3],
env: process.argv[4],
user: process.argv[5]};
airbrake.trackDeployment(deployment, function(err, params) {
if (err) {throw err}
console.log('Tracked deployment of %s to %s', params.rev, params.env);
})
In config/deploy.rb, add 在config / deploy.rb中,添加
require 'airbrake/capistrano'
and 和
namespace :airbrake do
desc "Notify Airbrake of a new deploy."
task :deploy do
system "node deploy.js #{current_revision} #{repository} #{stage} #{user}"
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.