How do I successfully notify Airbrake of a deployment when using capistrano to deploy a Node.js project?

StackOverflow https://stackoverflow.com/questions/16406827

문제

This is a bit of an oddball question.

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). However, I'd like to have Airbrake be notified of these deployments.

Using the 'airbrake' Node.js module, and calling

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.

Adding

require 'airbrake/capistrano'

to deploy.rb definitely does not work.

How do others successfully use

airbrake.trackDeployment

?

도움이 되었습니까?

해결책 2

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:

In my Node.js root directory, create a deploy.js file, like so:

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

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

다른 팁

You could create a simple js file you'd run locally (on your machine for example) that notifies airbrake as a last deploy task. 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:

deploy.task :notify_airbrake do
    `ssh youserver "node notify_airbrake.js"`
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top