Skip to content

Configuration

Configuration functions for reading Django Simple Queue settings.

API Reference

conf

Configuration settings for django_simple_queue.

Settings are read from Django's settings.py with the DJANGO_SIMPLE_QUEUE_ prefix.

get_allowed_tasks() -> set[str] | None

Returns the set of allowed task callables.

Configure in settings.py: DJANGO_SIMPLE_QUEUE_ALLOWED_TASKS = { "myapp.tasks.process_order", "myapp.tasks.send_email", }

If not set or set to None, ALL tasks are allowed (unsafe, but backwards-compatible). Set to an empty set to disallow all tasks.

Source code in django_simple_queue/conf.py
def get_allowed_tasks() -> set[str] | None:
    """
    Returns the set of allowed task callables.

    Configure in settings.py:
        DJANGO_SIMPLE_QUEUE_ALLOWED_TASKS = {
            "myapp.tasks.process_order",
            "myapp.tasks.send_email",
        }

    If not set or set to None, ALL tasks are allowed (unsafe, but backwards-compatible).
    Set to an empty set to disallow all tasks.
    """
    allowed = getattr(settings, "DJANGO_SIMPLE_QUEUE_ALLOWED_TASKS", None)
    if allowed is None:
        return None  # No restriction (backwards-compatible but unsafe)
    return set(allowed)

is_task_allowed(task_path: str) -> bool

Check if a task path is in the allowed list.

Parameters:

Name Type Description Default
task_path str

Dotted path to the callable (e.g., "myapp.tasks.process_order")

required

Returns:

Type Description
bool

True if allowed, False if not allowed.

bool

If DJANGO_SIMPLE_QUEUE_ALLOWED_TASKS is not configured, returns True (permissive).

Source code in django_simple_queue/conf.py
def is_task_allowed(task_path: str) -> bool:
    """
    Check if a task path is in the allowed list.

    Args:
        task_path: Dotted path to the callable (e.g., "myapp.tasks.process_order")

    Returns:
        True if allowed, False if not allowed.
        If DJANGO_SIMPLE_QUEUE_ALLOWED_TASKS is not configured, returns True (permissive).
    """
    allowed = get_allowed_tasks()
    if allowed is None:
        # No allowlist configured - permissive mode (backwards-compatible)
        return True
    return task_path in allowed

get_max_output_size() -> int

Returns the maximum allowed output size in bytes.

Configure in settings.py: DJANGO_SIMPLE_QUEUE_MAX_OUTPUT_SIZE = 1_000_000 # 1MB

Default: 10MB

Source code in django_simple_queue/conf.py
def get_max_output_size() -> int:
    """
    Returns the maximum allowed output size in bytes.

    Configure in settings.py:
        DJANGO_SIMPLE_QUEUE_MAX_OUTPUT_SIZE = 1_000_000  # 1MB

    Default: 10MB
    """
    return getattr(settings, "DJANGO_SIMPLE_QUEUE_MAX_OUTPUT_SIZE", 10 * 1024 * 1024)

get_max_args_size() -> int

Returns the maximum allowed args JSON size in bytes.

Configure in settings.py: DJANGO_SIMPLE_QUEUE_MAX_ARGS_SIZE = 100_000 # 100KB

Default: 1MB

Source code in django_simple_queue/conf.py
def get_max_args_size() -> int:
    """
    Returns the maximum allowed args JSON size in bytes.

    Configure in settings.py:
        DJANGO_SIMPLE_QUEUE_MAX_ARGS_SIZE = 100_000  # 100KB

    Default: 1MB
    """
    return getattr(settings, "DJANGO_SIMPLE_QUEUE_MAX_ARGS_SIZE", 1024 * 1024)

get_task_timeout() -> int | None

Returns the maximum execution time for a task in seconds.

Configure in settings.py: DJANGO_SIMPLE_QUEUE_TASK_TIMEOUT = 300 # 5 minutes

If not set or set to None, tasks can run indefinitely. Set to 0 or negative to disable timeout.

Default: 3600 (1 hour)

Source code in django_simple_queue/conf.py
def get_task_timeout() -> int | None:
    """
    Returns the maximum execution time for a task in seconds.

    Configure in settings.py:
        DJANGO_SIMPLE_QUEUE_TASK_TIMEOUT = 300  # 5 minutes

    If not set or set to None, tasks can run indefinitely.
    Set to 0 or negative to disable timeout.

    Default: 3600 (1 hour)
    """
    timeout = getattr(settings, "DJANGO_SIMPLE_QUEUE_TASK_TIMEOUT", 3600)
    if timeout is None or timeout <= 0:
        return None
    return timeout

Settings Overview

All settings are read from Django's settings.py with the DJANGO_SIMPLE_QUEUE_ prefix.

Setting Default Description
DJANGO_SIMPLE_QUEUE_ALLOWED_TASKS None Set of allowed task paths
DJANGO_SIMPLE_QUEUE_TASK_TIMEOUT 3600 Task timeout in seconds
DJANGO_SIMPLE_QUEUE_MAX_OUTPUT_SIZE 10MB Max output size in bytes
DJANGO_SIMPLE_QUEUE_MAX_ARGS_SIZE 1MB Max args JSON size in bytes

Functions

get_allowed_tasks()

Returns the set of allowed task callables, or None if no restriction.

from django_simple_queue.conf import get_allowed_tasks

allowed = get_allowed_tasks()
if allowed is None:
    print("All tasks allowed (not recommended)")
else:
    print(f"Allowed tasks: {allowed}")

is_task_allowed(task_path)

Check if a specific task path is allowed.

from django_simple_queue.conf import is_task_allowed

if is_task_allowed("myapp.tasks.send_email"):
    print("Task is allowed")
else:
    print("Task is blocked")

get_task_timeout()

Returns the task timeout in seconds, or None if disabled.

from django_simple_queue.conf import get_task_timeout

timeout = get_task_timeout()
if timeout:
    print(f"Tasks timeout after {timeout} seconds")
else:
    print("No timeout configured")

get_max_output_size()

Returns the maximum output size in bytes.

from django_simple_queue.conf import get_max_output_size

max_size = get_max_output_size()
print(f"Max output: {max_size / 1024 / 1024:.1f} MB")

get_max_args_size()

Returns the maximum args JSON size in bytes.

from django_simple_queue.conf import get_max_args_size

max_size = get_max_args_size()
print(f"Max args: {max_size / 1024:.1f} KB")

Example Configuration

# settings.py

# Only allow specific tasks
DJANGO_SIMPLE_QUEUE_ALLOWED_TASKS = {
    "orders.tasks.process_order",
    "emails.tasks.send_notification",
    "reports.tasks.generate_daily",
}

# 5 minute timeout
DJANGO_SIMPLE_QUEUE_TASK_TIMEOUT = 300

# Limit output to 5 MB
DJANGO_SIMPLE_QUEUE_MAX_OUTPUT_SIZE = 5 * 1024 * 1024

# Limit args to 100 KB
DJANGO_SIMPLE_QUEUE_MAX_ARGS_SIZE = 100 * 1024

See the Configuration Guide for detailed explanations of each setting.