Ejemplo n.º 1
0
	def setUp(self):
		alert = APNSAlert(body="alerttest1",has_data=False)
		alert.save()
		apspayload = APNSAPSPayload(payload_ref="apstest1",alert=alert)
		apspayload.save()
		msg = APNSMessage(message_ref="testmsg1",aps_payload=apspayload,has_data=False)
		msg.save()

		token = APNSToken(token="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",expired=False)
		token.save()

		msgq = MsgQueue(apnstoken=token,apnsmessage=msg,msg_sent=False)
		msgq.save()
Ejemplo n.º 2
0
    def setUp(self):
        alert = APNSAlert(body="alerttest1", has_data=False)
        alert.save()
        apspayload = APNSAPSPayload(payload_ref="apstest1", alert=alert)
        apspayload.save()
        msg = APNSMessage(message_ref="testmsg1",
                          aps_payload=apspayload,
                          has_data=False)
        msg.save()

        token = APNSToken(
            token=
            "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
            expired=False)
        token.save()

        msgq = MsgQueue(apnstoken=token, apnsmessage=msg, msg_sent=False)
        msgq.save()
Ejemplo n.º 3
0
	def push_to_all(self, request, queryset):
		tokenlist = APNSToken.objects.all().filter(expired=False)

		with transaction.commit_on_success():
			tasklist=[]
			for msg in queryset:
				for token in tokenlist:
					# Add to Msg queue
					entry = MsgQueue(apnstoken=token,apnsmessage=msg)
					entry.save()
					# Add to PreTaskQueue

					ptentry = PreTaskQueue(packet=binascii.hexlify(entry.to_packet()),msgidentifier=entry.id,pickedup=True)
					ptentry.save()
					tasklist.append((entry.to_packet(),ptentry.id,None))

			# Add to Task Queue by mapping tasks together. Celery executes mapped tasks sequentially with the same worker.
			if tasklist:
				# Mark the last packet in the queue
				packet,ptentry,islastpacket = tasklist[-1] 
				tasklist[-1] = packet,ptentry,True
				
			tasks.pushapnspacket.map(tasklist).delay()

			self.message_user(request, "%s message(s) to %s token(s) successfully added to MsgQueue." % (len(queryset) , len(tokenlist)))