upload_to_s3 : function ( end ){
        var flow = new Flow();

        photos.forEach( function ( photo ){
          var i    = 1;
          var each = function ( i ){
            return function ( ready ){
              var url = photo[ 'url' + i ];

              if(( i === 4 ) && ( url === '' )) return ready();

              img.s3.create({
                source_path : _pub_dir + url,
                target_path : url,
                headers     : {},
                callback    : function (){
                  ready();
                }
              });
            };
          };

          for( ; i < 5; i++ ){
            flow.parallel( each( i ));
          }
        });

        flow.join().end( function (){
          end();
        });
      }
示例#2
0
  init : function ( express, app ){

    flow.series( function ( next ){
      if( NODE_ENV === 'dev' ){
        var seed = require( './seed' );

        seed.init( next );
      }
    });

    flow.series( function ( next ){
      rater.init( next );
    });

    flow.series( function ( next ){
      sidebar.init( next );
    });

    flow.end( function(){
      setInterval( rater.init, 3600 * 1000 );
      setInterval( sidebar.init, 3600 * 1000 );

      LOG.debug( 'All background job finished' );
    });
  }
示例#3
0
文件: artist.js 项目: dreamerslab/sin
  remove_links : function ( next ){
    var self = this;
    var flow = new Flow();

    if( !this.links.length ) return next();

    this.links.forEach( function ( link_id, index ){
      flow.parallel( function ( ready ){
        Link.findByIdAndRemove( link_id, function ( err, link ){
          if( err ) return ready( err );

          ready();
        });
      });
    });

    flow.join().error( function ( err ){
        if( err ){
          LOG.error( 500, '[hooks][artist][remove_links] fail', err );
          next( err );
        }
      }).
      end( function (){
        LOG.debug( '[hooks][artist][remove_links] done', self.links );
        next();
      });
  },
示例#4
0
文件: Artist.js 项目: dreamerslab/sin
        }).save( function ( err, artist ){
          if( err ) return next( err );

          var i = 1;
          var insert_init_link = function ( i ){
            return function ( next ){
              args_for_link = {
                title : args[ 'link_name' + i ],
                url   : args[ 'link' + i ]
              };

              Link.insert( args_for_link,
                function ( err ){
                  LOG.error( 500, 'Link insert fail', err );
                  next();
                },
                function ( link ){
                  link.add_to_artists( artist, next );
                });
            };
          };

          for( ; i < 6; i++ ){
            flow.series( insert_init_link( i ));
          }

          flow.error( next ).end( function (){
            created( artist );
          });
        });
示例#5
0
    create_all : function ( names, callback ){
      var self = this;
      var flow = new Flow();

      names.forEach( function ( name ){
        flow.series( function ( name, next ){
          self.findOne({ name : name }, function ( err, tag ){
            if( err ) return flow.end( function (){
              callback( err );
            });

            if( tag ) return next();

            new self({
              name : name
            }).save( function ( err, tag, count ){
              if( err ) return flow.end( function (){
                callback( err );
              });

              next();
            });
          });
        }, name );
      });

      flow.end( function (){
        callback();
      });
    }
示例#6
0
文件: build.js 项目: timker/coke
module.exports = function ( current ){
  var source       = fs.readFileSync( current + 'config/assets.yml', 'utf8' );
  var config       = yaml.load( source );
  var version_path = current + 'public/assets_version.json';
  var tmp_dir      = current + 'tmp/assets/';

  lib.pub_dir = current + 'public/';

  var flow = new Flow({
    log    : true,
    minify : true,
    uglify : false
  });

  // check if the dir exist, if it does remove it
  flow.series( function ( args, next ){
    if( !fs.existsSync( tmp_dir )) return next();

    rmdir( tmp_dir, function ( err, dirs, files ){
      if( err ) throw err;

      next();
    });
  }).

  // create assets dir
  series( function ( args, next ){
    fs.mkdirSync( tmp_dir );
    next();
  });

  // build assets to tmp
  lib.build_assets( config, flow, 'css', tmp_dir );
  lib.build_assets( config, flow, 'js', tmp_dir );

  flow.join().end( function (){
    var version, compare;

    var tmp = {
      css : lib.assign_version( config.css ),
      js  : lib.assign_version( config.js )
    };

    if( fs.existsSync( version_path )){
      var ori_version = JSON.parse( fs.readFileSync( version_path, 'utf8' ));

      compare = true;
      version = extend( true, tmp, ori_version );
    }else{
      compare = false;
      version = tmp;
    }

    fs.writeFileSync( version_path, JSON.stringify( version, null, 2 ));
    lib.compare_and_replace( config, version, 'css', tmp_dir, compare, version_path );
    lib.compare_and_replace( config, version, 'js', tmp_dir, compare, version_path );
  });
};
示例#7
0
  merge_uploads : function ( req, res, next ){
    req.connection.setTimeout( ten_min );

    var files  = req.files;
    var videos = [];
    var format = '';
    var flow   = new Flow();
    var each   = function ( key ){
      return function ( ready ){
        var file = files[ key ];

        if( file.size == '0' ) return ready();

        if( key !== 'cover' ){
          format          = file.name.match( /.(webm|mp4)$/i );
          file.format     = format ? format[ 0 ] : file.type;
          file.key_name   = key;
          req.body[ key ] = file.name;

          videos.push( file );

          return ready();
        }

        img.check_size( file.path, function ( err, photo ){
          req.cover           = file;
          req.body.cover      = file.name;
          req.body.cover_size = photo.width + 'x' + photo.height;

          file.key_name = key;

          videos.push( file );

          ready();
        });
      };
    };

    var key;

    for( key in files ){
      flow.parallel( each( key ));
    }

    flow.join().end( function (){
      req.videos = videos;

      next();
    });
  },
示例#8
0
文件: Event.js 项目: woomooinc/gv
    create : function ( args, next, creataed ){
      var img_data = args.img_data;

      var event = new this({
        title     : args.title,
        desc      : args.desc,
        buzz      : args.buzz,
        player_id : args.session_player_id
      });

      var flow = new Flow();

      if( img_data ){
        var dir = event.gen_dir();

        flow.series( function ( _next ){
          fs.exists( dir, function ( is_exist ){
            if( is_exist ) return _next()

            mkdirp( event.gen_dir(), function ( err ){
              if( err ) return _next( err );

              _next()
            });
          });
        });

        flow.series( function ( _next ){
          var format = img_data.type.split( '/' )[ 1 ];

          fs.rename( img_data.path, event.gen_new_path( format ), function ( err ){
            if( err ) return _next( err );

            _next();
          });
        });
      }

      flow.error( function ( err ){
        if( err ) return next( err );
      });

      flow.end( function ( _next ){
        event.save( function ( err, event ){
          if( err ) return next( err );

          creataed( event );
        });
      });
    }
示例#9
0
文件: core.js 项目: rayshih/ivodka
Vodka.prototype.run = function( done ){
  var self = this;
  var flow = new Flow();

  this.queue.forEach( function ( task ){
    flow.series( function( next ){
      TaskRunners[ task.type ]( task, self.ctx, self.options, next );
    });
  });

  flow.end( function(){
    done();
  });
};
示例#10
0
            }).save( function ( err, tag, count ){
              if( err ) return flow.end( function (){
                callback( err );
              });

              next();
            });
示例#11
0
文件: artist.js 项目: dreamerslab/sin
    this.links.forEach( function ( link_id, index ){
      flow.parallel( function ( ready ){
        Link.findByIdAndRemove( link_id, function ( err, link ){
          if( err ) return ready( err );

          ready();
        });
      });
    });
示例#12
0
文件: Artist.js 项目: dreamerslab/sin
    insert : function ( args, next, exist, created ){
      var self          = this;
      var flow          = new Flow();
      var args_for_link = {};
      var query         = {
        name : new RegExp( args.name, 'i' )
      };

      this.findOne( query, function ( err, artist ){
        if( err )    return next( err );
        if( artist ) return exist( artist );

        new self({
          name  : args.name,
          desc  : args.desc,
          thumb : args.thumb,
          cover : args.cover,
          links : []
        }).save( function ( err, artist ){
          if( err ) return next( err );

          var i = 1;
          var insert_init_link = function ( i ){
            return function ( next ){
              args_for_link = {
                title : args[ 'link_name' + i ],
                url   : args[ 'link' + i ]
              };

              Link.insert( args_for_link,
                function ( err ){
                  LOG.error( 500, 'Link insert fail', err );
                  next();
                },
                function ( link ){
                  link.add_to_artists( artist, next );
                });
            };
          };

          for( ; i < 6; i++ ){
            flow.series( insert_init_link( i ));
          }

          flow.error( next ).end( function (){
            created( artist );
          });
        });
      });
    },
示例#13
0
  merge_uploads : function ( req, res, next ){
    var files  = req.files;
    var photos = [];
    var format = '';
    var flow   = new Flow();
    var each   = function ( key ){
      return function ( ready ){
        var file = files[ key ];

        if( file.size == '0' ) return ready();

        img.check_size( file.path, function ( err, photo ){
          req.body[ key + '_name' ] = file.name;
          req.body[ key + '_size' ] = photo.width + 'x' + photo.height;

          format = file.name.match( /.(png|jpg|jpeg)$/i );

          file.format   = format ? format[ 0 ] : file.type;
          file.key_name = key;

          photos.push( file );
          ready();
        });
      };
    };

    var key;

    for( key in files ){
      flow.parallel( each( key ));
    }

    flow.join().end( function (){
      req.photos = photos;
      next();
    });
  },
示例#14
0
          self.findOne({ name : name }, function ( err, tag ){
            if( err ) return flow.end( function (){
              callback( err );
            });

            if( tag ) return next();

            new self({
              name : name
            }).save( function ( err, tag, count ){
              if( err ) return flow.end( function (){
                callback( err );
              });

              next();
            });
          });
示例#15
0
      names.forEach( function ( name ){
        flow.series( function ( name, next ){
          self.findOne({ name : name }, function ( err, tag ){
            if( err ) return flow.end( function (){
              callback( err );
            });

            if( tag ) return next();

            new self({
              name : name
            }).save( function ( err, tag, count ){
              if( err ) return flow.end( function (){
                callback( err );
              });

              next();
            });
          });
        }, name );
      });
示例#16
0
module.exports = function boot( base_dir, options, callback ){
  if( arguments.length <= 2 ){
    callback = arguments[ 1 ];
    options = {};
    base_dir = arguments[ 0 ];
  }

  var flow = new Flow();

  // set global variables
  flow.series( function ( next ){
    require( './global' )( base_dir, next );
  }).

  // load logger
  series( function ( next ){
    require( CORE_DIR + '/logger' );
    // this has to go after the `require`
    LOG.sys( 'loading core module: logger' );
    next();
  }).

  // load util
  series( function ( next ){
    LOG.sys( 'loading core module: utils' );
    require( CORE_DIR + '/utils' );
    next();
  }).

  // load model
  series( function ( next ){
    var mongoose = require( 'mongoose' );
    var args = {
      mongoose : mongoose
    };

    if( options.schema ){
      args.schema_name = options.schema;
    }

    LOG.sys( 'loading core module: model' );
    require( CORE_DIR + '/model' )( args, next );
  }).

  // load express
  series( function ( model_names, next ){
    LOG.sys( 'loading core module: express' );
    require( CORE_DIR + '/express' )( next );
  }).

  // load lib
  parallel( function ( results, ready ){
    var app = results[ 0 ];

    LOG.sys( 'loading core module: lib' );
    require( CORE_DIR + '/lib' )( app, ready );
  }).

  // load assets
  parallel( function ( results, ready ){
    var app = results[ 0 ];

    LOG.sys( 'loading core module: assets' );
    require( CORE_DIR + '/assets' )( app, ready );
  }).

  join().

  // start server
  series( function ( results, next ){
    var app = results[ 0 ][ 0 ];

    LOG.sys( 'loading core module: server' );
    require( CORE_DIR + '/server' )( app, next );
  }).

  // load 'after server start libs'
  end( function ( servers, app ){
    LOG.sys( 'loading core module: started' );
    require( CORE_DIR + '/started' )( servers, app );

    if( callback ) callback();
  });
};
示例#17
0
  init : function ( callback ){

    // clearing all collections
    flow.series( function( next ){
      User.collection.drop( function (){
        Topic.collection.drop( function (){
          Comment.collection.drop( function (){
            Cache.collection.drop( function (){
              Tag.collection.drop( function (){
                Notif.collection.drop( function (){
                  next();
                }); // Notif.collection
              }); // Tap.collection
            }); // Cache.collection
          }); // Comment.collection
        }); // Topic.collection
      }); // User.collection
    });

    // creating users
    var i = 10;

    for(; i--;){
      flow.parallel( function ( ready ){
        var user = random_user();
        new User( user ).save( function ( err, user, count ){
          ready();
        });
      });
    }

    flow.join();

    // creating topics
    var j = 100;

    for(; j--;){
      flow.series( function ( ready ){
        User.find( function ( err, users ){
          // get a random user
          var user   = users[ random( users.length )];
          var topic  = random_topic();
          var string = Faker.Lorem.words( random( 5 )).join(', ');

          topic.user_id   = user;
          topic.tag_names = Tag.extract_names( string );

          new Topic( topic ).save( function ( err, topic, count ){
            ready();
          });
        });
      });
    }

    // create comments
    var k = 150;

    for(; k--;){
      flow.series( function ( ready ){
        User.find( function ( err, users ){
          // get a random user
          var user = users[ random( users.length )];

          Topic.find( function ( err, topics ){
            // get a random topic
            var topic   = topics[ random( topics.length )];
            var comment = random_comment();

            comment.user_id  = user;
            comment.topic_id = topic;

            new Comment( comment ).save( function ( err, comment, count ){
              ready();
            });
          });
        });
      });
    }

    flow.end( function (){
      LOG.debug( 'seed data filled' );

      callback && callback();
    });
  }
示例#18
0
文件: core.js 项目: rayshih/ivodka
 this.queue.forEach( function ( task ){
   flow.series( function( next ){
     TaskRunners[ task.type ]( task, self.ctx, self.options, next );
   });
 });
示例#19
0
// Benchmarking mongoose's populate, and compare
// with other ways to pull docs

var mongoose = require( "mongoose" );
var Schema   = mongoose.Schema;
var ObjectId = Schema.ObjectId;
var Flow     = require( 'node.flow' );
var flow     = new Flow();

mongoose.connect("mongodb://localhost/populate_performance_db");

var UserSchema = new Schema({
  name  : { type : String, required: true },
  email : { type : String, required: true },
  posts : [{ type : ObjectId, ref : 'Post' }]
});

var PostSchema = new Schema({
  user_id : { type : ObjectId, ref : 'User' },
  content : { type : Number, required : true }
});

var User    = mongoose.model( 'User', UserSchema );
var Post    = mongoose.model( 'Post', PostSchema );

// clear db data
flow.series( function ( next ){
  User.collection.drop( function (){
    Post.collection.drop ( function (){
      next();
    });
示例#20
0
function coke( base_dir ){
  var flow = new Flow();

  // set global variables
  flow.series( function ( next ){
    require( './lib/global' )( base_dir, next );
  }).

  // load logger
  series( function ( next ){
    require( CORE_DIR + 'logger' );
    // this has to go after the `require`
    LOG.sys( 'loading core module: logger' );
    next();
  }).

  // load util
  series( function ( next ){
    LOG.sys( 'loading core module: utils' );
    require( CORE_DIR + 'utils' );
    next();
  }).

  // load model
  series( function ( next ){
    LOG.sys( 'loading core module: model' );
    require( CORE_DIR + 'model' )( next );
  }).

  // load express
  series( function ( next ){
    LOG.sys( 'loading core module: express' );
    require( CORE_DIR + 'express' )( next );
  }).

  // load lib
  parallel( function ( results, ready ){
    var app = results[ 0 ];

    LOG.sys( 'loading core module: lib' );
    require( CORE_DIR + 'lib' )( app, ready );
  }).

  // load helper
  parallel( function ( results, ready ){
    var app = results[ 0 ];

    LOG.sys( 'Loading helper: application' );
    require( HELPER_DIR + 'application' )( app );
    ready();
  }).

  // load assets
  parallel( function ( results, ready ){
    var app = results[ 0 ];

    LOG.sys( 'loading core module: assets' );
    require( CORE_DIR + 'assets' )( app, ready );
  }).

  join().

  //load controller_brige
  series( function ( results, next ){
    var app = results[ 0 ][ 0 ];

    LOG.sys( 'loading core module: controller_bridge' );
    require( CORE_DIR + 'controller_bridge' )( app, next );
  }).

  // start server
  series( function ( app, next ){
    LOG.sys( 'loading core module: server' );
    require( CORE_DIR + 'server' )( app, next );
  }).

  // load 'after server start libs'
  end( function ( app ){
    LOG.sys( 'loading core module: started' );
    require( CORE_DIR + 'started' )( app );
  });
};