psr-factory 5.0.0b16__py3-none-win_amd64.whl → 5.0.0b67__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
psr/execqueue/watcher.py CHANGED
@@ -12,7 +12,7 @@ SERVER_URL = os.getenv("SERVER_URL", "http://127.0.0.1:5000")
12
12
  WATCH_DIR = os.getenv("WATCH_DIR")
13
13
  PROCESSED_DIR = os.getenv("PROCESSED_DIR")
14
14
  RESULTS_DIR = os.getenv("RESULTS_DIR", "results")
15
- SLEEP_SECONDS = int(os.getenv("WATCHER_SLEEP", "30"))
15
+ SLEEP_SECONDS = int(os.getenv("WATCHER_SLEEP", "10"))
16
16
  DB_PATH = os.getenv("WATCHER_DB_PATH", "watcher.sqlite")
17
17
 
18
18
 
@@ -42,11 +42,28 @@ def _log_to_db(filename, cloud_upload_id):
42
42
  conn.commit()
43
43
  conn.close()
44
44
 
45
-
45
+ def _is_file_locked(filepath):
46
+ """Returns True if the file is locked by another process (e.g., still being copied)."""
47
+ if not os.path.exists(filepath):
48
+ return True
49
+ try:
50
+ # Try to open for exclusive writing
51
+ with open(filepath, 'rb+') as f:
52
+ pass
53
+ return False
54
+ except (OSError, PermissionError):
55
+ return True
56
+
46
57
  def _process_zip_files():
47
58
  for filename in os.listdir(WATCH_DIR):
48
59
  if filename.lower().endswith('.zip'):
49
60
  zip_path = os.path.join(WATCH_DIR, filename)
61
+
62
+ # Check if the file is locked
63
+ if _is_file_locked(zip_path):
64
+ logging.info(f"Skipping {zip_path}: file is locked or being copied.")
65
+ continue
66
+
50
67
  logging.info(f"zip file found: {zip_path}")
51
68
 
52
69
  case_id = execqueue.upload_case_file(zip_path, SERVER_URL)
@@ -73,11 +90,12 @@ def _check_and_download_results():
73
90
  rows = cursor.fetchall()
74
91
  for row in rows:
75
92
  record_id, filename, cloud_upload_id = row
76
- result, response = execqueue.get_execution_status(cloud_upload_id, SERVER_URL, cloud_execution=True, return_status_id=True)
77
- status = response.get('status_id', 0)
78
- message = response.get('message', None)
79
- error = response.get('error', None)
80
- if status == "5" or status == 5:
93
+ status_id, status_msg = execqueue.get_execution_status(cloud_upload_id, SERVER_URL, cloud_execution=True)
94
+ logging.info(f"Execution status for {cloud_upload_id}: {status_id} - {status_msg}")
95
+ if status_id is None:
96
+ logging.error(f"Failed to get status for {cloud_upload_id}. Skipping download.")
97
+ continue
98
+ if status_id == 5 or status_id == 6:
81
99
  files = execqueue.get_results(cloud_upload_id, SERVER_URL, cloud_execution=True)
82
100
  if files:
83
101
  base_filename = os.path.splitext(filename)[0]
@@ -91,10 +109,6 @@ def _check_and_download_results():
91
109
  cursor.execute("UPDATE processed_files SET downloaded=1 WHERE id=?", (record_id,))
92
110
  conn.commit()
93
111
  logging.info(f"Results of {cloud_upload_id} downloaded to {download_path}")
94
- elif status == "4" or status == 4:
95
- logging.info(f"Execution {cloud_upload_id} is finished with errors.")
96
- cursor.execute("UPDATE processed_files SET downloaded=4 WHERE id=?", (record_id,))
97
- conn.commit()
98
112
 
99
113
  conn.close()
100
114
 
psr/factory/__init__.py CHANGED
@@ -2,6 +2,6 @@
2
2
  # Unauthorized copying of this file, via any medium is strictly prohibited
3
3
  # Proprietary and confidential
4
4
 
5
- __version__ = "5.0.0b16"
5
+ __version__ = "5.0.0b67"
6
6
 
7
7
  from .api import *