Example #1
0
def redeploy():
    suns_folder = get_suns_folder()
    names = os.listdir(suns_folder)

    for name in names:
        _base, extension = os.path.splitext(name)
        if not extension == ".sun": continue

        _name = name[:-4]
        file_path = os.path.join(suns_folder, "%s.sun" % _name)
        execute_sun = get_execute_sun(_name, file_path)
        quorum.run_back(execute_sun)
Example #2
0
    def schedule(self):
        # retrieves the various required project attributes
        # for the scheduling process they are going to be used
        # in the scheduling process
        next_time = self.next_time or time.time()

        # retrieves the "custom" run function to be used as the
        # work for the scheduler
        _run = self.get_run(schedule = True)

        # inserts a new work task into the execution (thread)
        # for the next (target time)
        quorum.run_back(_run, target_time = next_time)
Example #3
0
    def schedule(self):
        # retrieves the various required project attributes
        # for the scheduling process they are going to be used
        # in the scheduling process
        next_time = self.next_time or time.time()

        # retrieves the "custom" run function to be used as the
        # work for the scheduler
        _run = self.get_run(schedule = True)

        # inserts a new work task into the execution (thread)
        # for the next (target time)
        quorum.run_back(_run, target_time = next_time)
Example #4
0
    def ping(self):
        # retrieves the server again to ensure that the data
        # is correct in it
        self.server = self.server.reload()

        # retrieves the various attribute values from the server
        # that are going to be used in the method
        instance_id = self.server.instance_id
        name = self.server.name
        url = self.server.url
        method = self.server.val("method", "GET")

        # parses the provided url values, retrieving the various
        # components of it to be used in the ping operation
        url_s = quorum.legacy.urlparse(url)
        scheme = url_s.scheme
        hostname = url_s.hostname
        port = url_s.port
        path = url_s.path

        # retrieves the connection class to be used according
        # to the scheme defined in the url
        connection_c = quorum.legacy.HTTPSConnection if scheme == "https" else quorum.legacy.HTTPConnection

        # retrieves the timestamp for the start of the connection
        # to the remote host and then creates a new connection to
        # the remote host to proceed with the "ping" operation
        start_time = time.time()
        connection = connection_c(hostname, port)
        try:
            connection.request(method, path, headers=HEADERS)
            response = connection.getresponse()
        except:
            response = None
        finally:
            connection.close()
        end_time = time.time()
        latency = int((end_time - start_time) * 1000.0)

        # retrieves both the status and the reason values
        # defaulting to "down" values in case the response
        # is not available
        status = response and response.status or 0
        reason = response and response.reason or "Down"

        # checks if the current status code is in the
        # correct range these are considered the "valid"
        # status codes for an up server
        up = (status / 100) in (2, 3)

        # prints a debug message about the ping operation
        # with the complete diagnostics information
        quorum.debug("%s :: %s %s / %dms" % (url, status, reason, latency))

        # inserts the log document into the data source so that
        # the information is registered in the proper place
        _log = dict(
            enabled=True,
            instance_id=instance_id,
            name=name,
            url=url,
            up=up,
            status=status,
            reason=reason,
            latency=latency,
            timestamp=start_time,
        )
        _log = log.Log.new(model=_log)
        _log.save()

        # verifies the correct changing orders (from up to down and
        # from down to up) this will trigger the proper events
        change_down = not self.server.val("up", True) == up and not up
        change_up = not self.server.val("up", True) == up and up

        # updates the server information, so that it matched the last
        # available information from the last "ping" operation
        self.server.up = up
        self.server.latency = latency
        self.server.timestamp = start_time
        self.server.save()

        # in case there's a change from server state up to down, or
        # down to up (reversed) must trigger the proper event so
        # that the user is notified about the change
        if change_down:
            self.on_down()
        if change_up:
            self.on_up()

        # retrieves the current time and uses that value to
        # re-insert a new task into the execution thread, this
        # is considered the re-schedule operation
        current_time = time.time()
        self.server.enabled and quorum.run_back(self.ping, target_time=current_time + self.timeout)
Example #5
0
 def schedule(self):
     quorum.run_back(self.ping)