Module mfplugin.command

Classes

class Command (plugin_home, plugin_name, name, doc_fragment, custom_fragment)
Expand source code
class Command(object):

    def __init__(self, plugin_home, plugin_name, name, doc_fragment,
                 custom_fragment):
        self.plugin_name = plugin_name
        self.plugin_home = plugin_home
        self._doc_fragment = doc_fragment
        self._custom_fragment = custom_fragment
        self.name = name
        self._type = "command"

    def duplicate(self, new_name=None):
        c = self.__class__
        if new_name is None:
            new_name = self.name
        return c(self.plugin_home, self.plugin_name, new_name,
                 dict(self._doc_fragment), dict(self._custom_fragment))

    @property
    def cmd_and_args(self):
        return self._doc_fragment["_cmd_and_args"]

    @property
    def numprocesses(self):
        return self._doc_fragment["numprocesses"]

    @property
    def log_split_stdout_stderr(self):
        return self._doc_fragment["log_split_stdout_stderr"]

    @property
    def log_split_multiple_workers(self):
        return self._doc_fragment["log_split_multiple_workers"]

    @property
    def graceful_timeout(self):
        return self._doc_fragment["graceful_timeout"]

    @property
    def max_age(self):
        return self._doc_fragment["max_age"]

    @property
    def rlimit_as(self):
        return self._doc_fragment["rlimit_as"]

    @property
    def rlimit_nofile(self):
        return self._doc_fragment["rlimit_nofile"]

    @property
    def rlimit_stack(self):
        return self._doc_fragment["rlimit_stack"]

    @property
    def rlimit_fsize(self):
        return self._doc_fragment["rlimit_fsize"]

    @property
    def debug(self):
        return self._doc_fragment["debug"]

    def _get_log_proxy_args(self):
        if self.log_split_multiple_workers and self.numprocesses > 1:
            std_prefix = f"{MFMODULE_RUNTIME_HOME}/log/" \
                f"{self._type}_{self.plugin_name}_{self.name}_" \
                "worker$(circus.wid)"
        else:
            std_prefix = f"{MFMODULE_RUNTIME_HOME}/log/" \
                f"{self._type}_{self.plugin_name}_{self.name}"
        if self.numprocesses <= 1:
            use_locks = ""
        else:
            use_locks = "--use-locks"
        if self.log_split_stdout_stderr:
            res = "%s --stdout %s.stdout " \
                "--stderr %s.stderr" % (use_locks, std_prefix, std_prefix)
        else:
            res = "%s --stdout %s.log " \
                "--stderr STDOUT" % (use_locks, std_prefix)
        return res

    @property
    def circus_cmd_and_args(self):
        res = "%s -- plugin_wrapper %s -- %s" % \
            (self._get_log_proxy_args(),
             self.plugin_name,
             self.cmd_and_args)
        res = res.replace("{plugin_name}", self.plugin_name)
        res = res.replace("{plugin_dir}", self.plugin_home)
        res = res.replace("{%s_name}" % self._type, self.name)
        return res

    @property
    def type(self):
        return self._type

Subclasses

Instance variables

prop circus_cmd_and_args
Expand source code
@property
def circus_cmd_and_args(self):
    res = "%s -- plugin_wrapper %s -- %s" % \
        (self._get_log_proxy_args(),
         self.plugin_name,
         self.cmd_and_args)
    res = res.replace("{plugin_name}", self.plugin_name)
    res = res.replace("{plugin_dir}", self.plugin_home)
    res = res.replace("{%s_name}" % self._type, self.name)
    return res
prop cmd_and_args
Expand source code
@property
def cmd_and_args(self):
    return self._doc_fragment["_cmd_and_args"]
prop debug
Expand source code
@property
def debug(self):
    return self._doc_fragment["debug"]
prop graceful_timeout
Expand source code
@property
def graceful_timeout(self):
    return self._doc_fragment["graceful_timeout"]
prop log_split_multiple_workers
Expand source code
@property
def log_split_multiple_workers(self):
    return self._doc_fragment["log_split_multiple_workers"]
prop log_split_stdout_stderr
Expand source code
@property
def log_split_stdout_stderr(self):
    return self._doc_fragment["log_split_stdout_stderr"]
prop max_age
Expand source code
@property
def max_age(self):
    return self._doc_fragment["max_age"]
prop numprocesses
Expand source code
@property
def numprocesses(self):
    return self._doc_fragment["numprocesses"]
prop rlimit_as
Expand source code
@property
def rlimit_as(self):
    return self._doc_fragment["rlimit_as"]
prop rlimit_fsize
Expand source code
@property
def rlimit_fsize(self):
    return self._doc_fragment["rlimit_fsize"]
prop rlimit_nofile
Expand source code
@property
def rlimit_nofile(self):
    return self._doc_fragment["rlimit_nofile"]
prop rlimit_stack
Expand source code
@property
def rlimit_stack(self):
    return self._doc_fragment["rlimit_stack"]
prop type
Expand source code
@property
def type(self):
    return self._type

Methods

def duplicate(self, new_name=None)