Fix gather extract: file-based tasks (multi-worker safe), correct status completed check
This commit is contained in:
36
app.py.final
36
app.py.final
@@ -31,7 +31,41 @@ if not os.path.exists(TEMP_DIR):
|
||||
os.makedirs(TEMP_DIR)
|
||||
|
||||
# Global task store
|
||||
TASKS = {}
|
||||
import threading
|
||||
_task_lock = threading.Lock()
|
||||
_TASK_FILE = '/tmp/seismic_tasks.json'
|
||||
|
||||
def _load_tasks():
|
||||
try:
|
||||
with open(_TASK_FILE) as f:
|
||||
return json.load(f)
|
||||
except:
|
||||
return {}
|
||||
|
||||
def _save_tasks(tasks):
|
||||
with open(_TASK_FILE, 'w') as f:
|
||||
json.dump(tasks, f)
|
||||
|
||||
class TasksProxy:
|
||||
def get(self, key, default=None):
|
||||
return _load_tasks().get(key, default)
|
||||
def __setitem__(self, key, value):
|
||||
with _task_lock:
|
||||
tasks = _load_tasks()
|
||||
tasks[key] = value
|
||||
_save_tasks(tasks)
|
||||
def __getitem__(self, key):
|
||||
return _load_tasks()[key]
|
||||
def __contains__(self, key):
|
||||
return key in _load_tasks()
|
||||
def pop(self, key, *args):
|
||||
with _task_lock:
|
||||
tasks = _load_tasks()
|
||||
result = tasks.pop(key, *args)
|
||||
_save_tasks(tasks)
|
||||
return result
|
||||
|
||||
TASKS = TasksProxy()
|
||||
|
||||
# ========== UTILITY FUNCTIONS ==========
|
||||
|
||||
|
||||
Reference in New Issue
Block a user