示例#1
0
    def broadcast(self, data, delay=0):
        "广播一条消息"
        if not isinstance(data, (str, unicode)):
            data = utils.json_dumps(data)

        if delay > 0:
            utils.sleep(delay)

        try:
            resp = http.GET('%sbroadcast?content=%s' %
                            (self.admin_url, utils.urlencode(data)))
            return resp.text.strip().lower() == 'ok'
        except:
            return False
示例#2
0
	def sleepOneWithFireOnServiceStop(self, timeout):
		# Sleep
		for i in xrange(1, timeout + 1):
			if not self.isStarted:
				returnValue(None)

			yield sleep(1)
示例#3
0
	def sleepWithFireOnServiceStop(self, timeout, split):
		# Sleep
		for i in xrange(split, timeout + split, split):
			if self.loop == -1:
				returnValue(None)

			yield sleep(split)
示例#4
0
 def get_text(self, element):
     from core.utils import sleep
     max_attempts = 10
     attempt = 1
     obtained = False
     exception = None
     while attempt <= max_attempts and not obtained:
         try:
             text_value = self.wait_for_visible_element(
                 getattr(self, element)).text
             obtained = True
             return text_value
         except (StaleElementReferenceException, TimeoutException) as e:
             sleep(1)
             exception = e
         attempt += 1
     if not obtained:
         if exception:
             raise exception
         else:
             raise Exception(
                 "it has not been possible to get the text of the element")
示例#5
0
	def process_messages(self):
		if not self.isStarted:
			# Fail
			returnValue(None)

		self._process += 1

		# Try
		try:
			# Debug
			msg(self.name, 'process messages', system='-')

			success = None
			current = reactor.seconds()
			removed = []

			# Short
			delete = messages.delete
			append = removed.append

			# Confog
			oldLast = config.getint('garbage', 'old-last-messages')
			oldTime = config.getint('garbage', 'old-time-messages')

			# Clean messages
			for id, message in messages.getData().iteritems():
				if message.tos <= 0:
					if (message.last and (current - message.last) >= oldLast):
						# Remove message
						if DEBUG:
							msg(self.name, 'process messages', 'remove, old last', id, current - message.last, system='-')

						append(id)
					elif (message.last is None and (current - message.time) >= oldTime):
						# Remove message
						if DEBUG:
							msg(self.name, 'process messages', 'remove, old time', id, current - message.time, system='-')

						append(id)

			# Sleep
			(yield sleep(1))

			for id in removed:
				# Remove message
				delete(id)

			# Debug
			msg(self.name, 'process messages stops', system='-')
		finally:
			self._process -= 1
示例#6
0
def should_see_text_step_impl(context, value, element, page):
    from core.utils import sleep
    max_attempts = 10
    attempt = 1
    checked = False
    exception = None
    error_message = ""
    while attempt <= max_attempts and not checked:
        try:
            page_class = get_page_class(page)
            context.lp = page_class(context.browser)
            text = context.lp.get_text(element)
            error_message = "{0} does not contains the value '{1}': '{2}'".format(element, value, text)
            assert_in(value, text, error_message)
            checked = True
        except AssertionError as e:
            sleep(1)
            exception = e
        attempt += 1
    if not checked:
        if exception:
            raise exception
        else:
            raise Exception(error_message)