コード例 #1
0
def replication_status(request: HttpRequest) -> HttpResponse:
    statuses = get_replication_statuses()
    return render(
        request,
        "replication_status.html",
        {
            "private": True,
            "statuses": statuses
        },
    )
コード例 #2
0
    def handle(self, *args, **options):
        super(Command, self).handle(*args, **options)

        bad_slots = []
        statuses = get_replication_statuses()
        for server_name, rows in statuses.items():
            for row in rows:
                if row["lsn_distance"] > settings.MAX_REPLICATION_LAG:
                    bad_slots.append(
                        "Slot '%s' on '%s' is lagging by %s bytes." %
                        (row["slot_name"], server_name, row["lsn_distance"]))

        if bad_slots:
            subject = f"Replication is lagging on {len(bad_slots)} slots"
            template = loader.get_template("emails/replication_lag_email.txt")
            send_mail(
                subject=subject,
                message=template.render({"bad_slots": bad_slots}),
                from_email=settings.DEFAULT_FROM_EMAIL,
                recipient_list=[admin[1] for admin in settings.MANAGERS],
            )