Browse Source

Rate limit custom method

master
venkataakhil 2 years ago
parent
commit
bb0654201a
  1. 14
      smart_service/apis/master_api.py

14
smart_service/apis/master_api.py

@ -1,7 +1,7 @@
# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors # Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
# For license information, please see license.txt # For license information, please see license.txt
from frappe.rate_limiter import rate_limit # from frappe.rate_limiter import rate_limit
import frappe import frappe
from frappe.model.document import Document from frappe.model.document import Document
@ -12,11 +12,11 @@ from smart_service.apis.app_user_login import input_validation
current_db_name = frappe.conf.get("db_name") current_db_name = frappe.conf.get("db_name")
@frappe.whitelist(allow_guest=1) @frappe.whitelist(allow_guest=True)
def masters1(): def masters1():
val = rate_limit(limit=5, seconds=10) rate_res = rate_limit(limit=5, seconds=10)
if val != 1: if rate_res != 1:
return val return rate_res
return 1 return 1
@ -40,6 +40,10 @@ def rate_limit(limit, seconds):
@frappe.whitelist() @frappe.whitelist()
def masters(args=None, LSD=None): def masters(args=None, LSD=None):
rate = rate_limit(limit=5, seconds=5)
if rate != 1:
return rate
val = input_validation(args=args) val = input_validation(args=args)
if val != '': if val != '':
return {"status": 0, "error": "Parameter's missing:"+val} return {"status": 0, "error": "Parameter's missing:"+val}

Loading…
Cancel
Save