(20260317) Tried headless and parallel mode.
This commit is contained in:
+40
-22
@@ -112,7 +112,7 @@ err_printer = IceCreamDebugger(prefix = "[ERR] Cron | ", includeContext = True)
|
||||
# ***** ****
|
||||
# *** FUNCTIONS ***
|
||||
# ***** ****
|
||||
# *****************************************************************************************************************
|
||||
# *****************************************************************************************************************-
|
||||
|
||||
|
||||
async def yesterday_cron(
|
||||
@@ -139,7 +139,7 @@ async def yesterday_cron(
|
||||
cosec_creds = cosec_creds,
|
||||
from_dt = date_time.get_current_ist_date_time() - datetime.timedelta(days = 3),
|
||||
to_dt = date_time.get_current_ist_date_time(),
|
||||
cache_file = common.PREV_DAY_IN_OUT_SUMMARY_CACHE_FILE,
|
||||
cache_file = common.get_prev_day_in_out_summary_cache_file_path,
|
||||
test_mode = test_mode
|
||||
)
|
||||
|
||||
@@ -148,7 +148,7 @@ async def yesterday_cron(
|
||||
printer("IN/OUT SUMMARY: Sync'ing with TCAOFF")
|
||||
await common.sync_attendance_to_tcaoff(
|
||||
tcaoff_client = tcaoff_client,
|
||||
cosec_in_out_summary = json.from_file(common.PREV_DAY_IN_OUT_SUMMARY_CACHE_FILE),
|
||||
cosec_in_out_summary = json.from_file(common.get_prev_day_in_out_summary_cache_file_path()),
|
||||
chunk_size = 10
|
||||
)
|
||||
|
||||
@@ -198,7 +198,7 @@ async def today_cron(
|
||||
try:
|
||||
|
||||
# MUSTER-ROLL:
|
||||
|
||||
# -----------
|
||||
# Get the Muster Roll and then wait
|
||||
# for the driver's resources to get freed:
|
||||
success = common.get_muster_roll(
|
||||
@@ -208,14 +208,14 @@ async def today_cron(
|
||||
minute = 0,
|
||||
second = 0
|
||||
),
|
||||
cache_file = common.MUSTER_ROLL_CACHE_FILE,
|
||||
cache_file = common.get_muster_roll_cache_file_path,
|
||||
test_mode = test_mode
|
||||
)
|
||||
|
||||
# Sync data between Cosec and TCAOFF:
|
||||
if success:
|
||||
print("MUSTER ROLL: Sync'ing with TCAOFF")
|
||||
cosec_muster_roll = json.from_file(common.MUSTER_ROLL_CACHE_FILE)
|
||||
cosec_muster_roll = json.from_file(common.get_muster_roll_cache_file_path())
|
||||
await common.sync_branches_to_tcaoff(
|
||||
tcaoff_client = tcaoff_client,
|
||||
cosec_muster_roll = cosec_muster_roll,
|
||||
@@ -230,14 +230,14 @@ async def today_cron(
|
||||
)
|
||||
|
||||
# IN-OUT SUMMARY:
|
||||
|
||||
# --------------
|
||||
# Get the previous day's In/Out Summary and then wait
|
||||
# for the driver's resources to get freed:
|
||||
success = common.get_in_out_summary(
|
||||
cosec_creds = cosec_creds,
|
||||
from_dt = date_time.get_current_ist_date_time().replace(hour = 0, minute = 0, second = 0, microsecond = 0),
|
||||
to_dt = date_time.get_current_ist_date_time(),
|
||||
cache_file = common.IN_OUT_SUMMARY_CACHE_FILE,
|
||||
cache_file = common.get_in_out_summary_cache_file_path,
|
||||
test_mode = test_mode
|
||||
)
|
||||
|
||||
@@ -246,7 +246,7 @@ async def today_cron(
|
||||
printer("IN/OUT SUMMARY: Sync'ing with TCAOFF")
|
||||
await common.sync_attendance_to_tcaoff(
|
||||
tcaoff_client = tcaoff_client,
|
||||
cosec_in_out_summary = json.from_file(common.IN_OUT_SUMMARY_CACHE_FILE),
|
||||
cosec_in_out_summary = json.from_file(common.get_in_out_summary_cache_file_path()),
|
||||
chunk_size = 10
|
||||
)
|
||||
|
||||
@@ -354,18 +354,20 @@ if __name__ == "__main__":
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument(
|
||||
"--test", "--test-mode",
|
||||
help = "Picks the last cache file instead of fetching records from COSEC.",
|
||||
action = "store_true",
|
||||
default = False,
|
||||
)
|
||||
ap.add_argument(
|
||||
"--immediate",
|
||||
help = "To do one run immediately first, then set the scheduler.",
|
||||
action = "store_true",
|
||||
default = False,
|
||||
default = False
|
||||
)
|
||||
ap.add_argument(
|
||||
"--verbose",
|
||||
action = "store_true",
|
||||
default = False,
|
||||
default = False
|
||||
)
|
||||
ap.add_argument(
|
||||
"--cosec-creds",
|
||||
@@ -377,16 +379,30 @@ if __name__ == "__main__":
|
||||
help = "The credentials JSON from which you would like to connect to TheCAOffice.",
|
||||
default = "tcaoff.json"
|
||||
)
|
||||
ap.add_argument(
|
||||
"--org", "--organization",
|
||||
help = "When handling multiple organizations, this word will be used to keep their files separate.",
|
||||
default = "default"
|
||||
)
|
||||
args = ap.parse_args()
|
||||
|
||||
# Hold temporary environment variables:
|
||||
os.environ["ORG"] = args.org
|
||||
|
||||
# Read required credentials:
|
||||
cosec_creds_path = os.path.join(common.CREDS_DIR, args.cosec_creds)
|
||||
tcaoff_creds_path = os.path.join(common.CREDS_DIR, args.tcaoff_creds)
|
||||
# ---
|
||||
cosec_creds = json.from_file(cosec_creds_path)
|
||||
tcaoff_creds = json.from_file(tcaoff_creds_path)
|
||||
|
||||
# Explicitly mention the expected file paths for other devs to maintain:
|
||||
print("PROJ. DIR. :", common.PROJ_DIR)
|
||||
print("COSEC CREDS :", common.COSEC_CREDS_FILE)
|
||||
print("TCAOFF CREDS:", common.TCAOFF_CREDS_FILE)
|
||||
print("COSEC CREDS :", cosec_creds_path)
|
||||
print("TCAOFF CREDS:", tcaoff_creds_path)
|
||||
|
||||
# Read required credentials:
|
||||
cosec_creds = json.from_file(os.path.join(common.CREDS_DIR, args.cosec_creds))
|
||||
tcaoff_creds = json.from_file(os.path.join(common.CREDS_DIR, args.tcaoff_creds))
|
||||
# Ensure that certain required paths exist:
|
||||
common.init_paths()
|
||||
|
||||
# Create the clients:
|
||||
tcaoff_client = AsyncTheCAOffice(
|
||||
@@ -397,9 +413,11 @@ if __name__ == "__main__":
|
||||
)
|
||||
|
||||
# Schedule the activities:
|
||||
asyncio.run(set_scheduler(
|
||||
cosec_creds = cosec_creds,
|
||||
tcaoff_client = tcaoff_client,
|
||||
immediate = args.immediate,
|
||||
test_mode = args.test
|
||||
))
|
||||
asyncio.run(
|
||||
set_scheduler(
|
||||
cosec_creds = cosec_creds,
|
||||
tcaoff_client = tcaoff_client,
|
||||
immediate = args.immediate,
|
||||
test_mode = args.test
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user