Пример #1
0
    def post(self):
        token = self.get_argument("deviceToken", "")
        categorys = self.get_argument("categorys", "").split(",")
        categorys = [c for c in categorys if c in consts.CATEGORYS]
        categorys = ",".join(categorys)
        locale = self.get_argument("locale", "en")
        if locale not in consts.LOCALES:
            locale = "en"

        if token:
            load_model("subscribers").subscribe(token, categorys, locale)
Пример #2
0
def status_notifciation(changed_status):
    notifications = {}
    for category, services in changed_status.iteritems():
        for name, st in services.iteritems():
            # just push notification about game server now
            if name == "GameServer":
                notifications[category] = st

    for category, st in notifications.iteritems():
        status = "Available" if st else "Unavailable"

        offset = 0
        limit = 200
        while True:
            subscribers = load_model("subscribers").get_subscribers(limit, offset)
            if not subscribers:
                break

            for subscribe in subscribers:
                if category in subscribe.categorys:
                    alert = _trans_alert("Diablo3 %s server status has changed to %s",
                                         category, status, subscribe.locale)
                    apns_tasks.apns_push_task.delay(subscribe.token, {},
                                                    alert=alert, badge=1,
                                                    sound="default")
            offset += len(subscribers)
Пример #3
0
def update_server_status():
    url = options.d3_server_status_url
    req = HTTPRequest(url=url)

    client = HTTPClient()
    response = client.fetch(req)
    if response.code == 200:
        status = _parse_server_status(response.body)
        changed_status = load_model("status").update_status(status)
        if changed_status:
            status_tasks.status_notification_task.delay(changed_status)
    else:
        err = "GET_D3_SERVER_STAUTS_ERROR: %s\n%s" (response.code, response)
        logging.error(err)

        # send email
        subject = "[%s]Get D3 server status error" % options.sitename
        body = err
        if options.send_error_email:
            send_email(options.email_from, options.admins, subject, body)
Пример #4
0
def update_server_status():
    url = options.d3_server_status_url
    req = HTTPRequest(url=url)

    client = HTTPClient()
    response = client.fetch(req)
    if response.code == 200:
        status = _parse_server_status(response.body)
        changed_status = load_model("status").update_status(status)
        if changed_status:
            status_tasks.status_notification_task.delay(changed_status)
    else:
        err = "GET_D3_SERVER_STAUTS_ERROR: %s\n%s" (response.code, response)
        logging.error(err)

        # send email
        subject = "[%s]Get D3 server status error" % options.sitename
        body = err
        if options.send_error_email:
            send_email(options.email_from, options.admins, subject, body)
Пример #5
0
 def post(self):
     token = self.get_argument("deviceToken", "")
     if token:
         load_model("subscribers").unsubscribe(token)
Пример #6
0
 def get(self):
     self.finish(load_model('status').get_status())