// This function will get triggered/executed when a new message is written // on an Azure Queue called queue. public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TraceWriter logger, [NotificationHub(TagExpression = "JobsSuccessful")] out Notification[] notifications) { notifications = default(Notification[]); try { if (string.IsNullOrEmpty(message)) { throw new ArgumentNullException(nameof(message)); } var notification = new WebJobHealthNotification() { Message = $"Job '{nameof(ProcessQueueMessage)}' has been completed without errors.", Status = WebJobHealthStatus.Success, Title = $"A Job has completed", }; notifications = GetPlatformNotifications(notification).ToArray(); } catch (Exception ex) { LogError(logger, nameof(ProcessQueueMessage), ex); } }
private static IEnumerable <Notification> GetPlatformNotifications(WebJobHealthNotification webJobHealthNotification) { yield return(new GcmNotification(webJobHealthNotification.ToGcmPayload())); //You could add notifications for other platforms: //yield return new MpnsNotification(webJobHealthNotification.ToWpToastPayload()); //yield return new MpnsNotification(webJobHealthNotification.ToWpTilePayload()); //yield return new MpnsNotification(webJobHealthNotification.ToWpSecondaryTilePayload()); }
public static string ToGcmPayload(this WebJobHealthNotification webJobHealthNotification) { var gcmPayloadModel = new GcmPayloadModel() { Data = new { Content = webJobHealthNotification } }; return(JsonConvert.SerializeObject(gcmPayloadModel)); }
/// <summary> /// Job triggered when an error is reported in other jobs. /// Called whenever 1 error occurs within a 1 minute sliding window (throttled at a maximum of 1 notification per 15 seconds). /// </summary> public static void GlobalErrorMonitorJob([ErrorTrigger("0:01:00", 1, Throttle = "0:00:15")] TraceFilter filter, TextWriter log, [NotificationHub(TagExpression = "JobsFailing")] out Notification[] notifications) { var notification = new WebJobHealthNotification() { Message = filter.GetDetailedMessage(1), Status = WebJobHealthStatus.Failure, Title = $"An error has been detected in a job", }; notifications = GetPlatformNotifications(notification).ToArray(); Console.Error.WriteLine("An error has been detected in a job."); log.WriteLine(filter.GetDetailedMessage(1)); }
private void SendNotification(WebJobHealthNotification webJobHealthNotification) { var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot); var notificationBuilder = new Notification.Builder(this) .SetSmallIcon(Resource.Drawable.Icon) .SetContentTitle(webJobHealthNotification.Title) .SetContentText(webJobHealthNotification.Message) .SetAutoCancel(true) .SetContentIntent(pendingIntent) .SetStyle(new Notification.BigTextStyle().BigText(webJobHealthNotification.Message)); var notificationManager = NotificationManager.FromContext(this); notificationManager.Notify(0, notificationBuilder.Build()); }