From ab21aefd21e479c7b098e0adc5b10475c2c17579 Mon Sep 17 00:00:00 2001 From: Eli Jones Date: Mon, 29 Apr 2024 12:18:36 -0400 Subject: [PATCH] [2.5.1] removes spam from BeiweBackgroundTasks, updates non fatal sentry reports to say they are non-fatal. --- Beiwe/BeiweBackgroundTasks.swift | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/Beiwe/BeiweBackgroundTasks.swift b/Beiwe/BeiweBackgroundTasks.swift index 71b9105..c6000dd 100644 --- a/Beiwe/BeiweBackgroundTasks.swift +++ b/Beiwe/BeiweBackgroundTasks.swift @@ -1,8 +1,11 @@ import BackgroundTasks import Sentry +/// This file is under active development and is not documented. Once we work better code for this +/// background process management we can document. + func scheduleRefreshHeartbeat() { - print("scheduling refresh heartbeat") + // print("scheduling refresh heartbeat") let request = BGAppRefreshTaskRequest(identifier: BACKGROUND_TASK_NAME_HEARTBEAT_BGREFRESH) request.earliestBeginDate = Date(timeIntervalSinceNow: 10) do { @@ -12,7 +15,7 @@ func scheduleRefreshHeartbeat() { if let sentry_client = Client.shared { sentry_client.snapshotStacktrace { let event = Event(level: .error) - event.message = "scheduling refresh heartbeat: \(error)" + event.message = "not a crash - scheduling refresh heartbeat: \(error)" event.environment = Constants.APP_INFO_TAG sentry_client.appendStacktrace(to: event) sentry_client.send(event: event) @@ -22,7 +25,7 @@ func scheduleRefreshHeartbeat() { } func scheduleProcessingHeartbeat() { - print("scheduling processing heartbeat") + // print("scheduling processing heartbeat") let request = BGProcessingTaskRequest(identifier: BACKGROUND_TASK_NAME_HEARTBEAT_BGPROCESSING) request.earliestBeginDate = Date(timeIntervalSinceNow: 10) request.requiresExternalPower = false @@ -34,7 +37,7 @@ func scheduleProcessingHeartbeat() { if let sentry_client = Client.shared { sentry_client.snapshotStacktrace { let event = Event(level: .error) - event.message = "scheduling processing heartbeat: \(error)" + event.message = "not a crash - scheduling processing heartbeat: \(error)" event.environment = Constants.APP_INFO_TAG sentry_client.appendStacktrace(to: event) sentry_client.send(event: event) @@ -45,7 +48,7 @@ func scheduleProcessingHeartbeat() { @available(iOS 17.0, *) func scheduleHealthHeartbeat() { - print("scheduling health heartbeat") + // print("scheduling health heartbeat") let request = BGHealthResearchTaskRequest(identifier: BACKGROUND_TASK_NAME_HEARTBEAT_BGHEALTH) request.earliestBeginDate = Date(timeIntervalSinceNow: 10) request.requiresExternalPower = false @@ -58,7 +61,7 @@ func scheduleHealthHeartbeat() { if let sentry_client = Client.shared { sentry_client.snapshotStacktrace { let event = Event(level: .error) - event.message = "scheduling health heartbeat: \(error)" + event.message = "not a crash - scheduling health heartbeat: \(error)" event.environment = Constants.APP_INFO_TAG sentry_client.appendStacktrace(to: event) sentry_client.send(event: event) @@ -83,20 +86,20 @@ func updateBackgroundTasksCount() { print("There are \(taskRequests.count) BGTaskRequests outstanding right now:") for request in taskRequests { if let refresh_task_request = request as? BGAppRefreshTaskRequest { - print("\t BGAppRefreshTaskRequest - ", request.identifier, request.earliestBeginDate!) + // print("\t BGAppRefreshTaskRequest - ", request.identifier, request.earliestBeginDate!) info.append("BGAppRefreshTaskRequest \(request.identifier):\(request.earliestBeginDate!)") } if let processing_task_request = request as? BGProcessingTaskRequest { - print("\t BGProcessingTaskRequest - ", request.identifier, request.earliestBeginDate!, - "external power:", processing_task_request.requiresExternalPower, - "requires network:", processing_task_request.requiresNetworkConnectivity) + // print("\t BGProcessingTaskRequest - ", request.identifier, request.earliestBeginDate!, + // "external power:", processing_task_request.requiresExternalPower, + // "requires network:", processing_task_request.requiresNetworkConnectivity) info.append("BGProcessingTaskRequest \(request.identifier):\(request.earliestBeginDate!)") } // the background health tasks DO NOT SHOW UP. This is not a version-gating bug, I tested it THOROUGHLY, // it's either another bug or they are hidden and are not visible to the getPendingTaskRequests function. if #available(iOS 17.0, *) { if let health_task_request = request as? BGHealthResearchTaskRequest { - print("\t BGHealthResearchTaskRequest - ", request.identifier, request.earliestBeginDate!) + // print("\t BGHealthResearchTaskRequest - ", request.identifier, request.earliestBeginDate!) info.append("BGHealthResearchTaskRequest \(request.identifier):\(request.earliestBeginDate!)") } } @@ -107,20 +110,20 @@ func updateBackgroundTasksCount() { } func handleHeartbeatRefresh(task: BGAppRefreshTask) { - print("BGAppRefreshTask - the handler is getting called \(dateFormatLocal(Date()))") + // print("BGAppRefreshTask - the handler is getting called \(dateFormatLocal(Date()))") StudyManager.sharedInstance.heartbeat("BGAppRefreshTask - \(Ephemerals.background_task_count)") scheduleRefreshHeartbeat() } func handleHeartbeatProcessing(task: BGProcessingTask) { - print("BGProcessingTask - the handler is getting called \(dateFormatLocal(Date()))") + // print("BGProcessingTask - the handler is getting called \(dateFormatLocal(Date()))") StudyManager.sharedInstance.heartbeat("BGProcessingTask - \(Ephemerals.background_task_count)") scheduleProcessingHeartbeat() } @available(iOS 17.0, *) func handleHeartbeatHealth(task: BGHealthResearchTask) { - print("BGHealthResearchTask - the handler is getting called \(dateFormatLocal(Date()))") + // print("BGHealthResearchTask - the handler is getting called \(dateFormatLocal(Date()))") StudyManager.sharedInstance.heartbeat("BGHealthResearchTask - \(Ephemerals.background_task_count)") scheduleHealthHeartbeat() }