mirror of
https://github.com/thecyberlearn/quantum-ai-v3.git
synced 2026-08-18 15:12:58 +00:00
Fix job posting generator processing issues
- Correct price display from 4.00 AED to dynamic agent price (3.00 AED) - Fix JavaScript balance check to use proper agent price - Improve polling function with better error handling and logging - Add proper JavaScript variable initialization for agent price - Enhance status response handling for failed requests 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8e3cf451a1
commit
f2a0b3c3af
@ -14,6 +14,9 @@
|
|||||||
document.body.setAttribute('data-user-authenticated', '{{ user.is_authenticated|yesno:"true,false" }}');
|
document.body.setAttribute('data-user-authenticated', '{{ user.is_authenticated|yesno:"true,false" }}');
|
||||||
document.body.setAttribute('data-login-url', '{% url "authentication:login" %}');
|
document.body.setAttribute('data-login-url', '{% url "authentication:login" %}');
|
||||||
document.body.setAttribute('data-wallet-url', '{% url "wallet:wallet" %}');
|
document.body.setAttribute('data-wallet-url', '{% url "wallet:wallet" %}');
|
||||||
|
|
||||||
|
// Initialize agent configuration
|
||||||
|
window.AGENT_PRICE = {{ agent.price }};
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
@ -275,13 +278,13 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
{% if user.wallet_balance >= 4.00 %}
|
{% if user.wallet_balance >= agent.price %}
|
||||||
<button type="submit" class="btn btn-primary btn-full" id="processButton">
|
<button type="submit" class="btn btn-primary btn-full" id="processButton">
|
||||||
💼 Generate Job Posting (4.00 AED)
|
💼 Generate Job Posting ({{ agent.price }} AED)
|
||||||
</button>
|
</button>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="alert alert-error">
|
<div class="alert alert-error">
|
||||||
Insufficient balance! You need 4.00 AED.
|
Insufficient balance! You need {{ agent.price }} AED.
|
||||||
</div>
|
</div>
|
||||||
<a href="{% url 'wallet:wallet' %}" class="btn btn-primary btn-full">
|
<a href="{% url 'wallet:wallet' %}" class="btn btn-primary btn-full">
|
||||||
💰 Top Up Wallet
|
💰 Top Up Wallet
|
||||||
@ -371,31 +374,49 @@
|
|||||||
// Poll for results
|
// Poll for results
|
||||||
function pollForResults(requestId) {
|
function pollForResults(requestId) {
|
||||||
let pollCount = 0;
|
let pollCount = 0;
|
||||||
const maxPolls = 30;
|
const maxPolls = 30; // 30 seconds max
|
||||||
|
|
||||||
|
console.log(`Starting polling for request: ${requestId}`);
|
||||||
|
|
||||||
const pollInterval = setInterval(() => {
|
const pollInterval = setInterval(() => {
|
||||||
pollCount++;
|
pollCount++;
|
||||||
|
console.log(`Poll attempt ${pollCount}/${maxPolls} for request: ${requestId}`);
|
||||||
|
|
||||||
fetch(`/agents/job-posting-generator/status/${requestId}/`)
|
fetch(`/agents/job-posting-generator/status/${requestId}/`)
|
||||||
.then(response => response.json())
|
.then(response => {
|
||||||
|
console.log(`Status response: ${response.status}`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP ${response.status}`);
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.status === 'completed' || result.status === 'failed') {
|
console.log('Poll result:', result);
|
||||||
|
|
||||||
|
if (result.status === 'completed') {
|
||||||
clearInterval(pollInterval);
|
clearInterval(pollInterval);
|
||||||
hideProcessing();
|
hideProcessing();
|
||||||
document.getElementById('processButton').disabled = false;
|
document.getElementById('processButton').disabled = false;
|
||||||
displayResults(result);
|
displayResults(result);
|
||||||
|
} else if (result.status === 'failed') {
|
||||||
|
clearInterval(pollInterval);
|
||||||
|
hideProcessing();
|
||||||
|
document.getElementById('processButton').disabled = false;
|
||||||
|
showToast(`❌ Processing failed: ${result.error || 'Unknown error'}`, 'error');
|
||||||
} else if (pollCount >= maxPolls) {
|
} else if (pollCount >= maxPolls) {
|
||||||
clearInterval(pollInterval);
|
clearInterval(pollInterval);
|
||||||
hideProcessing();
|
hideProcessing();
|
||||||
document.getElementById('processButton').disabled = false;
|
document.getElementById('processButton').disabled = false;
|
||||||
showToast('❌ Timeout - please try again', 'error');
|
showToast('⏰ Processing is taking longer than expected. Please check back later.', 'error');
|
||||||
}
|
}
|
||||||
|
// Continue polling if status is 'processing' or 'pending'
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
console.error('Polling error:', error);
|
||||||
clearInterval(pollInterval);
|
clearInterval(pollInterval);
|
||||||
hideProcessing();
|
hideProcessing();
|
||||||
document.getElementById('processButton').disabled = false;
|
document.getElementById('processButton').disabled = false;
|
||||||
showToast('❌ Network error', 'error');
|
showToast(`❌ Error checking status: ${error.message}`, 'error');
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
@ -419,8 +440,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const currentBalance = parseFloat(document.getElementById('walletBalance').textContent) || 0;
|
const currentBalance = parseFloat(document.getElementById('walletBalance').textContent) || 0;
|
||||||
if (currentBalance < 4.00) {
|
const requiredBalance = window.AGENT_PRICE || 3.00;
|
||||||
showToast('Insufficient balance! You need 4.00 AED.', 'error');
|
if (currentBalance < requiredBalance) {
|
||||||
|
showToast(`Insufficient balance! You need ${requiredBalance} AED.`, 'error');
|
||||||
setTimeout(() => window.location.href = document.body.getAttribute('data-wallet-url'), 2000);
|
setTimeout(() => window.location.href = document.body.getAttribute('data-wallet-url'), 2000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user