Example #1
0
 def _update_state(self):
     new_state = self._calc_state()
     if new_state == self.state:
         return
     self.state = new_state
     self.history.append((new_state, time.time()))
     logging.info("new state %s" % new_state)
Example #2
0
def Runner(pgrpguard_binary=None):
    child_err_rd, child_err_wr = os.pipe()
    channel_parent, channel_child = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM, 0)

    pid = os.fork()

    if pid:
        os.close(child_err_wr)
        channel_child.close()
        del channel_child
        logging.info("_Server pid = %s" % pid)
        return _Client(pid, channel_parent) # child_err_rd
    else:
        try:
            channel_parent.close()
            del channel_parent
            os.close(child_err_rd)
        except BaseException as e:
            try:
                os.write(2, '%s\n' % e)
            except:
                pass
            os._exit(1)
        set_thread_name("rem-RunnerSrv")
        _run_executor_wrapper(child_err_wr, channel_child, pgrpguard_binary)
Example #3
0
def cleanup_directory(directory, to_keep, max_removed_items_to_output=100):
    removed = []

    files = os.listdir(directory)

    for basename in files:
        if basename in to_keep:
            continue

        filename = directory + '/' + basename

        remove = shutil.rmtree \
            if os.path.isdir(filename) and not os.path.islink(filename) \
            else os.unlink

        try:
            remove(filename)
        except Exception as e:
            logging.error("Can't remove %s: %s" % (filename, e))
        else:
            removed.append(basename)

    if removed:
        logging.info('%d files removed from %s: %s' \
            % (len(removed), directory, ', '.join(removed[:max_removed_items_to_output])))
Example #4
0
File: job.py Project: cgorbit/rem
    def _append_results(self):
        job = self._job

        def append_result(result):
            job.results.append(result)

        if self._timedout:
            append_result(TimeOutExceededResult(job.id))

        as_legacy_start_error = self._process_start_error or self._environment_error

        if as_legacy_start_error:
            append_result(JobStartErrorResult(job.id, str(as_legacy_start_error)))

        elif self._finish_time:
            message = self._stderr_summary or ""
            if job.output_to_status and self._stdout_summary: # FIXME Second check what for?
                message += self._stdout_summary

            append_result(
                CommandLineResult(
                    self._process.returncode,
                    self._start_time,
                    self._finish_time,
                    message
                )
            )

        if self.returncode_robust != 0 and job.tries >= job.max_try_count:
            logging.info("%s result: TriesExceededResult", job)
            append_result(TriesExceededResult(job.tries))
Example #5
0
 def Clear(self, final_time):
     logging.info("TagLogger.Clear(%s)", final_time)
     dirname, db_filename = os.path.split(self.db_filename)
     for filename in os.listdir(dirname):
         if filename.startswith(db_filename) and filename != db_filename:
             file_time = int(filename.split("-")[-1])
             if file_time <= final_time:
                 os.remove(os.path.join(dirname, filename))
Example #6
0
 def _wait_stop(self):
     for w in [self._read_thread, self._write_thread]:
         t = w()
         if t:
             t.join()
     _, status = os.waitpid(self._server_pid, 0)
     logging.info('_Server exited with %s' % status)
     if status:
         raise RuntimeError("Runner.Server process exited abnormally %d" % status)
Example #7
0
    def Rotate(self, timestamp):
        logging.info("TagLogger.Rotate")

        with self._db_lock:
            if self._db:
                self._db.sync()
                self._db.close()

            if os.path.exists(self.db_filename):
                new_filename = "%s-%d" % (self.db_filename, timestamp)
                os.rename(self.db_filename, new_filename)

            self._reopen()
Example #8
0
    def _stop(self, wait=True, timeout=None):
        if self._stopped:
            return

        new_value = self._ST_WAIT if wait else self._ST_NOWAIT

        with self._lock:
            if self._should_stop < new_value:
                logging.info("Stopping YtTags.Client (%s)" % '_ST_WAIT' if wait == self._ST_WAIT else '_ST_NOWAIT')
                self._do_stop(new_value)

            elif self._should_stop > new_value:
                logging.warning("stop() called with lower stop-level")

        self._connect_thread.join(timeout) # TODO sleeps
Example #9
0
    def convert_in_memory_tags_to_cloud_if_need(self):
        if not self._has_cloud_setup():
            return False

        updates = []

        for tag_name, tag in self.inmem_items.iteritems():
            must_be_cloud = self._is_cloud_tag_name(tag_name) \
                and not tag.IsRemote() # Hack for disable_remote_tags

            if must_be_cloud == tag.IsCloud():
                continue

            elif must_be_cloud:
                if tag.IsLocallySet():
                    updates.append((tag_name, ETagEvent.Set))

                self._make_tag_cloud(tag)
            else:
                logging.error("Tag %s is cloud, but must not be" % tag_name)

        if not updates:
            return False

        logging.info("before conversion %d tags to CloudTag's" % len(updates))

        cloud = self._create_cloud_client(lambda ev: None)

        try:
            for bucket in split_in_groups(updates, 100000): # TODO Fix cloud_client.update
                cloud.update(bucket).get()
        finally:
            try:
                cloud.stop()
            except:
                logging.exception("Failed to stop temporary cloud client")

        logging.info("after conversion %d tags to CloudTag's" % len(updates))

        return True
Example #10
0
    def _connect_loop_inner(self):
        while True:
            with self._lock:
                if self._should_and_can_stop():
                    return

            if self._io:
                self._io._connection.close()
                if COUNT_IO:
                    rd, wr = self._io._connection.get_stats()
                    self._io_stats[0] += rd
                    self._io_stats[1] += wr
                self._io = None

            self._reconstruct_outgoing()

            # FIXME What if exception will throw here? self._broken? _push -> raise and fail futures

            io = self._io = self.IO()

            logging.info("Connecting to servers...")

            connection = self._create_connection()

            if not connection:
                break

            addr = (connection._host, connection._port)

            logging.info("Connected to %s" % (addr,))

            io._connection = connection

            with self._lock:
                self._io._connected = True
                #self._connection_state_changed.notify_all()

            io_threads = [
                ProfiledThread(target=self._read_loop, name_prefix='CldTg-ReadLoop'),
                ProfiledThread(target=self._write_loop, name_prefix='CldTg-WriteLoop')
            ]

            for t in io_threads:
                t.start()

            for t in io_threads:
                t.join()

            logging.info("Disconnected from %s" % (addr,))