Example #1
0
        def on_commit_callback():
            if self.__initial_slug and self.slug != self.__initial_slug:
                # Rename any previously existing repo directory to the new slug.
                # TODO: In a distributed Nautobot deployment, each Django instance and/or RQ worker instance may
                # have its own clone of this repository on its own local filesystem; we need some way to ensure
                # that all such clones are renamed.
                # For now we just rename the one that we have locally and rely on other methods
                # (notably get_jobs()) to clean up other clones as they're encountered.
                if os.path.exists(os.path.join(settings.GIT_ROOT, self.__initial_slug)):
                    os.rename(
                        os.path.join(settings.GIT_ROOT, self.__initial_slug),
                        self.filesystem_path,
                    )

            if trigger_resync:
                assert self.request is not None, "No HTTP request associated with this update!"
                from nautobot.extras.datasources import (
                    enqueue_pull_git_repository_and_refresh_data,
                )

                enqueue_pull_git_repository_and_refresh_data(self, self.request)

            # Update cached values
            self.__initial_token = self._token
            self.__initial_slug = self.slug
Example #2
0
    def sync(self, request, pk):
        """
        Enqueue pull git repository and refresh data.
        """
        if not request.user.has_perm("extras.change_gitrepository"):
            raise PermissionDenied("This user does not have permission to make changes to Git repositories.")

        if not get_worker_count():
            raise CeleryWorkerNotRunningException()

        repository = get_object_or_404(GitRepository, id=pk)
        enqueue_pull_git_repository_and_refresh_data(repository, request)
        return Response({"message": f"Repository {repository} sync job added to queue."})