🔍 Overview

This document describes the Celery tasks responsible for scheduling and sending domain unblock appeals to Google Search Console. The tasks ensure that appeals are sent only when appropriate, adhering to timing constraints to avoid spamming.


📝 Task Definitions

@celery.task
def schedule_domain_appeals_task():
    logger.info("Starting appeal sender task...")
    domains_map = Link.get_blocked_by_google_domains_map()
    # randomize the start countdown
    start_countdown = random.randint(0, 60)
    for domain, owners in domains_map.items():
        for owner in owners:
            logger.info(f"Processing blocked domain {domain} for owner {str(owner)}")
            if not DomainBlockAppeal.can_send_appeal(domain, owner.id):
                logger.info(
                    f"Skipping appeal for domain {domain} for owner {str(owner)}. "
                    "Either an appeal was already sent successfully within the last 12 hours or it is safe."
                )
                continue
            # create a new task to send appeal
            send_appeal_task.apply_async(args=(domain, owner.id), countdown=start_countdown)
            logger.info(f"Scheduled appeal for domain {domain} to be sent in {start_countdown} seconds.")
            # randomize the countdown for the next appeal
            start_countdown += random.randint(120, 180)
    logger.info("All blocked domains processed, appeal sender task completed.")
 
 
@celery.task
def send_appeal_task(domain: str, owner_id: int):
    owner = UserModel.objects.get(id=owner_id)
    if not DomainBlockAppeal.can_send_appeal(domain, owner_id):
        logger.info(
            f"Cannot send appeal for domain {domain} for owner {str(owner)}. "
            "Either an appeal was already sent successfully within the last 12 hours or it is safe."
        )
        return
    AppealSenderController(domain, owner).send_appeal()

⚙️ Task Behavior & Flow

  1. Scheduling Appeals: The schedule_domain_appeals_task is responsible for identifying blocked domains and scheduling appeal tasks for each domain-owner pair. It checks if an appeal can be sent based on the business rules and randomizes the countdown for each scheduled task.
  2. Sending Appeals: The send_appeal_task is responsible for actually sending the appeal for a specific domain-owner pair. It checks if the appeal can be sent and, if so, invokes the AppealSenderController to perform the sending.
  3. Timing Constraints: Appeals are only sent if no successful appeal has been sent in the last 12 hours for the same domain-owner pair, ensuring compliance with anti-spam measures.
  4. Logging: Both tasks include logging at various stages to provide visibility into the process, including when appeals are scheduled and sent, as well as any reasons for skipping appeals.