diff options
author | Hui Lan <lanhui@zjnu.edu.cn> | 2025-08-19 14:25:07 +0800 |
---|---|---|
committer | Hui Lan <lanhui@zjnu.edu.cn> | 2025-08-19 14:25:07 +0800 |
commit | 9a4a23c89cdba6a8eebe4ee13cd55e6d3aed5b81 (patch) | |
tree | ceb8cd2bf76d60ecba3e8ccc4726ac46565ec361 | |
parent | 9ff8b3390fb5175cf00cbdfac3f4055dbc6f4e30 (diff) |
Running the publisher as a seperate script seems solved the problem of not being able to receive messages.
-rw-r--r-- | Code/download_and_map.py | 20 | ||||
-rw-r--r-- | Code/publish_mapped_data.py (renamed from Code/test_redis_publish2.py) | 15 | ||||
-rw-r--r-- | Code/test_redis_publish.py | 4 |
3 files changed, 25 insertions, 14 deletions
diff --git a/Code/download_and_map.py b/Code/download_and_map.py index 0e8f160..2a0a157 100644 --- a/Code/download_and_map.py +++ b/Code/download_and_map.py @@ -392,6 +392,7 @@ def publish(mapped_data_directory): redis_password = os.getenv('REDIS_PASSWORD', '123456') r = redis.Redis(host=redis_host, port=6379, password=redis_password, db=0) r.publish(REDIS_CHANNEL, json.dumps({'filename':'REDIS_START.txt', 'data':str(datetime.now())})) + time.sleep(3) for fname in glob.glob('%s/*_quant.txt' % (mapped_data_directory.rstrip('/'))): try: file_basename = os.path.basename(fname) @@ -400,7 +401,7 @@ def publish(mapped_data_directory): r.publish(REDIS_CHANNEL, json.dumps({'filename':file_basename, 'data':data})) except Exception as e: r.publish(REDIS_CHANNEL, json.dumps({'filename':'REDIS_ERROR.txt', 'data':str(e)})) - time.sleep(1) + time.sleep(3) ## main @@ -421,6 +422,8 @@ if not last_session_finished(DOWNLOADED_SRA_ID_LOG_FILE): # last session not fin write_network_log_file(s, UPDATE_NETWORK_LOG_FILE) if age_of_file_in_hours(DOWNLOADED_SRA_ID_LOG_FILE) > 24: # add DONE to the log file anyway append_done(DOWNLOADED_SRA_ID_LOG_FILE) + download_log_file(DOWNLOADED_SRA_ID_LOG_FILE, 'DONE at %s\n' % (curr_time)) + reverse_lines(DOWNLOADED_SRA_ID_LOG_FILE, os.path.splitext(DOWNLOADED_SRA_ID_LOG_FILE)[0] + '_reversed.txt') kill_process('wget') sys.exit() @@ -450,14 +453,21 @@ if not os.path.isdir(MAPPED_RDATA_DIR): # after mapping is finished, move all resulting files to MAPPED_RDATA_DIR if glob.glob('%s/*_quant.txt' % (SALMON_MAP_RESULT_DIR.rstrip('/'))) != []: - publish(SALMON_MAP_RESULT_DIR) - cmd = 'mv %s/*_quant.txt %s' % (SALMON_MAP_RESULT_DIR.rstrip('/'), MAPPED_RDATA_DIR) + + try: + write_log_file('[download_and_map.py] Ready to publish quant files.', UPDATE_NETWORK_LOG_FILE) + publish(SALMON_MAP_RESULT_DIR) + time.sleep(5) + except Exception as e: + write_log_file('[download_and_map.py] Publish error %s.' % (str(e)), UPDATE_NETWORK_LOG_FILE) + + cmd = 'cp %s/*_quant.txt %s' % (SALMON_MAP_RESULT_DIR.rstrip('/'), MAPPED_RDATA_DIR) os.system(cmd) print('[download_and_map.py] Done. Check directory %s.' % (os.path.abspath(MAPPED_RDATA_DIR))) else: print('[download_and_map.py] No quant files to move.') - + write_log_file('[download_and_map.py] No quant files to move.', UPDATE_NETWORK_LOG_FILE) write_download_log_file(DOWNLOADED_SRA_ID_LOG_FILE, '%s\n' % ('\n'.join(map_list))) -write_download_log_file(DOWNLOADED_SRA_ID_LOG_FILE, 'DONE at %s\n' % (curr_time)) +download_log_file(DOWNLOADED_SRA_ID_LOG_FILE, 'DONE at %s\n' % (curr_time)) reverse_lines(DOWNLOADED_SRA_ID_LOG_FILE, os.path.splitext(DOWNLOADED_SRA_ID_LOG_FILE)[0] + '_reversed.txt') diff --git a/Code/test_redis_publish2.py b/Code/publish_mapped_data.py index eeda27d..2bd655c 100644 --- a/Code/test_redis_publish2.py +++ b/Code/publish_mapped_data.py @@ -2,14 +2,13 @@ import redis from configure import DAILY_MAP_NUMBER, MIN_FASTQ_FILE_SIZE, RNA_SEQ_INFO_FILE, DOWNLOADED_SRA_ID_LOG_FILE, IGNORED_SRA_ID_LOG_FILE, UPDATE_NETWORK_LOG_FILE, MAPPED_RDATA_DIR, RAW_RDATA_DIR, SALMON_MAP_RESULT_DIR, REDIS_CHANNEL import json, glob, os, time from datetime import datetime -def publish(mapped_data_directory): +def publish(mapped_files): redis_host = os.getenv('REDIS_HOST', '127.0.0.1') - #redis_host = os.getenv('REDIS_HOST', '0.0.0.0') redis_password = os.getenv('REDIS_PASSWORD', '123456') print(redis_password) r = redis.Redis(host=redis_host, port=6379, password=redis_password, db=0) r.publish(REDIS_CHANNEL, json.dumps({'filename':'REDIS_START.txt', 'data':str(datetime.now())})) - for fname in glob.glob('%s/*_quant.txt' % (mapped_data_directory.rstrip('/'))): + for fname in mapped_files: print(fname) try: file_basename = os.path.basename(fname) @@ -23,10 +22,12 @@ def publish(mapped_data_directory): # after mapping is finished, move all resulting files to MAPPED_RDATA_DIR -if glob.glob('%s/*_quant.txt' % (SALMON_MAP_RESULT_DIR.rstrip('/'))) != []: - publish(SALMON_MAP_RESULT_DIR) - #cmd = 'mv %s/*_quant.txt %s' % (SALMON_MAP_RESULT_DIR.rstrip('/'), MAPPED_RDATA_DIR) - #os.system(cmd) +mapped_files = glob.glob('%s/*_quant.txt' % (SALMON_MAP_RESULT_DIR.rstrip('/'))) +print(mapped_files) +publish(mapped_files) +if mapped_files != []: + cmd = 'mv %s/*_quant.txt %s' % (SALMON_MAP_RESULT_DIR.rstrip('/'), MAPPED_RDATA_DIR) + os.system(cmd) print('[download_and_map.py] Done. Check directory %s.' % (os.path.abspath(MAPPED_RDATA_DIR))) else: print('[download_and_map.py] No quant files to move.') diff --git a/Code/test_redis_publish.py b/Code/test_redis_publish.py index 937833f..722e80e 100644 --- a/Code/test_redis_publish.py +++ b/Code/test_redis_publish.py @@ -8,7 +8,7 @@ def publish(number): r.publish(REDIS_CHANNEL, json.dumps({'filename':'a.txt', 'data':str(number)})) n = 0 -while True: +while n < 10: publish(n) - time.sleep(3) + time.sleep(2) n += 1 |