feat: random sleep & more for statcollector
All checks were successful
Build and Run VSTU Schedule Parser / build_and_run (push) Successful in 20s
All checks were successful
Build and Run VSTU Schedule Parser / build_and_run (push) Successful in 20s
This commit is contained in:
28
main.py
28
main.py
@@ -175,6 +175,9 @@ def run_session():
|
||||
last_changeds = set()
|
||||
states = []
|
||||
changed = False
|
||||
changed_files = 0
|
||||
total_files = len(EXCEL_LINKS)
|
||||
new_files = 0
|
||||
for excel_dict in EXCEL_LINKS:
|
||||
try:
|
||||
last_changeds.add(excel_dict['last_changed'])
|
||||
@@ -189,6 +192,22 @@ def run_session():
|
||||
is_new = state is None
|
||||
if is_new:
|
||||
state = {}
|
||||
channel.basic_publish(
|
||||
exchange=EXCHANGE_NAME,
|
||||
routing_key='parser.excel_found.new',
|
||||
properties=pika.BasicProperties(
|
||||
content_type="application/json",
|
||||
delivery_mode=2
|
||||
),
|
||||
body=json.dumps({
|
||||
"type": "excel_file_found",
|
||||
"same": False,
|
||||
"is_new": True,
|
||||
"excel_dict": excel_dict
|
||||
}, ensure_ascii=False).encode('utf-8')
|
||||
)
|
||||
print(f"RabbitMQ published r={r}")
|
||||
new_files += 1
|
||||
|
||||
else:
|
||||
same_date = False
|
||||
@@ -210,6 +229,7 @@ def run_session():
|
||||
body=json.dumps({
|
||||
"type": "excel_file_found",
|
||||
"same": same_date,
|
||||
"is_new": False,
|
||||
"excel_dict": excel_dict
|
||||
}, ensure_ascii=False).encode('utf-8')
|
||||
)
|
||||
@@ -224,6 +244,7 @@ def run_session():
|
||||
save_parsed_state(excel_filename, state)
|
||||
continue
|
||||
|
||||
changed_files += 1
|
||||
changed = True
|
||||
excel_dict['different_in_this_session'] = True
|
||||
state['actual_at'] = currt()
|
||||
@@ -317,7 +338,7 @@ def run_session():
|
||||
except Exception as e:
|
||||
print(f"Error deleting directory '{DIRNAME}': {e}")
|
||||
|
||||
return {"changed": changed}
|
||||
return {"changed_files": changed_files, 'total_files': total_files, "changed": changed, "new_files": new_files}
|
||||
|
||||
def check_dirs():
|
||||
|
||||
@@ -360,8 +381,9 @@ def main():
|
||||
}, ensure_ascii=False).encode('utf-8')
|
||||
)
|
||||
|
||||
print("Sleep for 30 minutes")
|
||||
time.sleep(60*30)
|
||||
sleep_time = random.randint(14*60, 21*60)
|
||||
print(f"Sleep for {round(sleep_time/6)/10} minutes")
|
||||
time.sleep(sleep_time)
|
||||
print("Wake up!")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user