本文整理汇总了Python中notification.models.ScheduledNotification.message方法的典型用法代码示例。如果您正苦于以下问题:Python ScheduledNotification.message方法的具体用法?Python ScheduledNotification.message怎么用?Python ScheduledNotification.message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类notification.models.ScheduledNotification
的用法示例。
在下文中一共展示了ScheduledNotification.message方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_notifications_for_user
# 需要导入模块: from notification.models import ScheduledNotification [as 别名]
# 或者: from notification.models.ScheduledNotification import message [as 别名]
def generate_notifications_for_user(incident, user, delay=None, preparedmsg = None):
now = timezone.make_aware(datetime.now(), timezone.get_current_timezone())
current_time = now
notifications = []
methods = user.notification_methods.order_by('position').all()
method_index = 0
for method in methods:
if delay is None:
notification_time = incident.service_key.retry * method_index + incident.service_key.escalate_after
else:
notification_time = method_index * delay
notify_at = current_time + timedelta(minutes=notification_time)
notification = ScheduledNotification()
notification.incident = incident
notification.user_to_notify = user
notification.notifier = method.method
notification.send_at = notify_at
if preparedmsg is None:
uri = settings.BASE_URL + "/incidents/details/" + str(incident.id)
notification.message = "A Service is experiencing a problem: " + incident.incident_key + " " + incident.description + ". Handle at: " + uri
else:
notification.message = preparedmsg
notifications.append(notification)
print "Notify %s at %s with method: %s" % (user.username, notify_at, notification.notifier)
method_index += 1
# todo: error handling
return notifications
示例2: generate_notifications_for_incident
# 需要导入模块: from notification.models import ScheduledNotification [as 别名]
# 或者: from notification.models.ScheduledNotification import message [as 别名]
def generate_notifications_for_incident(incident):
now = timezone.make_aware(datetime.now(), timezone.get_current_timezone())
duty_officers = get_escalation_for_service(incident.service_key)
current_time = now
notifications = []
for officer_index, duty_officer in enumerate(duty_officers):
escalation_time = incident.service_key.escalate_after * (officer_index + 1)
escalate_at = current_time + timedelta(minutes=escalation_time)
methods = duty_officer.notification_methods.all()
method_index = 0
for method in methods:
notification_time = incident.service_key.retry * method_index + incident.service_key.escalate_after * officer_index
notify_at = current_time + timedelta(minutes=notification_time)
if notify_at < escalate_at:
notification = ScheduledNotification()
notification.incident = incident
notification.user_to_notify = duty_officer
notification.notifier = method.method
notification.send_at = notify_at
uri = settings.BASE_URL + "/incidents/details/" + str(incident.id)
notification.message = "A Service is experiencing a problem: " + incident.incident_key + " " + incident.description + ". Handle at: " + uri
notifications.append(notification)
print "Notify %s at %s with method: %s" % (duty_officer.username, notify_at, notification.notifier)
else:
break
method_index += 1
# todo: error handling
return notifications