Exemple #1
0
    def run_job(self):

        self.duration = int(self.description.get("duration", DEFAULT_DURATION))

        # Keep grabbing work until there is no more work.
        process_type, command = self.get_task()
        if not process_type:
            self.log.info("No task available to start")
            return

        self._action("startproc")

        def handler(signum, frame):
            self.log.info("Shutting down process.")
            raise TimeoutException()
        signal.signal(signal.SIGALRM, handler)
        signal.alarm(self.duration)

        self.log.info("Starting process (%s %s)" % (process_type, command))
        try:
            if process_type == "wsgi":
                self.log.info("Installing gunicorn")
                console.run_in_venv(self.id_, "pip install gunicorn")
                self.wsgi(command)
            else:
                self.proc(command)

            self.log.info("Process terminated")
        except TimeoutException:
            self.log.info("Process completed")
            return

        signal.alarm(0)
Exemple #2
0
    def deploy(self):
        repo = self.description.get("repo")
        commit = self.description.get("commit", None)

        self.log.info("Deploying (%s)" % repo)
        repo_dir = os.path.join(JOBS_DIR, self.id_)

        def wait_for_deployment():
            while not os.path.exists(os.path.join(repo_dir, "__unlocked__.py")):
                time.sleep(1)

        # If the repo was already set up, great!
        if os.path.exists(repo_dir):
            wait_for_deployment()
            self.log.info("Job already configured")
            return

        # Create the directory to run the job in.
        try:
            os.mkdir(repo_dir)
        except OSError:
            if not os.path.exists(repo_dir):
                self.log.error("Permissions error when creating repo directory.")
                return
            wait_for_deployment()
            return

        # Clone the repo into the directory.
        self.log.debug("Cloning git repo")
        _run_command("git clone %s %s" % (repo, self.id_), JOBS_DIR)
        if commit is not None:
            self.log.debug("Resetting to commit: %s" % commit)
            _run_command("git reset --hard %s" % commit, repo_dir)

        # Install the prereqs.
        if self.description.get("install", True):
            envdir = os.path.join(repo_dir, "venv")
            os.mkdir(envdir)

            self.log.debug("Creating virtualenv")
            _run_command("virtualenv %s -p /usr/bin/python%s" %
                             (envdir, self.description.get("python", "2.7")))

            self.log.debug("Installing dependencies")
            run_in_venv(self.id_, "pip install -r requirements.txt")

        self.log.info("Completed deployment")
        _run_command("touch __unlocked__.py", dir=repo_dir)

        self._action("deploy")
Exemple #3
0
 def proc(self, command):
     self.output("proc %s @@ %s" % (command, MY_IP))
     console.run_in_venv(self.id_, command)
Exemple #4
0
 def wsgi(self, command):
     port = random.randrange(9000, 9999)
     host = "%s:%d" % ("0.0.0.0", port)
     self.output("wsgi %s @@ %s" % (command, host))
     console.run_in_venv(self.id_,
                         "gunicorn -w 4 -b %s %s" % (host, command))