Exemple #1
0
 def update_job(self, job):
     update = self.jobs_t.update().values(**{
         'next_run_time': datetime_to_utc_timestamp(job.next_run_time),
         'job_state': dill.dumps(job.__getstate__(), self.pickle_protocol)
     }).where(self.jobs_t.c.id == job.id)
     result = self.engine.execute()
     if result.rowcount == 0:
         raise JobLookupError(id)
Exemple #2
0
 def update_job(self, job):
     update = self.jobs_t.update().values(**{
         'next_run_time': datetime_to_utc_timestamp(job.next_run_time),
         'job_state': dill.dumps(job.__getstate__(), self.pickle_protocol)
     }).where(self.jobs_t.c.id == job.id)
     result = self.engine.execute()
     if result.rowcount == 0:
         raise JobLookupError(id)
Exemple #3
0
 def add_job(self, job):
     insert = self.jobs_t.insert().values(**{
         'id': job.id,
         'next_run_time': datetime_to_utc_timestamp(job.next_run_time),
         'job_state': dill.dumps(job.__getstate__(), self.pickle_protocol)
     })
     try:
         self.engine.execute()
     except IntegrityError:
         raise ConflictingIdError(job.id)
Exemple #4
0
 def add_job(self, job):
     insert = self.jobs_t.insert().values(**{
         'id': job.id,
         'next_run_time': datetime_to_utc_timestamp(job.next_run_time),
         'job_state': dill.dumps(job.__getstate__(), self.pickle_protocol)
     })
     try:
         self.engine.execute()
     except IntegrityError:
         raise ConflictingIdError(job.id)
Exemple #5
0
    def build(self) -> str:
        """
        Builds the commands.
        :return: build comamnds.
        """
        if self.container is None and self.image is None:
            raise ValueError(
                "Must define either the Docker image or container to run commands in"
            )
        if self.container is not None and self.image is not None:
            raise ValueError(
                "Cannot build Docker command to work in for both an image and a running container"
            )

        mounts = ""
        for local_volume, container_volumes in self.mounts.items():
            if not isinstance(container_volumes, set):
                container_volumes = {container_volumes}
            for container_volume in container_volumes:
                mounts += "-v %s:%s " % (local_volume, container_volume)

        ports = ""
        for local_port, container_port in self.ports.items():
            ports += "-p %d:%d" % (local_port, container_port)

        variables = ""
        for variable in self.variables:
            variables += "-e %s " % variable

        executable_arguments = " ".join(
            self.executable_arguments
        ) if self.executable_arguments is not None else CLI_ARGUMENTS

        if self.get_path_arguments_to_mount is not None:
            serialised_arguments_parser = base64.b64encode(
                dill.dumps(self.get_path_arguments_to_mount)).decode("utf-8")

            calculate_additional_mounts = (
                """
                $("%(python_interpreter)s" "%(python_arguments_script)s" "%(serialised_arguments_parser)s" %(cli_arguments)s)
            """ % {
                    "python_interpreter": sys.executable,
                    "python_arguments_script": _ARGUMENTS_TO_MOUNT_SCRIPT,
                    "serialised_arguments_parser": serialised_arguments_parser,
                    "cli_arguments": executable_arguments
                }).strip()
        else:
            calculate_additional_mounts = ""

        return """
            docker %(docker_noun)s -i \\
                %(name)s \\
                %(detached)s \\
                %(mounts)s %(calculate_additional_mounts)s \\
                %(ports)s \\
                %(variables)s \\
                %(other_docker)s \\
                %(image_or_container)s \\
                %(executable)s %(executable_arguments)s
        """ % {
            "calculate_additional_mounts": calculate_additional_mounts,
            "name": "--name %s" % self.name if self.name is not None else "",
            "detached": "-d" if self.detached else "",
            "mounts": mounts,
            "ports": ports,
            "variables": variables,
            "other_docker": self.other_docker,
            "docker_noun": "run" if self.image is not None else "exec",
            "image_or_container":
            self.image if self.image is not None else self.container,
            "executable": self.executable,
            "executable_arguments": executable_arguments
        }