示例#1
0
    def find_device(self):
        # FIXME: refactor.
        device_name = None
        count = self.machine.increment_counter(self.state_name)
        request = data.dump_requests(self.machine.request_id)[0]
        if request['requested_device'] == 'any':
            free_devices = data.get_free_devices()
            if free_devices:
                device_id = random.randint(0, len(free_devices) - 1)
                device_name = free_devices[device_id]
                logs.request_logs.add(
                    self.machine.request_id,
                    'assigning device %s' % device_name)
            else:
                self.logger.info('no free devices')
        else:
            device_name = request['requested_device']
            self.logger.info('assigning requested device %s' % device_name)

        if device_name and data.reserve_device(self.machine.request_id,
                                               device_name):
            self.logger.info('request succeeded')
            self.machine.goto_state(contacting_lifeguard)
        else:
            self.logger.warn('request failed!')
            if request['requested_device'] == 'any':
                if count >= self.MAX_ANY_REQUESTS:
                    logs.request_logs.add(
                        self.machine.request_id,
                        'hit maximum number of attempts; giving up')
                    self.machine.goto_state(device_not_found)
            else:
                if count >= self.MAX_SPECIFIC_REQUESTS:
                    logs.request_logs.add(
                        self.machine.request_id,
                        'requested device %s is busy' % device_name)
                    self.machine.goto_state(device_busy)
示例#2
0
    def find_device(self):
        # FIXME: refactor.
        device_name = None
        count = self.machine.increment_counter(self.state_name)
        request = data.dump_requests(self.machine.request_id)[0]
        if request['requested_device'] == 'any':
            free_devices = data.get_free_devices()
            if free_devices:
                device_id = random.randint(0, len(free_devices) - 1)
                device_name = free_devices[device_id]
                logs.request_logs.add(self.machine.request_id,
                                      'assigning device %s' % device_name)
            else:
                self.logger.info('no free devices')
        else:
            device_name = request['requested_device']
            self.logger.info('assigning requested device %s' % device_name)

        if device_name and data.reserve_device(self.machine.request_id,
                                               device_name):
            self.logger.info('request succeeded')
            self.machine.goto_state(contacting_lifeguard)
        else:
            self.logger.warn('request failed!')
            if request['requested_device'] == 'any':
                if count >= self.MAX_ANY_REQUESTS:
                    logs.request_logs.add(
                        self.machine.request_id,
                        'hit maximum number of attempts; giving up')
                    self.machine.goto_state(device_not_found)
            else:
                if count >= self.MAX_SPECIFIC_REQUESTS:
                    logs.request_logs.add(
                        self.machine.request_id,
                        'requested device %s is busy' % device_name)
                    self.machine.goto_state(device_busy)
示例#3
0
 def GET(self):
     args, _ = templeton.handlers.get_request_parms()
     include_closed = args.get('include_closed', False)
     return dict(requests=data.dump_requests(include_closed=include_closed))
示例#4
0
 def GET(self):
     args, _ = templeton.handlers.get_request_parms()
     include_closed = args.get('include_closed', False)
     return dict(requests=data.dump_requests(include_closed=include_closed))