def vcs_error(qi, e): """Handles exceptions that come up during VCS operations. A message is added to the user's message queue.""" log.debug("Handling VCS error: %s", e) s = database._get_session() user = qi.message['user'] # if the user hadn't already been looked up, go ahead and pull # them out of the database if isinstance(user, basestring): user = User.find_user(user) else: s.add(user) # if we didn't find the user in the database, there's not much # we can do. if user: if isinstance(e, (FSException, main.UVCError)): # for exceptions that are our types, just display the # error message tb = str(e) else: # otherwise, it looks like a programming error and we # want more information tb = format_exc() message = dict(jobid=qi.id, output=tb, error=True) message['asyncDone'] = True retval = Message(user_id=user.id, message=simplejson.dumps(message)) s.add(retval)
def post_message(self): s = database._get_session() message_body = dict(jobid=self.qid, asyncDone=False, output="%s %s" % (self.line_count, self.label)) message = Message(user_id=self.user_id, message=simplejson.dumps(message_body)) s.add(message) s.commit()
def clone_run(qi): """Runs the queued up clone job.""" message = qi.message s = database._get_session() user = User.find_user(message['user']) message['user'] = user result = _clone_impl(**message) result.update(dict(jobid=qi.id, asyncDone=True)) retvalue = Message(user_id=user.id, message=simplejson.dumps(result)) s.add(retvalue) config.c.stats.incr('vcs_DATE')
def file_done(self): super(BespinOmniSync, self).file_done() if time.time() - self.last_display_time > 5: s = _get_session() message_body = dict(jobid=self.qid, asyncDone=False, output="%s files and %s bytes copied" % (self.file_counter, self.bytes_total)) message = Message(user_id=self.user_id, message=dumps(message_body)) s.add(message) s.commit() self.last_display_time = time.time()
def clone_run(qi): """Runs the queued up clone job.""" message = qi.message s = database._get_session() user = User.find_user(message['user']) message['user'] = user # wrap the output in "output" in a new dictionary, because # the client will peel off one layer from this. result = dict(output=_clone_impl(qid=qi.id, **message)) result.update(dict(jobid=qi.id, asyncDone=True)) retvalue = Message(user_id=user.id, message=simplejson.dumps(result)) s.add(retvalue) config.c.stats.incr('vcs_DATE')
def deploy_impl(qi): """Executed via the worker queue to actually deploy the project.""" message = qi.message kcpass = message['kcpass'] options = _OptionHolder(message['options']) s = _get_session() user = User.find_user(message['user']) project = get_project(user, user, message['project']) pdo = ProjectDeploymentOptions.get(project) keychain = DeploymentKeyChain(user, kcpass) credentials = keychain.get_credentials_for_project(project) cwd = os.getcwd() keyfile = None options.username = credentials['username'] if credentials['type'] == 'ssh': keyfile = TempSSHKeyFile() keyfile.store(credentials['ssh_public_key'], credentials['ssh_private_key']) options.sshkey = keyfile.filename else: options.password = credentials['password'] desturl = "sftp://%s/%s" % (quote(pdo.remote_host, safe=""), quote(pdo.remote_directory)) try: os.chdir(project.location) log.debug("Computed destination URL: %s", desturl) log.debug("Running with options: %r", options) error, output = _launch_sync(qi.id, user.id, desturl, options) # there's an extra layer around the output that is # expected by the client result = dict(output=dict(output=output, error=error)) result.update(dict(jobid=qi.id, asyncDone=True)) retvalue = Message(user_id=user.id, message=dumps(result)) s.add(retvalue) finally: if keyfile: keyfile.delete() os.chdir(cwd)
def deploy_error(qi, e): """Handles errors that come up during deployment.""" log.debug("Handling deploy error: %s", e) s = _get_session() user = qi.message['user'] # if the user hadn't already been looked up, go ahead and pull # them out of the database if isinstance(user, basestring): user = User.find_user(user) else: s.add(user) # if we didn't find the user in the database, there's not much # we can do. if user: # it looks like a programming error and we # want more information tb = format_exc() print "E:", tb message = dict(jobid=qi.id, output=dict(output=tb, error=True)) message['asyncDone'] = True retval = Message(user_id=user.id, message=dumps(message)) s.add(retval)