Git Product home page Git Product logo

Comments (5)

kyleaquino avatar kyleaquino commented on July 28, 2024

Here's my fix for this issue. Kindly respond. Thank you!

# Added msg_group_id for customization of id
def publish(self, task_class, task_id, payload,
                current_retry_num=None, delay_sec=None, msg_group_id='default'): 
        """Publish the given task type to the queue with the provided payload.

        :param obj task_class: class of the task that we are publishing.
        :param str task_id: unique identifying string for this task.
        :param dict payload: dictionary for the task payload.
        :param int current_retry_num: current task retry count. If 0, this is
            the first attempt to run the task.
        :param int delay_sec: time (in seconds) that a task should stay
                in the queue before being released to consumers.
        :param str msg_group_id: MessageGroupId Parameter for Content-based 
                Deduplication enabled queues
        :raises: TaskTooChubbyException: This task is outrageously chubby.
                The publisher of the task should handle this exception and
                determine how to proceed.def publish(self, task_class, task_id, payload,
        """

        if delay_sec is not None and delay_sec > settings.SQS_MAX_TASK_DELAY_SEC:
            raise exceptions.InvalidTaskDelayException(
                'Invalid task delay_sec (%d > %d).' % (
                    delay_sec, settings.SQS_MAX_TASK_DELAY_SEC))

        queue_class = utils.class_import_from_path(settings.QUEUE_CLASS)
        q_info = queue_info.QueueInfo(settings.QUEUE_CONFIG, self, queue_class)
        queue_obj = q_info.get_queue(task_class.queue)

        if task_class.time_limit >= queue_obj.visibility_timeout_sec:
            raise exceptions.InvalidTimeLimitTaskException(
                'Invalid task time limit: %d >= %d from %s' % (
                    task_class.time_limit, queue_obj.visibility_timeout_sec,
                    settings.QUEUE_CONFIG))

        sqs_queue = self._get_or_create_queue(queue_obj.name)

        kale_msg = message.KaleMessage(
            task_class=task_class,
            task_id=task_id,
            payload=payload,
            current_retry_num=current_retry_num)

        # Updated Code Block
        #######################################################
        params = { "MessageBody": kale_msg.encode() }
        print(sqs_queue.attributes)

        if bool(sqs_queue.attributes['ContentBasedDeduplication']):
            params['MessageGroupId']=msg_group_id
        
        if not bool(sqs_queue.attributes['FifoQueue']):
            params['DelaySeconds']=delay_sec or 1

        sqs_queue.send_message(**params)
         #######################################################

        logger.debug('Published task. Task id: %s; Task name: %s' % (
            task_id, '%s.%s' % (task_class.__module__, task_class.__name__)))

from ndkale.

kyleaquino avatar kyleaquino commented on July 28, 2024

Hello @stlava @timnd @davidkern what do you think of this fix? is this okay?

from ndkale.

kyleaquino avatar kyleaquino commented on July 28, 2024

Made a PR: #51

from ndkale.

sabw8217 avatar sabw8217 commented on July 28, 2024

Is this still an issue? your fix looked basically OK to me, I think using .get() on the sqs_queue.attributes dict instead of indexing into it with [] to handle the possibility that attributes like FifoQueue aren't set (not sure if elasticmq sets that, for example) would be a good idea but otherwise this seems reasonable.

from ndkale.

kyleaquino avatar kyleaquino commented on July 28, 2024

@sabw8217 I closed this for now since i'm still testing this library for our application. I might encounter some other problems in future that is specific in our use case. Thank you for the response btw.

from ndkale.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.