Hello,


I am using django 1.3, together with djcelery 2.3.3 and rabbitmq.


When I create a task via one specific post_save signal, the 
get_basecamp_account.delay() task gets added twice to the queue.


I have checked, the post save signal got only called once. The signal is 
executed once, the logger statements just before method.delay(object) and 
after it are getting logged just once. But celeryd says, that it received 
two tasks (with different ids). Which results in duplicate new objects in 
the database.


This is the signal, which calls the task:

def get_basecamp_account_details(sender, instance, **kwargs):

    """

    Retrieves account details for a basecamp account

    Depending on the parameter

      ``created``

    """

    account = instance

    # Set created to True in case we don't get this keyword.

    # If created is to True, a new object will be created in basecamp

    created = kwargs.get('created', True)

    logger.info('Ready to process sender: %s with id %s' % (sender, 
account.id))

    # write to the queue only if there is no basecamp_id or if there was an

    # error previously writing to the queue (indicated with id 0)

    if (created == True or not account.basecamp) and notaccount.skip_update:

        try:

            logger.debug('READY TO CREATE TASK FOR CREATING AN ACCOUNT 
###########################################################')

            logger.debug('Called delay() and got this id %s' % 
get_basecamp_account.delay(account))

            logger.info('Sender "%s" with id "%s" added to the queue.' % 
(sender, account.id))

        except:

            logger.exception('Unknown Error for sender "%s with id "%d"' % 
(sender, instance.id))

        

    elif account.shall_update:

        # shall_update is a property, which is not included in the initial 
model

        # this property is added in a pre_save signal and idicates if an 
object

        # shall be updated on basecamp or not

        # we need a period x seconds between the last update to avoid 
bursting the

        # basecamp api

        # the seconds are set in the settings.py, parameter UPDATE_DELAY

        logger.debug('going to update instance basecamp id: %s' % 
account.basecamp_id)

        try:

            logger.error('Please implement me: update function for %s' % 
__name__)

        except:

            logger.exception('Unhandled Exception')

            raise

    else:

        logger.info('the account %s was updated within the last %d seconds, 
doing nothing' % (account.id,

                                                                             
                  settings.UPDATE_DELAY))

    logger.debug('done with method %s' % __name__)    

    retur
  

  
 
 
  Just some more details. This is the output I get when I add 
pdb.set_trace() just before I call delay (or apply_async)


> 
/Users/Tom/src/agileamp/scrumtool/scrumtool/accounts/signals.py(30)get_basecamp_account_details()

-> get_basecamp_account.apply_async([account])

(Pdb) n

> 
/Users/Tom/src/agileamp/scrumtool/scrumtool/accounts/signals.py(31)get_basecamp_account_details()

-> logger.info('Sender "%(sender)s" with id "%(id)s" added to the queue.' % 
{'sender': sender,

(Pdb) n

> 
/Users/Tom/src/agileamp/scrumtool/scrumtool/accounts/signals.py(32)get_basecamp_account_details()

-> 'id': account.id})

(Pdb) n

> 
/Users/Tom/src/agileamp/scrumtool/scrumtool/accounts/signals.py(52)get_basecamp_account_details()

-> return

(Pdb) n

--Return--

> 
/Users/Tom/src/agileamp/scrumtool/scrumtool/accounts/signals.py(52)get_basecamp_account_details()->None

-> return

(Pdb) n

> 
/Users/Tom/src/agileamp/scrumtool/lib/python/django/dispatch/dispatcher.py(173)send()

-> responses.append((receiver, response))

(Pdb) n

> 
/Users/Tom/src/agileamp/scrumtool/lib/python/django/dispatch/dispatcher.py(171)send()

-> for receiver in self._live_receivers(_make_id(sender)):

(Pdb) n

> 
/Users/Tom/src/agileamp/scrumtool/lib/python/django/dispatch/dispatcher.py(172)send()

-> response = receiver(signal=self, sender=sender, **named)

(Pdb) n

> 
/Users/Tom/src/agileamp/scrumtool/scrumtool/accounts/signals.py(30)get_basecamp_account_details()

-> get_basecamp_account.apply_async([account])



Any help is very much appreciated.


regards, tom


  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/aZiESsqHDXAJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to