realtime updated
This commit is contained in:
1 parent
a438493a76
commit
25ab7dfce7
3 files changed
+48
No files matched your search
Binary file not shown.
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"2024-01-01_12-00-00": {
|
||||
"status": "processing",
|
||||
"files": [
|
||||
{
|
||||
"name": "test.pdf",
|
||||
"path": "/tmp/test.pdf"
|
||||
}
|
||||
],
|
||||
"zip_path": null,
|
||||
"zip_name": null,
|
||||
"processed_files": [],
|
||||
"skipped": [],
|
||||
"created_at": "2024-01-01 12:00:00",
|
||||
"job_id": "2024-01-01_12-00-00",
|
||||
"progress": "Created ZIP archive with 1 organized files"
|
||||
}
|
||||
}
|
||||
@@ -510,6 +510,7 @@ def process_job(job_id, files):
|
||||
print("=== DEBUG: process_job STARTED ===")
|
||||
job_queue[job_id]['status'] = 'processing'
|
||||
job_queue[job_id]['progress'] = 'Starting job processing...'
|
||||
save_jobs() # Persist initial progress
|
||||
save_jobs() # Persist status change
|
||||
processed_files = []
|
||||
temp_extract_dirs = []
|
||||
@@ -538,6 +539,7 @@ def process_job(job_id, files):
|
||||
for file_info in files if file_info['name'].lower().endswith('.zip'))
|
||||
|
||||
job_queue[job_id]['progress'] = f'Found {total_files} files to process'
|
||||
save_jobs() # Persist file count
|
||||
|
||||
processed_count = 0
|
||||
|
||||
@@ -662,6 +664,7 @@ def process_job(job_id, files):
|
||||
job_queue[job_id]['zip_path'] = zip_output
|
||||
job_queue[job_id]['zip_name'] = f'renamed_{job_id}.zip'
|
||||
job_queue[job_id]['progress'] = f'Created ZIP archive with {len(successful_files)} organized files'
|
||||
save_jobs() # Persist completion progress
|
||||
print(f"DEBUG: ZIP creation completed successfully")
|
||||
except Exception as e:
|
||||
job_queue[job_id]['progress'] = f'Error creating ZIP: {str(e)}'
|
||||
@@ -1028,17 +1031,41 @@ def jobs():
|
||||
<p>No jobs yet. <a href="/">Upload some files</a> to get started.</p>
|
||||
{% endif %}
|
||||
<script>
|
||||
// Track previous job statuses to detect completion
|
||||
let previousJobStatuses = {};
|
||||
|
||||
function updateJobs() {
|
||||
fetch('/api/jobs', { credentials: 'same-origin' })
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log('Job update received:', data);
|
||||
const jobs = Object.entries(data);
|
||||
|
||||
// Check for job completions
|
||||
let hasNewCompletion = false;
|
||||
if (jobs.length > 0) {
|
||||
jobs.forEach(([jobId, job]) => {
|
||||
console.log(`Job ${jobId}: status=${job.status}, progress=${job.progress || 'none'}`);
|
||||
|
||||
// Check if job just completed
|
||||
if (job.status === 'completed' && previousJobStatuses[jobId] === 'processing') {
|
||||
hasNewCompletion = true;
|
||||
console.log(`Job ${jobId} just completed!`);
|
||||
}
|
||||
|
||||
// Update previous status
|
||||
previousJobStatuses[jobId] = job.status;
|
||||
});
|
||||
}
|
||||
|
||||
// Redirect to completed jobs if a job just finished
|
||||
if (hasNewCompletion) {
|
||||
console.log('Redirecting to completed jobs page...');
|
||||
setTimeout(() => {
|
||||
window.location.href = '/completed-jobs';
|
||||
}, 500); // Small delay to show completion briefly
|
||||
return; // Stop processing to avoid UI updates during redirect
|
||||
}
|
||||
const jobsContainer = document.querySelector('h1').parentNode;
|
||||
const existingJobs = jobsContainer.querySelectorAll('.job');
|
||||
const existingNoJobsMsg = jobsContainer.querySelectorAll('p');
|
||||
@@ -1120,6 +1147,9 @@ def jobs():
|
||||
// Update jobs every 1 second
|
||||
setInterval(updateJobs, 1000);
|
||||
|
||||
// Initialize previous job statuses
|
||||
updateJobs(); // Run once immediately to populate initial statuses
|
||||
|
||||
// Collapsible section functions
|
||||
function toggleZipDetails(element) {
|
||||
const details = element.nextElementSibling;
|
||||
|
||||
Reference in new issue
Block a user