# Path: carrot/utilities.py
# def publish_message(task: Union[str, Callable],
#                     *task_args,
#                     priority: int = 0,
#                     queue: str = None,
#                     exchange: str = '',
#                     routing_key: str = None,
#                     **task_kwargs) -> MessageLog:
#     """
#     Wrapped for :func:`.create_message`, which publishes the task to the queue
# 
#     This function is the primary method of publishing tasks to a message queue
#     """
#     if not queue:
#         queue = 'default'
#     msg = create_message(task, queue, priority, task_args, exchange, routing_key, task_kwargs)
#     return msg.publish()


import json
import pprint
from django.core.management.base import BaseCommand, CommandError, CommandParser
from carrot.utilities import publish_message


class Command(BaseCommand):
    help = 'Queues a job for execution'

    def add_arguments(self, parser: CommandParser) -> None:
        parser.add_argument('job_name', type=str)
        parser.add_argument('job_args', type=str, nargs='+')

    def handle(self, *args, **options) -> None:
        job_name = options['job_name']
        job_args = options['job_args']

        if job_args:
            publish_message(job_name, *job_args)
        else:

# Path: carrot/utilities.py
# def publish_message(task: Union[str, Callable],
#                     *task_args,
#                     priority: int = 0,
#                     queue: str = None,
#                     exchange: str = '',
#                     routing_key: str = None,
#                     **task_kwargs) -> MessageLog:
#     """
#     Wrapped for :func:`.create_message`, which publishes the task to the queue
# 
#     This function is the primary method of publishing tasks to a message queue
#     """
#     if not queue:
#         queue = 'default'
#     msg = create_message(task, queue, priority, task_args, exchange, routing_key, task_kwargs)
#     return msg.publish()


# Path: carrot/management/commands/carrot_send.py
import json
import pprint
from django.core.management.base import BaseCommand, CommandError, CommandParser
from carrot.utilities import publish_message



class Command(BaseCommand):
    help = 'Queues a job for execution'

    def add_arguments(self, parser: CommandParser) -> None:
        parser.add_argument('job_name', type=str)
        parser.add_argument('job_args', type=str, nargs='+')

    def handle(self, *args, **options) -> None:
        job_name = options['job_name']
        job_args = options['job_args']

        if job_args:
            publish_message(job_name, *job_args)
        else:

            publish_message(job_name)