Skip to content

CLI & node module for running stuff on heroku one-off dynos

Notifications You must be signed in to change notification settings

amarczuk/herokuRun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Heroku Run

Build Status

Simple module that allows to run commands on one-off heroku dynos from within the node applications. May beused for task automation.

How to nstall

$ npm install herokuRun --save

How to use

Run simple command (demo/command.js):

var herokuRun = require( 'herokuRun' ),
	runner = herokuRun( 'token', 'my-app-name' );

runner.run( 'pwd && ls', function( err, logger ) {

        if ( err ) {
        	console.log( err );
        	return;
        }

        logger
            .on( 'connected', function( auth ) {
               	console.log( 'connected' );
               	console.log( (auth) ? 'authorized' : 'unauthorized' );
            })
            .on( 'data', function( data ) {
                 process.stdout.write( data.toString() );
            })
            .on( 'end', function() {
                console.log( 'connection ended' );
            });
    } );

or using Promise (since 0.0.7):

var herokuRun = require( 'herokuRun' ),
    runner = herokuRun( 'token', 'my-app-name' );

runner.run( 'pwd && ls' )
    .then( function( logger ) {

        return new Promise( function( resolve, reject ) {
            logger
                .on( 'connected', function( auth ) {
                    console.log( 'connected' );
                    console.log( (auth) ? 'authorized' : 'unauthorized' );
                })
                .on( 'data', function( data ) {
                     process.stdout.write( data.toString() );
                })
                .on( 'end', function() {
                    console.log( 'connection ended' );
                    resolve();
                });
        } );
        
    } )
    .then( function() {
        // do something more...
    } )
    .catch( function( err ) ) {
        console.log( err );
    });

Run bash and interact with dyno (demo/bash.js):

var herokuRun = require( 'herokuRun' ),
	runner = herokuRun( 'token', 'my-app-name' );
 
runner.run( 'bash', function( err, logger ) {
 
        if ( err ) {
        	console.log( err );
        	return;
        }
 
        logger
            .on( 'connected', function( auth ) {
               	console.log( 'connected' );
               	console.log( (auth) ? 'authorized' : 'unauthorized' );
                process.stdin.on('data', function(chunk) {
                    logger.send(chunk);
                });

            })
            .on( 'data', function( data ) {
                process.stdout.write( data.toString() );
            })
            .on( 'end', function() {
                console.log( 'connection ended' );
                process.stdin.end();
            });
    } );

How to test

Add heroku credentials to tests/conf/heroku.json for end-to-end test to pass.

{
	"herokutoken": "placeholder_for_valid_heroku_token",
	"app": "placeholder_for_valid_heroku_app_name"
}

Run npm install && npm test.

About

CLI & node module for running stuff on heroku one-off dynos

Resources

Stars

Watchers

Forks

Packages

No packages published