def send_optional_first_message(sender, instance, created, **kwargs): if created and settings.SUBSCRIPTION_SEND_INITIAL_DELAYED > 0: from subscription.tasks import processes_message api_client = sendHttpApiSender( account_key=settings.VUMI_GO_ACCOUNT_KEY, conversation_key=settings.VUMI_GO_CONVERSATION_KEY, conversation_token=settings.VUMI_GO_ACCOUNT_TOKEN ) processes_message.apply_async( args=[instance.id, api_client], countdown=settings.SUBSCRIPTION_SEND_INITIAL_DELAYED)
def process_message_queue(schedule, sender=None): # Get all active and incomplete subscriptions for schedule subscriptions = Subscription.objects.filter( schedule=schedule, active=True, completed=False, process_status=0).all() # Make a reusable session to Vumi if sender is None: sender = sendHttpApiSender( account_key=settings.VUMI_GO_ACCOUNT_KEY, conversation_key=settings.VUMI_GO_CONVERSATION_KEY, conversation_token=settings.VUMI_GO_ACCOUNT_TOKEN ) # sender = LoggingSender('go_http.test') # Fire off message processor for each for subscription in subscriptions: subscription.process_status = 1 # In Proceses subscription.save() processes_message.delay(subscription.id, sender) return subscriptions.count()