
from typing import List, Optional

from ... import email
from ...typing import BrandID

from .models import EmailConfig


def find_sender_address_for_brand(brand_id: BrandID) -> Optional[str]:
    """Return the configured sender e-mail address for the brand."""
    config = EmailConfig.query.get(brand_id)

    if config is None:
        return None

    return config.sender_address


def send_email(recipients: List[str], subject: str, body: str, *,
               sender: Optional[str]=None) -> None:
    """Send an e-mail."""
    email.send(recipients, subject, body, sender=sender)


from typing import List, Optional

from ... import email
from ...typing import BrandID
from ...util.jobqueue import enqueue

from .models import EmailConfig


def find_sender_address_for_brand(brand_id: BrandID) -> Optional[str]:
    """Return the configured sender e-mail address for the brand."""
    config = EmailConfig.query.get(brand_id)

    if config is None:
        return None

    return config.sender_address


def enqueue_email(recipients: List[str], subject: str, body: str, *,
               sender: Optional[str]=None) -> None:
    """Enqueue an e-mail to be sent asynchronously."""
    enqueue(send_email, recipients, subject, body, sender=sender)


def send_email(recipients: List[str], subject: str, body: str, *,
               sender: Optional[str]=None) -> None:
    """Send an e-mail."""
    email.send(recipients, subject, body, sender=sender)

Add function to enqueue e-mails to be sent asynchronously rather than blocking/sending synchronously
Add function to enqueue e-mails to be sent asynchronously rather than blocking/sending synchronously

  
  from typing import List, Optional
  
  from ... import email
  from ...typing import BrandID
+ from ...util.jobqueue import enqueue
  
  from .models import EmailConfig
  
  
  def find_sender_address_for_brand(brand_id: BrandID) -> Optional[str]:
      """Return the configured sender e-mail address for the brand."""
      config = EmailConfig.query.get(brand_id)
  
      if config is None:
          return None
  
      return config.sender_address
  
  
+ def enqueue_email(recipients: List[str], subject: str, body: str, *,
+                sender: Optional[str]=None) -> None:
+     """Enqueue an e-mail to be sent asynchronously."""
+     enqueue(send_email, recipients, subject, body, sender=sender)
+ 
+ 
  def send_email(recipients: List[str], subject: str, body: str, *,
                 sender: Optional[str]=None) -> None:
      """Send an e-mail."""
      email.send(recipients, subject, body, sender=sender)
  
Add function to enqueue e-mails to be sent asynchronously rather than blocking/sending synchronously
## Code Before:

from typing import List, Optional

from ... import email
from ...typing import BrandID

from .models import EmailConfig


def find_sender_address_for_brand(brand_id: BrandID) -> Optional[str]:
    """Return the configured sender e-mail address for the brand."""
    config = EmailConfig.query.get(brand_id)

    if config is None:
        return None

    return config.sender_address


def send_email(recipients: List[str], subject: str, body: str, *,
               sender: Optional[str]=None) -> None:
    """Send an e-mail."""
    email.send(recipients, subject, body, sender=sender)

## Instruction:
Add function to enqueue e-mails to be sent asynchronously rather than blocking/sending synchronously
## Code After:

from typing import List, Optional

from ... import email
from ...typing import BrandID
from ...util.jobqueue import enqueue

from .models import EmailConfig


def find_sender_address_for_brand(brand_id: BrandID) -> Optional[str]:
    """Return the configured sender e-mail address for the brand."""
    config = EmailConfig.query.get(brand_id)

    if config is None:
        return None

    return config.sender_address


def enqueue_email(recipients: List[str], subject: str, body: str, *,
               sender: Optional[str]=None) -> None:
    """Enqueue an e-mail to be sent asynchronously."""
    enqueue(send_email, recipients, subject, body, sender=sender)


def send_email(recipients: List[str], subject: str, body: str, *,
               sender: Optional[str]=None) -> None:
    """Send an e-mail."""
    email.send(recipients, subject, body, sender=sender)
