Enhance caching mechanism and logging configuration

- Updated .gitignore to include additional IDE and OS files, as well as log and web build directories.
- Expanded config.sample.yaml to include cache configuration options for memory and Redis.
- Modified wallamonitor.py to load cache configuration and initialize ArticleCache.
- Refactored QueueManager to utilize ArticleCache for tracking notified articles.
- Improved logging setup to dynamically determine log file path based on environment.
This commit is contained in:
Omar Sánchez Pizarro
2026-01-19 19:42:12 +01:00
parent b32b0b2e09
commit 9939c4d9ed
41 changed files with 6742 additions and 28 deletions

View File

@@ -0,0 +1,212 @@
<template>
<div>
<div class="flex justify-between items-center mb-6">
<h1 class="text-3xl font-bold text-gray-900">Artículos Notificados</h1>
<div class="flex items-center space-x-4">
<select
v-model="selectedPlatform"
@change="loadArticles"
class="input"
style="width: auto;"
>
<option value="">Todas las plataformas</option>
<option value="wallapop">Wallapop</option>
<option value="vinted">Vinted</option>
</select>
<button @click="loadArticles" class="btn btn-primary">
Actualizar
</button>
</div>
</div>
<div v-if="loading" class="text-center py-12">
<div class="inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-primary-600"></div>
<p class="mt-2 text-gray-600">Cargando artículos...</p>
</div>
<div v-else-if="articles.length === 0" class="card text-center py-12">
<p class="text-gray-600">No hay artículos para mostrar</p>
</div>
<div v-else class="space-y-4">
<div
v-for="article in articles"
:key="`${article.platform}-${article.id}`"
class="card hover:shadow-lg transition-shadow"
>
<div class="flex gap-4">
<!-- Imagen del artículo -->
<div class="flex-shrink-0">
<div v-if="article.images && article.images.length > 0" class="w-32 h-32 relative">
<img
:src="article.images[0]"
:alt="article.title || 'Sin título'"
class="w-32 h-32 object-cover rounded-lg"
@error="($event) => handleImageError($event)"
/>
</div>
<div v-else class="w-32 h-32 bg-gray-200 rounded-lg flex items-center justify-center">
<span class="text-gray-400 text-xs">Sin imagen</span>
</div>
</div>
<!-- Información del artículo -->
<div class="flex-1 min-w-0">
<div class="flex items-start justify-between mb-2">
<div class="flex-1 min-w-0">
<div class="flex items-center space-x-2 mb-2">
<span
class="px-2 py-1 text-xs font-semibold rounded flex-shrink-0"
:class="
article.platform === 'wallapop'
? 'bg-blue-100 text-blue-800'
: 'bg-green-100 text-green-800'
"
>
{{ article.platform?.toUpperCase() || 'N/A' }}
</span>
<span class="text-sm text-gray-500 whitespace-nowrap">
{{ formatDate(article.notifiedAt) }}
</span>
</div>
<h3 class="text-lg font-semibold text-gray-900 mb-1 truncate" :title="article.title">
{{ article.title || 'Sin título' }}
</h3>
<div v-if="article.price !== null && article.price !== undefined" class="mb-2">
<span class="text-xl font-bold text-primary-600">
{{ article.price }} {{ article.currency || '€' }}
</span>
</div>
<div class="space-y-1 text-sm text-gray-600 mb-2">
<div v-if="article.location" class="flex items-center">
<span class="font-medium">📍 Localidad:</span>
<span class="ml-2">{{ article.location }}</span>
</div>
<div v-if="article.allows_shipping !== null" class="flex items-center">
<span class="font-medium">🚚 Envío:</span>
<span class="ml-2">{{ article.allows_shipping ? '✅ Acepta envíos' : '❌ No acepta envíos' }}</span>
</div>
<div v-if="article.modified_at" class="flex items-center">
<span class="font-medium">🕒 Modificado:</span>
<span class="ml-2">{{ article.modified_at }}</span>
</div>
</div>
<p v-if="article.description" class="text-sm text-gray-700 mb-2 overflow-hidden" style="display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;">
{{ article.description }}
</p>
<div class="flex items-center space-x-4 mt-3">
<a
v-if="article.url"
:href="article.url"
target="_blank"
rel="noopener noreferrer"
class="text-primary-600 hover:text-primary-700 text-sm font-medium"
>
🔗 Ver anuncio
</a>
<span class="text-xs text-gray-400">
ID: {{ article.id }}
</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="flex justify-center space-x-2 mt-6">
<button
@click="loadMore"
:disabled="articles.length >= total"
class="btn btn-secondary"
:class="{ 'opacity-50 cursor-not-allowed': articles.length >= total }"
>
Cargar más
</button>
</div>
<p class="text-center text-sm text-gray-500 mt-4">
Mostrando {{ articles.length }} de {{ total }} artículos
</p>
</div>
</div>
</template>
<script setup>
import { ref, onMounted, onUnmounted } from 'vue';
import api from '../services/api';
const articles = ref([]);
const loading = ref(true);
const total = ref(0);
const offset = ref(0);
const limit = 50;
const selectedPlatform = ref('');
function formatDate(timestamp) {
if (!timestamp) return 'N/A';
return new Date(timestamp).toLocaleString('es-ES');
}
async function loadArticles(reset = true) {
if (reset) {
offset.value = 0;
articles.value = [];
}
loading.value = true;
try {
const data = await api.getArticles(limit, offset.value);
let filtered = data.articles;
if (selectedPlatform.value) {
filtered = filtered.filter(a => a.platform === selectedPlatform.value);
}
if (reset) {
articles.value = filtered;
} else {
articles.value.push(...filtered);
}
total.value = data.total;
offset.value += limit;
} catch (error) {
console.error('Error cargando artículos:', error);
} finally {
loading.value = false;
}
}
function loadMore() {
loadArticles(false);
}
function handleWSMessage(event) {
const data = event.detail;
if (data.type === 'articles_updated') {
loadArticles();
}
}
function handleImageError(event) {
// Si la imagen falla al cargar, reemplazar con placeholder
event.target.onerror = null; // Prevenir bucle infinito
event.target.src = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTI4IiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4IiBmaWxsPSIjRjNGNEY2Ii8+CjxwYXRoIGQ9Ik00OCA0OEg4ME04MCA4MEg0OE00OCA0OEw2NCA2NEw4MCA0OE00OCA4MEw2NCA2NE04MCA4MEw2NCA2NEw0OCA4MCIgc3Ryb2tlPSIjOUI5Q0E0IiBzdHJva2Utd2lkdGg9IjIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPgo8L3N2Zz4K';
}
onMounted(() => {
loadArticles();
window.addEventListener('ws-message', handleWSMessage);
});
onUnmounted(() => {
window.removeEventListener('ws-message', handleWSMessage);
});
</script>