🔍 Overview
These Celery tasks monitor active Links and block them when they become unsafe or unreachable.
When a link is blocked, Link Switcher tries to switch traffic to the next backup link in Voluum via MirrorRule.
Main tasks:
check_active_links_via_google_task— checks ACTIVE link domains via Google Safe Browsing.check_active_domains_via_dns_task— blocks domains that are not resolvable via DNS.rotation_check_active_links_task— blocks links whose rotation interval has expired.block_link_task— blocks a specific link and triggers switching.fix_pipelines_task— fixes failed switches in MirrorRule (safety net).
⏱ Schedule (Celery Beat)
Configured in config/settings.py:
check_active_links_via_google_task— everyCHECK_ACTIVE_LINKS_INTERVALsecondsrotation_check_active_links_task— every 15 minutesfix_pipelines_task— every hour (minute0)
📝 Task Definitions
@celery.task
def check_active_links_via_google_task():
domain_map = Link.get_domains_map()
if not domain_map:
return
VoluumController.load_data(landers=True, offers=True, campaigns=False)
for chunk_domains in chunked(list(domain_map.keys())):
unsafe_domains = GoogleSafeBrowsing.check_links(chunk_domains)
if unsafe_domains is None:
continue
for unsafe_domain, reason in unsafe_domains.items():
for obj in domain_map[unsafe_domain]:
block_link_task.delay(link_id=obj.id, reason=reason)
check_active_domains_via_dns_task.delay()
@celery.task
def block_link_task(link_id: int, reason: str = BlockReasons.UNKNOWN, action_by: str = "system"):
try:
link = Link.objects.get(id=link_id)
except Link.DoesNotExist:
return
if link.status != LinkStatuses.ACTIVE:
return
link.set_block(reason=reason, with_switch=True, action_by=action_by)📑 Parameters (block_link_task)
| Name | Type | Description |
|---|---|---|
link_id | int | Primary key of the Link to block. |
reason | str | Block reason (DNS / rotation / Google Safe Browsing threat type). |
action_by | str | Actor causing the block (system or a username). |
⚙️ Task Behavior & Flow
-
Google Safe Browsing check
- Groups active links by domain.
- Calls Google Safe Browsing in batches.
- Enqueues
block_link_taskfor unsafe domains.
-
DNS check
- Blocks domains that fail DNS resolution using
BlockReasons.DNS_NOT_RESOLVABLE.
- Blocks domains that fail DNS resolution using
-
Rotation check
- Blocks links with
with_rotation=Truewhen their rotation interval has expired usingBlockReasons.ROTATION.
- Blocks links with
-
Blocking & switching
block_link_taskcallsLink.set_block(..., with_switch=True).- Switching to the next backup is handled by
MirrorRule.switch(...).
-
Pipeline maintenance
fix_pipelines_taskretries failedMirrorRule.switch()executions and cleans up mirror rules stuck in an inconsistent state.