def run(): username = input("input delete username: ") try: GithubUser.objects.get(username=username) github_information_service = GithubInformationService(username=username) github_information_service.update() except GithubUser.DoesNotExist: pass
def run(): """ 30분마다 실행되는 Github user 업데이트 : github api가 rate_limit 걸려서 더이상 호출하지 못하는 경우 """ start_time = timeit.default_timer() # 시작 시간 체크 update_user_queue_qs = UpdateUserQueue.objects.filter( status__in=[UpdateUserQueue.READY, UpdateUserQueue.FAIL]) if not update_user_queue_qs: return try: # 스크립트를 시작하기전 rate_limit 를 체크한다. rate_limit_check_service = GithubInformationService( is_insert_queue=False) rate_limit_check_service.get_rate_remaining() except RateLimit: return SlackService.slack_update_github_user(status='시작', message='') update_user_count = 0 for user_queue in chunkator(update_user_queue_qs, 1000): try: github_information_service = GithubInformationService( user_queue.username, False) github_information_service.update() user_queue.status = UpdateUserQueue.SUCCESS user_queue.save(update_fields=['status']) update_user_count += 1 except RateLimit: # rate limit 면 다른 유저들도 업데이드 못함 SlackService.slack_notify_update_fail( message=f'Rate Limit 로 인해 업데이트가 실패되었습니다. ' f'{update_user_count}명만 업데이트 되었습니다.😭') break except Exception as e: capture_exception(e) terminate_time = timeit.default_timer() # 종료 시간 체크 SlackService.slack_update_github_user( status='완료', message=f'업데이트가 {terminate_time - start_time:.2f}초 걸렸습니다.', update_user=update_user_count)
def retrieve(self, request, *args, **kwargs): self.serializer_class = GithubUserSerializer username = self.kwargs.get(self.lookup_url_kwarg) github_user = self.get_queryset().filter(username=username).first() if not github_user: try: github_information_service = GithubInformationService(username) github_user = github_information_service.update() except GitHubUserDoesNotExist: raise NotExistsGithubUser() except RateLimit: raise RateLimitGithubAPI() serializer = self.serializer_class(github_user) return Response(serializer.data)
def update(self, request, *args, **kwargs): self.serializer_class = GithubUserSerializer username = self.kwargs.get(self.lookup_url_kwarg) try: github_user = GithubUser.objects.filter(username=username).get() if self.can_update(updated_date=github_user.updated) is False: response_data = self.serializer_class(github_user).data return Response(response_data) github_information_service = GithubInformationService(username) user = github_information_service.update() response_data = self.serializer_class(user).data except GithubUser.DoesNotExist: raise exceptions.NotFound except RateLimit: raise RateLimitGithubAPI() return Response(response_data)