(20251122) Reverted formatting and added a semaphore.
This commit is contained in:
@@ -75,6 +75,7 @@ from cosec_web.cosec_web import CosecWeb
|
||||
from backend.shared import constants
|
||||
|
||||
# To work with dat and time:
|
||||
import time
|
||||
import datetime
|
||||
|
||||
# For asynchronous activities:
|
||||
@@ -174,6 +175,14 @@ async def in_out_report_generate(
|
||||
# Show all the paths for debugging:
|
||||
current_app.printer("PATHS:", chrome_driver_dir, user_data_dir, downloads_dir)
|
||||
|
||||
# Wait for the semaphore so that only one instance is automating Chrome at a time:
|
||||
async with current_app.chrome_semaphore:
|
||||
|
||||
# First kill the previous processes:
|
||||
kill_count = CosecWeb.kill_chrome_processes()
|
||||
current_app.printer("Killed Chrome Procs.", kill_count)
|
||||
if kill_count > 0: time.sleep(2.5)
|
||||
|
||||
# Create an instance of the automation object:
|
||||
cosec = CosecWeb(
|
||||
cosec_url = inbound_headers.cosecUrl,
|
||||
|
||||
@@ -176,6 +176,7 @@ async def muster_roll_report_generate(
|
||||
report_data = None
|
||||
|
||||
# Get the muster roll data:
|
||||
async with current_app.chrome_semaphore:
|
||||
report_data = muster_roll.load(
|
||||
cosec_url = inbound_headers.cosecUrl,
|
||||
username = inbound_headers.cosecUsername,
|
||||
@@ -186,21 +187,22 @@ async def muster_roll_report_generate(
|
||||
|
||||
# If data was loaded:
|
||||
if report_data is not None:
|
||||
report_data = report_data.copy()
|
||||
report_data = report_data[[
|
||||
"User ID", "User Name", "Category Name",
|
||||
"Grade Name", "Branch Name", "Department Name",
|
||||
"Direct Reporting", "Level-1"
|
||||
]]
|
||||
unique_branches = report_data["Branch Name"].unique().tolist()
|
||||
unique_depts = report_data[["Branch Name", "Department Name"]].drop_duplicates().to_dict(orient = "records")
|
||||
unique_reportees = report_data[["Branch Name", "Department Name", "Direct Reporting"]].drop_duplicates().to_dict(orient = "records")
|
||||
unique_combos = {
|
||||
"Branch Name": unique_branches,
|
||||
"Department Name": unique_depts,
|
||||
"Direct Reporting": unique_reportees
|
||||
}
|
||||
report_data = unique_combos
|
||||
# report_data = report_data.copy()
|
||||
# report_data = report_data[[
|
||||
# "User ID", "User Name", "Category Name",
|
||||
# "Grade Name", "Branch Name", "Department Name",
|
||||
# "Direct Reporting", "Level-1"
|
||||
# ]]
|
||||
# unique_branches = report_data["Branch Name"].unique().tolist()
|
||||
# unique_depts = report_data[["Branch Name", "Department Name"]].drop_duplicates().to_dict(orient = "records")
|
||||
# unique_reportees = report_data[["Branch Name", "Department Name", "Direct Reporting"]].drop_duplicates().to_dict(orient = "records")
|
||||
# unique_combos = {
|
||||
# "Branch Name": unique_branches,
|
||||
# "Department Name": unique_depts,
|
||||
# "Direct Reporting": unique_reportees
|
||||
# }
|
||||
# report_data = unique_combos
|
||||
report_data = report_data.to_dict(orient = "records")
|
||||
success = True
|
||||
|
||||
# ┳┓
|
||||
|
||||
@@ -38,6 +38,9 @@ sys.path.append("..")
|
||||
|
||||
# System-level:
|
||||
import os
|
||||
|
||||
# To work with date and time:
|
||||
import time
|
||||
import datetime
|
||||
|
||||
# For using Quart:
|
||||
@@ -123,6 +126,11 @@ def load_from_cosec(
|
||||
downloads_dir = os.path.join(base_dir, r"downloads")
|
||||
masters_dir = os.path.join(base_dir, r"masters")
|
||||
|
||||
# First kill the previous processes:
|
||||
kill_count = CosecWeb.kill_chrome_processes()
|
||||
current_app.printer("Killed Chrome Procs.", kill_count)
|
||||
if kill_count > 0: time.sleep(2.5)
|
||||
|
||||
# Create an instance of the automation object:
|
||||
current_app.cosec = CosecWeb(
|
||||
cosec_url = cosec_url,
|
||||
|
||||
+7
-14
@@ -59,6 +59,9 @@ from backend.shared import constants
|
||||
# To make REST API calls:
|
||||
import httpx
|
||||
|
||||
# For asynchronous activities:
|
||||
import asyncio
|
||||
|
||||
# For debugging:
|
||||
from icecream import IceCreamDebugger
|
||||
|
||||
@@ -211,21 +214,11 @@ async def app_startup(**kwargs):
|
||||
# ┃┃┃┓┏┏
|
||||
# ┛ ┗┗┛┗
|
||||
|
||||
# cosec_creds = files.read_file(
|
||||
# file_path = os.path.join(
|
||||
# files.get_parent_directory(
|
||||
# path = files.get_file_directory(include_filename = False),
|
||||
# depth = 2
|
||||
# ),
|
||||
# "creds",
|
||||
# "cosec",
|
||||
# "cosec_velankani.json"
|
||||
# )
|
||||
# )
|
||||
# Semaphores:
|
||||
current_app.chrome_semaphore = asyncio.Semaphore(1)
|
||||
|
||||
# Helpers:
|
||||
muster_roll.init()
|
||||
# muster_roll.load(
|
||||
#
|
||||
# )
|
||||
|
||||
# ┏┓┓
|
||||
# ┃ ┃┏┓┏┓┏┓┓┏┏┓
|
||||
|
||||
Reference in New Issue
Block a user