1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00
Files
peeringdb-peeringdb/peeringdb_server/management/commands/pdb_deskpro_publish.py

52 lines
1.6 KiB
Python
Raw Normal View History

2018-11-08 19:45:21 +00:00
#!/usr/bin/env python
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)
self.log(f"DESKPRO: {settings.DESKPRO_URL}")
# Per issue #858 we want to ignore the IX-F tickets
ticket_qs = (
models.DeskProTicket.objects.filter(published__isnull=True)
.exclude(subject__icontains="[IX-F]")
.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]:
self.log(f"Posting to Deskpro: #{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(
"!!!! 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())
ticket.subject = f"[FAILED] {ticket.subject}"
ticket.body = f"{ticket.body}\nAPI Delivery Error: {exc.data}"
2018-11-08 19:45:21 +00:00
ticket.save()