module.exports = g.lift(function* upload(stream, idOrPath, tag, done) {
    try {
        var blob = blobManager.create(account);
        var tx = db.begin();
        var blobId = yield blob.put(stream);
        var file = yield self.byUuidOrPath(idOrPath).get();

        var previousId = file ? file.version : null;
        version = {
            userAccountId: userAccount.id,
            date: new Date(),
            blobId: blobId,
            creatorId: userAccount.id,
            previousId: previousId,
        };
        version.id = Version.createHash(version);
        yield Version.insert(version).execWithin(tx);
        if (!file) {
            var splitPath = idOrPath.split('/');
            var fileName = splitPath[splitPath.length - 1];
            file = {
                id: uuid.v1(),
                userAccountId: userAccount.id,
                name: fileName,
                version: version.id
            }
            var query = yield self.createQuery(idOrPath, file);
            yield query.execWithin(tx);
        }
        yield FileVersion.insert({fileId: file.id, versionId: version.id})
            .execWithin(tx);
        yield File.whereUpdate({id: file.id}, {version: version.id})
            .execWithin(tx);
        tx.commit();
        done();
    } catch (err) {
        tx.rollback();
        done(err);
    }
});
var processRequest = gen.lift(function*(params, route_type) {
	//get state object for CallSid
	var body = undefined;
	var state = update_state(params.CallSid, params.CallStatus);  //TODO: this is a memory leaky problem. need to fix
	
	try {
		switch(route_type) {
			case 'call':
				if (!state.closed) body = yield helper.voiceCallResponse(params);
				else body = yield helper.buildMessageTwiml('Failed to complete your call.  Goodbye');
				break;
			case 'sms':
				if (!state.closed) body = yield helper.smsResponse(params);
				else body = yield helper.buildMessageTwiml('Failed to complete your sms request.  Goodbye');
				break;
			case 'status':
				yield helper.callStatusResponse(params);
				body = undefined;
				break;
			case 'action':
				if (!state.closed) {
					if ('Digits' in params) body = yield helper.callActionGatherResponse(params);
					else if ('SmsSid' in params) body = yield helper.callActionSmsResponse(params);
					else if ('DialCallSid' in params) body = yield helper.callActionDialResponse(params);
					else body = yield helper.callActionRouterResponse(params);
				} else body = yield helper.buildMessageTwiml('The call has already ended.  Goodbye');
				break;
			case 'dequeue':
				body = yield helper.callDequeueReponse(params);
				break;
			case 'wait':
				body = yield helper.queueWaitReponse(params);
				break;
			default:
				body = undefined;
				break;
		}
		console.log('returning body')
		return body;
	} catch(e) {
		console.log('Error processing twiml request - ', e.stack);
		body = yield helper.buildMessageTwiml('An error was encountered, terminating session.  Goodbye');
		console.log('returning body error')
		return body;
	}
});
Exemple #3
0
/**
* Generator function that runs the benchmark
*/
function *runGen(){
  var result;
  try{
    // retrieve Mongoose session objects for session and exercise
    session = yield Session.findOne({_id: session._id}).exec();
    exercise = yield Exercise.findOne({_id: exercise._id}).exec();
    questions = yield Question.find({}).exec();

    var l = whitelist.length;
    
    for (var i=0; i<l; i++){
      //get random user
      var index = Math.floor(Math.random() * whitelist.length);
      var whitelistEntry = whitelist[index];
      whitelist.splice(index, 1);

      //create jobCounter entry
      jobCounters[whitelistEntry._id]=1;

      //create answers
      var answers=[];
      questions.forEach(function(question){
        answers.push({
          exercise : exercise._id,
          question : question._id,
          session: session._id,
          submission : ['basic-question-' + question._id + '-user-' + index],
          confidence : 3,
          answeree : whitelistEntry._id
        });
      });

      //persist to mongo
      answers = yield nodefn.lift(Answer.create.bind(Answer))(answers);

      //populate question field
      yield when.map(answers, gen.lift(function *populateQuestions(answer){
        yield nodefn.lift(answer.populate.bind(answer))('question');
      }));
     
      var startAssessmentCreation = new Date;
      result = yield assManager.enqueue(session._id, exercise, answers)
      // console.log ( "Created assessments in %s ms for user %s",
      //  new Date - startAssessmentCreation, whitelistEntry.screenName );
      // console.log('after queue:Using %s of memory', bytesToSize(process.memoryUsage().heapUsed));

      /* ---------- ACTUAL BENCHMARK STARTS HERE ---------- */
      start = new Date;

      // find next assessment job for each of the viewers
      var nextJob = yield assManager.getNextAssessmentJob(session._id, exercise, whitelistEntry._id);

      console.log("Searched for assessment #%d in %d ms for \
user %d of %d %s",jobCounters[whitelistEntry._id], (new Date - start), i+1, l, whitelistEntry.screenName);

      yield startJob(nextJob, exercise, whitelistEntry);

      var nextJobs = yield assManager.getNextJobForIdleViewers(session._id, exercise);
      
      //start jobs for idle users in parallell, no need to wait with a yield
      when.map(nextJobs, function(job){
        return startJob(job, exercise, job.assessor)
      }).catch(function(err){
        console.log(err.stack)
      })

      /* ---------- ACTUAL BENCHMARK ENDS HERE ---------- */

      if(mode === 'avg'){
         yield wait( ~~expSample(lamda))
      }  
    }

  }catch(err){
    console.log(err.stack)
  }
  
  return result;
}
Exemple #4
0
}

/* Stats */
var getPresentationStats = gen.lift(function *getPresentationStats(req, res, next) {
  var slideshow ;
  try{
    var slideshow = yield Slideshow.findById(req.params.presentationId).exec();
  }catch(err){
    appLogger.error("Presentation %s not found", req.params.presentationId);
    appLogger.error(err.message, { err: err.stack });
    res.status(404);
    return res.render('404', {'msg': 'Presentation not found'});
  }

  try{
    var statsObj = yield stats.getPresentationStats(slideshow);
    statsObj.presentationId = req.params.presentationId;
    statsObj.username = req.user.username;
    statsObj.host = ASQ.appHost;
    statsObj.port = app.get('port');
    return res.render('presentationStats', statsObj);
  }catch(err){
    appLogger.error("Presentation %s not found", req.params.presentationId);
    appLogger.error(err.message, { err: err.stack });
    next(err)
  }
  
})

module.exports = {
  editPresentation      : editPresentation,
Exemple #5
0
   }

   try{
    job.status = "active";
    yield nodefn.lift(job.save.bind(job))();
    
    // console.log("Assigned assessment #%d to user %s",
    // jobCounters[assessor._id] , assessor.screenName);

    setTimeout(submitJob, ~~expSample(lamda), job, exercise, assessor);
   }catch(err){
    console.log(err.stack)
   }        
}

var startJob = gen.lift(startJobGen);

/**
* Generator function that runs the benchmark
*/
function *runGen(){
  var result;
  try{
    // retrieve Mongoose session objects for session and exercise
    session = yield Session.findOne({_id: session._id}).exec();
    exercise = yield Exercise.findOne({_id: exercise._id}).exec();
    questions = yield Question.find({}).exec();

    var l = whitelist.length;
    
    for (var i=0; i<l; i++){