Пример #1
0
    def post(self, instance_id):
        instance = self._getInstance(instance_id) or abort(404)

        query = request.get_json()
        # force async
        request.json['async'] = True

        machineName = query.get('machine', "")

        action = query.get('action')
        permission = states.get(action)
        if permission:
            if current_user.has_permission(permission, instance_id):
                if action == 'runScript':
                    job_id = instance.runScript(query.get('script'),
                                                machineName)
                elif action == 'rsync':
                    job_id = instance.rsync()
                elif action == 'sync':
                    job_id = instance.sync()
                else:
                    job_id = getattr(self, action)(instance_id, machineName)
            else:
                abort(403)
        console = redis_conn.get('{}:console'.format(job_id)) or ''
        return {'id': job_id, 'console': console}
Пример #2
0
def get_git_references(projectId):
    forceRefresh = bool(int(request.args.get('force')))
    project = Project.query.get(projectId)

    fullRefs = None
    if forceRefresh is False:
        fullRefs = redis_conn.get('project:{}:refs'.format(projectId))

    if fullRefs is None:
        with Connection():
            queue = Queue('low', connection=redis_conn)
            action = 'worker.get_git_references'

            job = queue.enqueue_call(
                func=action,
                timeout=900,
                args=(project.git_address, project.id)
            )
            while job.result is None:
                time.sleep(0.5)

            fullRefs = str(job.result)
            redis_conn.set('project:{}:refs'.format(projectId), fullRefs)

    return jsonify({'gitReferences': json.loads(fullRefs)})
Пример #3
0
 def get(self, instance_id, command_id=None):
     """Get a list of commands in queue for the instance
     or the specified command states+output"""
     if command_id is not None:
         try:
             # job = Job.fetch(str(command_id), connection=redis_conn)
             job = redis_conn.hgetall('rq:job:{}'.format(command_id))
             job.pop('data', None)
             job.pop('description', None)
         except Exception as e:
             print(e.message)
             abort(400)
         console = redis_conn.get('{}:console'.format(command_id)) or ''
         job.update({
             'id': command_id,
             'result': u'{}'.format(repr(job.get('result', ''))),
             'console': console
         })
         return job
     # find redis jobs for the instance
     jobs_key = 'jobs:{}'.format(instance_id)
     jobs = redis_conn.hkeys(jobs_key)
     # sort by jobid/time most recent first
     jobs.sort(reverse=True)
     return jobs
Пример #4
0
    def post(self, instance_id):
        instance = self._getInstance(instance_id) or abort(404)

        query = request.get_json()
        # force async
        request.json['async'] = True

        machineName = query.get('machine', "")

        action = query.get('action')
        permission = states.get(action)
        if permission:
            if current_user.has_permission(permission, instance_id):
                if action == 'runScript':
                    job_id = instance.runScript(
                        query.get('script'), machineName)
                elif action == 'rsync':
                    job_id = instance.rsync()
                elif action == 'sync':
                    job_id = instance.sync()
                else:
                    job_id = getattr(self, action)(instance_id, machineName)
            else:
                abort(403)
        console = redis_conn.get('{}:console'.format(job_id)) or ''
        return {
            'id': job_id,
            'console': console
        }
Пример #5
0
def get_git_references(projectId):
    forceRefresh = bool(int(request.args.get('force')))
    project = Project.query.get(projectId)

    fullRefs = None
    if forceRefresh is False:
        fullRefs = redis_conn.get('project:{}:refs'.format(projectId))

    if fullRefs is None:
        with Connection():
            queue = Queue('low', connection=redis_conn)
            action = 'worker.get_git_references'

            job = queue.enqueue_call(
                func=action,
                timeout=900,
                args=(project.git_address, project.id)
            )
            while job.result is None:
                time.sleep(0.5)

            fullRefs = str(job.result)
            redis_conn.set('project:{}:refs'.format(projectId), fullRefs)

    return jsonify({'gitReferences': json.loads(fullRefs)})
Пример #6
0
 def get(self, instance_id, command_id=None):
     """Get a list of commands in queue for the instance
     or the specified command states+output"""
     if command_id is not None:
         try:
             # job = Job.fetch(str(command_id), connection=redis_conn)
             job = redis_conn.hgetall('rq:job:{}'.format(command_id))
             job.pop('data', None)
             job.pop('description', None)
         except Exception as e:
             print(e.message)
             abort(400)
         console = redis_conn.get('{}:console'.format(command_id)) or ''
         job.update(
             {'id': command_id,
              'result': u'{}'.format(repr(job.get('result', ''))),
              'console': console})
         return job
     # find redis jobs for the instance
     jobs_key = 'jobs:{}'.format(instance_id)
     jobs = redis_conn.hkeys(jobs_key)
     # sort by jobid/time most recent first
     jobs.sort(reverse=True)
     return jobs
Пример #7
0
def _read_console(jobId):
    console = redis_conn.get('{}:console'.format(jobId))
    if console is None:
        console = ''
    return console
Пример #8
0
def _read_console(jobId):
    console = redis_conn.get('{}:console'.format(jobId))
    if console is None:
        console = ''
    return console