2018-11-08 19:45:21 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
|
|
from peeringdb_server import models
|
|
|
|
|
from peeringdb_server.deskpro import APIClient, APIError
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
|
help = "Process deskpro ticket queue"
|
|
|
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def log(self, msg):
|
|
|
|
|
print(msg)
|
|
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
|
client = APIClient(settings.DESKPRO_URL, settings.DESKPRO_KEY)
|
2020-01-08 13:29:58 -06:00
|
|
|
self.log("DESKPRO: {}".format(settings.DESKPRO_URL))
|
2018-11-08 19:45:21 +00:00
|
|
|
ticket_qs = models.DeskProTicket.objects.filter(
|
2019-12-05 16:57:52 +00:00
|
|
|
published__isnull=True
|
|
|
|
|
).order_by("created")
|
2018-11-08 19:45:21 +00:00
|
|
|
|
|
|
|
|
if not ticket_qs.count():
|
|
|
|
|
self.log("No tickets in queue")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
for ticket in ticket_qs[:10]:
|
2020-01-08 13:29:58 -06:00
|
|
|
self.log("Posting to Deskpro: #{}".format(ticket.id))
|
2018-11-08 19:45:21 +00:00
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
client.create_ticket(ticket)
|
2019-12-05 16:57:52 +00:00
|
|
|
ticket.published = datetime.datetime.now().replace(tzinfo=models.UTC())
|
2018-11-08 19:45:21 +00:00
|
|
|
ticket.save()
|
|
|
|
|
except APIError as exc:
|
|
|
|
|
self.log(
|
2020-01-08 13:29:58 -06:00
|
|
|
"!!!! Could not create ticket #{} - error data has been attached to ticket body.".format(
|
2019-12-05 16:57:52 +00:00
|
|
|
ticket.id
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
ticket.published = datetime.datetime.now().replace(tzinfo=models.UTC())
|
2020-01-08 13:29:58 -06:00
|
|
|
ticket.subject = "[FAILED] {}".format(ticket.subject)
|
|
|
|
|
ticket.body = "{}\nAPI Delivery Error: {}".format(ticket.body, exc.data)
|
2018-11-08 19:45:21 +00:00
|
|
|
ticket.save()
|