def sync_status(self, request: Request, slug: str) -> Response: """Get source's sync status""" source = self.get_object() task = TaskInfo.by_name(f"ldap_sync_{slugify(source.name)}") if not task: raise Http404 return Response(TaskSerializer(task, many=False).data)
def sync_status(self, request: Request, slug: str) -> Response: """Get source's sync status""" source = self.get_object() results = [] for sync_class in [ UserLDAPSynchronizer, GroupLDAPSynchronizer, MembershipLDAPSynchronizer, ]: sync_name = sync_class.__name__.replace("LDAPSynchronizer", "").lower() task = TaskInfo.by_name(f"ldap_sync_{source.slug}_{sync_name}") if task: results.append(task) return Response(TaskSerializer(results, many=True).data)
def retry(self, request: Request, pk=None) -> Response: """Retry task""" task = TaskInfo.by_name(pk) if not task: raise Http404 try: task_module = import_module(task.task_call_module) task_func = getattr(task_module, task.task_call_func) task_func.delay(*task.task_call_args, **task.task_call_kwargs) messages.success( self.request, _("Successfully re-scheduled Task %(name)s!" % {"name": task.task_name}), ) return Response(status=204) except (ImportError, AttributeError): # pragma: no cover # if we get an import error, the module path has probably changed task.delete() return Response(status=500)
def retrieve(self, request: Request, pk=None) -> Response: """Get a single system task""" task = TaskInfo.by_name(pk) if not task: raise Http404 return Response(TaskSerializer(task, many=False).data)