Faviconsο
The favicons module is responsible for automatically fetching and storing favicon images for monitored projects. It provides a complete workflow from scheduling to storage, ensuring that project favicons are kept up-to-date.
Model Structureο
Faviconο
The Favicon model stores favicon-related data and metadata for projects.
File: src/favicons/models.py
Field |
Type |
Default |
Description |
|---|---|---|---|
id |
AutoField |
Auto-increment |
Primary key |
project |
OneToOneField |
- |
Reference to the Project this favicon belongs to |
favicon |
ImageField |
null |
The actual favicon image file |
task_status |
CharField |
βUNKNOWNβ |
Status of the favicon fetching task |
last_edited |
DateTimeField |
timezone.now |
Last time the favicon was updated |
created_at |
DateTimeField |
auto_now_add |
When the favicon record was created |
updated_at |
DateTimeField |
auto_now |
When the favicon record was last modified |
celery_task_log |
ForeignKey |
null |
Reference to the associated Celery task log |
Task Status Optionsο
The task_status field can have the following values:
PENDING: Task is queued but not yet startedSUCCESS: Favicon was successfully fetched and storedFAILURE: Failed to fetch favicon from the websiteUNKNOWN: Default status for new records
File Upload Pathο
Favicons are stored using the following path structure:
user_{user_id}/prjct_{project_id}/favicons/{filename}
Workflow Overviewο
The favicon system operates through a sophisticated workflow involving multiple components:
Scheduler: Runs periodic tasks to identify projects needing favicon updates
Worker: Fetches favicons from websites and processes them
API: Handles communication between components and database operations
Database: Stores favicon metadata and file references
API Endpointsο
Fetch Deprecated Faviconsο
Endpoint: GET /api/fetch_deprecated_favicons/{secret_key}/
Purpose: Returns a list of projects that need favicon updates (older than 6 hours or missing favicon)
Authentication: Uses Django SECRET_KEY for worker authentication
Response:
{
"projects": [
{
"id": 1,
"url": "https://example.com"
}
]
}
Save Faviconο
Endpoint: POST /api/save_favicon/{secret_key}/{project_id}/
Purpose: Saves the fetched favicon data to the database
Authentication: Uses Django SECRET_KEY for worker authentication
Request Body:
{
"favicon_url": "https://example.com/favicon.ico",
"favicon_content": "base64_encoded_image_data",
"duration": 2.5
}
Tasksο
queue_deprecated_faviconsο
Schedule: Every 60 seconds (configured in src/fromedwin/celery.py)
Purpose:
Identifies projects with outdated favicons (older than 6 hours)
Ensures only one instance of this task runs at a time
Schedules individual
fetch_favicontasks for each project
Workflow:
Revokes any existing queued tasks of the same type
Calls the API to get list of projects needing updates
Schedules
fetch_favicontasks for each project
fetch_faviconο
Purpose: Fetches favicon from a website and processes it
Parameters:
pk: Project IDurl: Website URL to fetch favicon from
Workflow:
Fetches the webpage HTML
Searches for favicon links in
<link>tagsDownloads and processes each favicon candidate
Selects the largest favicon (by pixel area)
Prefers SVG format when available
Sends results back to the API for storage
Error Handling:
Logs errors for individual favicon URLs
Falls back to default
/favicon.icolocationReports failure status if no favicon is found
Configurationο
Key settings in src/fromedwin/celery.py:
app.conf.beat_schedule = {
'queue_deprecated_favicons': {
'task': 'favicons.tasks.queue_deprecated_favicons',
'schedule': 60, # Run every 60 seconds
},
}
Monitoringο
The system provides several monitoring capabilities:
Task status tracking in the Favicon model
Celery task logs with duration metrics
API endpoint authentication logging
Error logging for failed favicon fetches