diff --git a/burundi_compliance/burundi_compliance/api_classes/cancel_invoice.py b/burundi_compliance/burundi_compliance/api_classes/cancel_invoice.py index 862cb0d..8a7d651 100644 --- a/burundi_compliance/burundi_compliance/api_classes/cancel_invoice.py +++ b/burundi_compliance/burundi_compliance/api_classes/cancel_invoice.py @@ -1,68 +1,3 @@ -# import requests -# from ..doctype.custom_exceptions import AuthenticationError, InvoiceCancellationError -# import frappe -# from .base import OBRAPIBase -# from requests.exceptions import RequestException -# import time as time -# from frappe.integrations.utils import make_post_request, make_get_request, create_request_log - -# class InvoiceCanceller: - -# MAX_RETRIES = 1000 -# RETRY_DELAY_SECONDS = 10 - -# def __init__(self, token): -# obr_base = OBRAPIBase() -# self.BASE_CANCEL_INVOICE_API_URL = obr_base.get_api_from_ebims_settings("cancel_invoice") -# self.token = token - -# def _retry_request(self, data, retries): -# try: -# response = requests.post(self.BASE_CANCEL_INVOICE_API_URL, json=data, headers=self._get_headers()) -# response.raise_for_status() - -# '''Validate the response structure''' -# if not response.json().get("success"): -# raise InvoiceCancellationError(f"Unexpected API response format: {response.text}") - -# return response.json() -# except requests.exceptions.RequestException as e: -# error_message = f"Error during API request: {str(e)}" -# frappe.log_error(error_message, "InvoiceCanceller Request Error") -# frappe.log_error(f"Response content: {response.text}") - -# '''Resend the cancel invoice request to OBR''' -# if retries > 0: -# frappe.logger().warning(f"Retrying cancel invoice in {self.RETRY_DELAY_SECONDS} seconds... ({self.MAX_RETRIES - retries + 1}/{self.MAX_RETRIES})") -# time.sleep(self.RETRY_DELAY_SECONDS) -# return self._retry_request(data, retries - 1) -# else: -# raise AuthenticationError(f"Max retries reached. {error_message}") - -# def _send_request(self, data): -# try: -# return self._retry_request(data, self.MAX_RETRIES) -# except RequestException as e: -# frappe.log_error(f"Error during API request: {str(e)}", title="InvoiceCanceller Request Error") -# raise AuthenticationError(f"Error during API request: {str(e)}") - -# def _handle_response(self, response): -# if response.get("success"): -# return response["msg"] -# else: -# raise InvoiceCancellationError(response["msg"]) - -# def _get_headers(self): -# return { -# "Content-Type": "application/json", -# "Authorization": f"Bearer {self.token}" -# } - -# def cancel_invoice(self, data): -# cancel_invoice_data = data -# response = self._send_request(cancel_invoice_data) -# return self._handle_response(response) - import requests import json import frappe diff --git a/burundi_compliance/burundi_compliance/utils/background_jobs.py b/burundi_compliance/burundi_compliance/utils/background_jobs.py index 62ac05a..dcb3249 100644 --- a/burundi_compliance/burundi_compliance/utils/background_jobs.py +++ b/burundi_compliance/burundi_compliance/utils/background_jobs.py @@ -57,8 +57,8 @@ def enqueue_retry_posting_sales_invoice(invoice_data, doc_name): invoice_data=invoice_data, doc=doc_name, - queue="long", - timeout=300, + queue="short", + timeout=30, is_async=True, at_front=False, ) diff --git a/burundi_compliance/burundi_compliance/utils/schedular.py b/burundi_compliance/burundi_compliance/utils/schedular.py index dfc9c0a..e36fce5 100644 --- a/burundi_compliance/burundi_compliance/utils/schedular.py +++ b/burundi_compliance/burundi_compliance/utils/schedular.py @@ -21,7 +21,6 @@ def check_and_send_pending_stock_ledger_entry(): check_item = frappe.get_doc("Item", stock_ledger_entry_doc.item_code) if check_item.custom_allow_obr_to_track_stock_movement == 0: continue - # frappe.publish_realtime("msgpring",f'{stock_ledger_entry_doc}', user=frappe.session.user) send_data(stock_ledger_entry_doc) frappe.db.set_value("Stock Ledger Entry", stock_ledger_entry_doc.name, 'custom_queued', 1) time.sleep(2) diff --git a/burundi_compliance/hooks.py b/burundi_compliance/hooks.py index 8dba622..8181fac 100644 --- a/burundi_compliance/hooks.py +++ b/burundi_compliance/hooks.py @@ -192,7 +192,7 @@ scheduler_events = { "cron":{ - "0 * * * *":["burundi_compliance.burundi_compliance.utils.schedular.check_and_send_pending_sales_invoices"], + "*/5 * * * *":["burundi_compliance.burundi_compliance.utils.schedular.check_and_send_pending_sales_invoices"], "* * * * *":["burundi_compliance.burundi_compliance.utils.schedular.check_and_send_pending_stock_ledger_entry"], },