def get(self, request: Request, *args, **kwargs) -> Response: """ Connect to the job broker for the account. This endpoint is for self-hosted workers. These need to be enabled for the account. You may need to include your authentication token in the URL. For example, when using [Celery](https://www.celeryproject.org/) in Python: ```python app = Celery( broker="https://{token}@hub.stenci.la/api/accounts/{account}/jobs/broker".format( token = os.environ.get("STENCILA_TOKEN"), account = os.environ.get("STENCILA_ACCOUNT") ) ) ``` """ get_account(kwargs["account"], request.user) # TODO: Check that the account has self-hosted workers enabled # TODO: Authenticate with the RabbitMQ broker and use account's virtual host url = "http://*****:*****@broker:0000/account-vhost" return Response(headers={ "X-Accel-Redirect": "@jobs-broker", "X-Accel-Redirect-URL": url })
def get_queryset(self): """ Get the queryset for the current action. If the user is a member of the account, returns all heartbeats for the worker. Otherwise, raises permission denied. """ get_account(self.kwargs["account"], self.request.user) return WorkerHeartbeat.objects.filter( worker=self.kwargs["worker"]).order_by("-time")
def get_queryset(self): """ Get the queryset for the current action. If the user is a member of the account, returns all queues for the account. Otherwise, raises permission denied. """ account = get_account(self.kwargs["account"], self.request.user) return Queue.objects.filter(zone__account=account)
def get_queryset(self, roles: Optional[List[AccountRole]] = None): """ Get the queryset for the current action. If the user is a member of the account, returns all zones for the account. Otherwise, raises permission denied. """ account = get_account(self.kwargs["account"], self.request.user, roles) return Zone.objects.filter(account=account)
def get_queryset(self): """ Get the queryset for the current action. If the user is a member of the account, returns all worker for the account (via queues and zones). Otherwise, raises permission denied. """ account = get_account(self.kwargs["account"], self.request.user) queryset = Worker.objects.filter( queues__zone__account=account).distinct() active = self.request.GET.get("active", None) if active == "true": queryset = queryset.filter(finished__isnull=True) elif active == "false": queryset = queryset.filter(finished__isnull=False) return queryset