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:
30
main.py
30
main.py
@@ -175,6 +175,9 @@ def run_session():
|
|||||||
last_changeds = set()
|
last_changeds = set()
|
||||||
states = []
|
states = []
|
||||||
changed = False
|
changed = False
|
||||||
|
changed_files = 0
|
||||||
|
total_files = len(EXCEL_LINKS)
|
||||||
|
new_files = 0
|
||||||
for excel_dict in EXCEL_LINKS:
|
for excel_dict in EXCEL_LINKS:
|
||||||
try:
|
try:
|
||||||
last_changeds.add(excel_dict['last_changed'])
|
last_changeds.add(excel_dict['last_changed'])
|
||||||
@@ -189,6 +192,22 @@ def run_session():
|
|||||||
is_new = state is None
|
is_new = state is None
|
||||||
if is_new:
|
if is_new:
|
||||||
state = {}
|
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:
|
else:
|
||||||
same_date = False
|
same_date = False
|
||||||
@@ -210,6 +229,7 @@ def run_session():
|
|||||||
body=json.dumps({
|
body=json.dumps({
|
||||||
"type": "excel_file_found",
|
"type": "excel_file_found",
|
||||||
"same": same_date,
|
"same": same_date,
|
||||||
|
"is_new": False,
|
||||||
"excel_dict": excel_dict
|
"excel_dict": excel_dict
|
||||||
}, ensure_ascii=False).encode('utf-8')
|
}, ensure_ascii=False).encode('utf-8')
|
||||||
)
|
)
|
||||||
@@ -224,6 +244,7 @@ def run_session():
|
|||||||
save_parsed_state(excel_filename, state)
|
save_parsed_state(excel_filename, state)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
changed_files += 1
|
||||||
changed = True
|
changed = True
|
||||||
excel_dict['different_in_this_session'] = True
|
excel_dict['different_in_this_session'] = True
|
||||||
state['actual_at'] = currt()
|
state['actual_at'] = currt()
|
||||||
@@ -317,14 +338,14 @@ def run_session():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error deleting directory '{DIRNAME}': {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():
|
def check_dirs():
|
||||||
|
|
||||||
if not os.path.exists(PARSED_DIR):
|
if not os.path.exists(PARSED_DIR):
|
||||||
os.mkdir(PARSED_DIR)
|
os.mkdir(PARSED_DIR)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
while True:
|
while True:
|
||||||
t = utils.StepTimeCounter()
|
t = utils.StepTimeCounter()
|
||||||
err = None
|
err = None
|
||||||
@@ -360,8 +381,9 @@ def main():
|
|||||||
}, ensure_ascii=False).encode('utf-8')
|
}, ensure_ascii=False).encode('utf-8')
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Sleep for 30 minutes")
|
sleep_time = random.randint(14*60, 21*60)
|
||||||
time.sleep(60*30)
|
print(f"Sleep for {round(sleep_time/6)/10} minutes")
|
||||||
|
time.sleep(sleep_time)
|
||||||
print("Wake up!")
|
print("Wake up!")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user