mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-29 08:42:51 +00:00
Add additional activity reporting.
This commit is contained in:
1 parent
0dda4aae0a
commit
69cd3ec768
9 files changed
+113
-4
No files matched your search
@@ -11,6 +11,7 @@ import UserNotifications
|
||||
import os
|
||||
import Articles
|
||||
import Account
|
||||
import ActivityLog
|
||||
import ErrorLog
|
||||
import RSCore
|
||||
import RSCoreObjC
|
||||
@@ -861,6 +862,8 @@ extension AppDelegate {
|
||||
func saveState() {
|
||||
mainWindowController?.saveStateToUserDefaults()
|
||||
inspectorWindowController?.saveState()
|
||||
activityWindowController?.saveState()
|
||||
activityLogWindowController?.saveState()
|
||||
errorLogWindowController?.saveState()
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ let package = Package(
|
||||
targets: ["Account"])
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "../ActivityLog"),
|
||||
.package(path: "../Articles"),
|
||||
.package(path: "../ArticlesDatabase"),
|
||||
.package(path: "../CloudKitSync"),
|
||||
@@ -32,6 +33,7 @@ let package = Package(
|
||||
"RSDatabase",
|
||||
"RSParser",
|
||||
"RSWeb",
|
||||
"ActivityLog",
|
||||
"Articles",
|
||||
"ArticlesDatabase",
|
||||
"CloudKitSync",
|
||||
|
||||
@@ -11,6 +11,7 @@ import CloudKit
|
||||
import ErrorLog
|
||||
import SystemConfiguration
|
||||
import os
|
||||
import ActivityLog
|
||||
import RSCore
|
||||
import RSParser
|
||||
import RSWeb
|
||||
@@ -104,7 +105,7 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable {
|
||||
func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable: Any]) async {
|
||||
Self.logger.debug("CloudKitAccountDelegate: \(#function, privacy: .public)")
|
||||
await withCheckedContinuation { continuation in
|
||||
let op = CloudKitRemoteNotificationOperation(accountZone: accountZone, articlesZone: articlesZone, userInfo: userInfo)
|
||||
let op = CloudKitRemoteNotificationOperation(accountZone: accountZone, articlesZone: articlesZone, accountID: account.accountID, userInfo: userInfo)
|
||||
op.completionBlock = { _ in
|
||||
Self.logger.debug("CloudKitAccountDelegate: \(#function, privacy: .public) did complete")
|
||||
continuation.resume()
|
||||
@@ -146,7 +147,7 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable {
|
||||
func refreshArticleStatus(for account: Account) async throws {
|
||||
Self.logger.debug("CloudKitAccountDelegate: \(#function, privacy: .public)")
|
||||
return try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
|
||||
let op = CloudKitReceiveStatusOperation(articlesZone: articlesZone)
|
||||
let op = CloudKitReceiveStatusOperation(articlesZone: articlesZone, accountID: account.accountID)
|
||||
op.completionBlock = { mainThreadOperation in
|
||||
Self.logger.debug("CloudKitAccountDelegate: \(#function, privacy: .public) did complete")
|
||||
if mainThreadOperation.isCanceled {
|
||||
@@ -579,10 +580,18 @@ private extension CloudKitAccountDelegate {
|
||||
|
||||
syncProgress.addTasks(3)
|
||||
|
||||
let activityLog = ActivityLog.shared
|
||||
let owner = ActivityOwner.account(account.accountID)
|
||||
let fetchChangesTaskNumber = activityLog.nextTaskNumberString()
|
||||
let fetchChangesID = activityLog.createActivity(owner: owner, kind: .refreshFeedList, detail: "Fetching account zone changes \(fetchChangesTaskNumber)")
|
||||
activityLog.didStart(id: fetchChangesID)
|
||||
|
||||
do {
|
||||
try await accountZone.fetchChangesInZone()
|
||||
activityLog.didComplete(id: fetchChangesID)
|
||||
syncProgress.completeTask()
|
||||
} catch {
|
||||
activityLog.didFail(id: fetchChangesID, error: error)
|
||||
if case CloudKitZoneError.userDeletedZone = error {
|
||||
account.removeFeedsFromTreeAtTopLevel(account.topLevelFeeds)
|
||||
for folder in account.folders ?? Set<Folder>() {
|
||||
@@ -605,6 +614,7 @@ private extension CloudKitAccountDelegate {
|
||||
throw error
|
||||
}
|
||||
|
||||
refresher.accountID = account.accountID
|
||||
await refresher.refreshFeeds(feeds)
|
||||
|
||||
if sendArticleStatus {
|
||||
|
||||
@@ -10,13 +10,16 @@ import Foundation
|
||||
import os
|
||||
import RSCore
|
||||
import CloudKitSync
|
||||
import ActivityLog
|
||||
|
||||
final class CloudKitReceiveStatusOperation: MainThreadOperation, @unchecked Sendable {
|
||||
private weak var articlesZone: CloudKitArticlesZone?
|
||||
private let accountID: String
|
||||
private static let logger = cloudKitLogger
|
||||
|
||||
init(articlesZone: CloudKitArticlesZone) {
|
||||
init(articlesZone: CloudKitArticlesZone, accountID: String) {
|
||||
self.articlesZone = articlesZone
|
||||
self.accountID = accountID
|
||||
super.init(name: "CloudKitReceiveStatusOperation")
|
||||
}
|
||||
|
||||
@@ -31,12 +34,19 @@ final class CloudKitReceiveStatusOperation: MainThreadOperation, @unchecked Send
|
||||
self.didComplete()
|
||||
}
|
||||
|
||||
let activityLog = ActivityLog.shared
|
||||
let taskNumber = activityLog.nextTaskNumberString()
|
||||
let activityID = activityLog.createActivity(owner: .account(accountID), kind: .refreshArticleStatuses, detail: "Receiving article statuses \(taskNumber)")
|
||||
activityLog.didStart(id: activityID)
|
||||
|
||||
Self.logger.debug("iCloud: Refreshing article statuses")
|
||||
do {
|
||||
try await articlesZone.refreshArticles()
|
||||
Self.logger.debug("iCloud: Finished refreshing article statuses")
|
||||
activityLog.didComplete(id: activityID)
|
||||
} catch {
|
||||
Self.logger.error("iCloud: Receive status error: \(error.localizedDescription)")
|
||||
activityLog.didFail(id: activityID, error: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,16 +10,19 @@ import Foundation
|
||||
import os
|
||||
import RSCore
|
||||
import CloudKitSync
|
||||
import ActivityLog
|
||||
|
||||
@MainActor final class CloudKitRemoteNotificationOperation: MainThreadOperation, @unchecked Sendable {
|
||||
private weak var accountZone: CloudKitAccountZone?
|
||||
private weak var articlesZone: CloudKitArticlesZone?
|
||||
private let accountID: String
|
||||
nonisolated(unsafe) private var userInfo: [AnyHashable: Any]
|
||||
private static let logger = cloudKitLogger
|
||||
|
||||
init(accountZone: CloudKitAccountZone, articlesZone: CloudKitArticlesZone, userInfo: [AnyHashable: Any]) {
|
||||
init(accountZone: CloudKitAccountZone, articlesZone: CloudKitArticlesZone, accountID: String, userInfo: [AnyHashable: Any]) {
|
||||
self.accountZone = accountZone
|
||||
self.articlesZone = articlesZone
|
||||
self.accountID = accountID
|
||||
self.userInfo = userInfo
|
||||
super.init(name: "CloudKitRemoteNotificationOperation")
|
||||
}
|
||||
@@ -31,9 +34,21 @@ import CloudKitSync
|
||||
}
|
||||
|
||||
Task { @MainActor in
|
||||
let activityLog = ActivityLog.shared
|
||||
let owner = ActivityOwner.account(accountID)
|
||||
let taskNumber = activityLog.nextTaskNumberString()
|
||||
|
||||
let accountZoneActivityID = activityLog.createActivity(owner: owner, kind: .refreshFeedList, detail: "Receiving account changes \(taskNumber)")
|
||||
activityLog.didStart(id: accountZoneActivityID)
|
||||
|
||||
Self.logger.debug("iCloud: Processing remote notification")
|
||||
await accountZone.receiveRemoteNotification(userInfo: userInfo)
|
||||
activityLog.didComplete(id: accountZoneActivityID)
|
||||
|
||||
let articlesZoneActivityID = activityLog.createActivity(owner: owner, kind: .refreshArticleStatuses, detail: "Receiving article changes \(taskNumber)")
|
||||
activityLog.didStart(id: articlesZoneActivityID)
|
||||
await articlesZone.receiveRemoteNotification(userInfo: self.userInfo)
|
||||
activityLog.didComplete(id: articlesZoneActivityID)
|
||||
|
||||
Self.logger.debug("iCloud: Finished processing remote notification")
|
||||
didComplete()
|
||||
|
||||
@@ -13,11 +13,13 @@ import RSCore
|
||||
import RSWeb
|
||||
import SyncDatabase
|
||||
import CloudKitSync
|
||||
import ActivityLog
|
||||
|
||||
final class CloudKitSendStatusOperation: MainThreadOperation, @unchecked Sendable {
|
||||
private let blockSize = 150
|
||||
private weak var account: Account?
|
||||
private weak var articlesZone: CloudKitArticlesZone?
|
||||
private let accountID: String
|
||||
private var syncDatabase: SyncDatabase
|
||||
private let syncArticleContentForUnreadArticles: @Sendable () -> Bool
|
||||
private static let logger = cloudKitLogger
|
||||
@@ -25,6 +27,7 @@ final class CloudKitSendStatusOperation: MainThreadOperation, @unchecked Sendabl
|
||||
|
||||
init(account: Account, articlesZone: CloudKitArticlesZone, database: SyncDatabase, syncArticleContentForUnreadArticles: @escaping @Sendable () -> Bool, syncErrorHandler: CloudKitSyncErrorHandler?) {
|
||||
self.account = account
|
||||
self.accountID = account.accountID
|
||||
self.articlesZone = articlesZone
|
||||
self.syncDatabase = database
|
||||
self.syncArticleContentForUnreadArticles = syncArticleContentForUnreadArticles
|
||||
@@ -35,9 +38,15 @@ final class CloudKitSendStatusOperation: MainThreadOperation, @unchecked Sendabl
|
||||
@MainActor override func run() {
|
||||
Self.logger.debug("iCloud: Sending article statuses")
|
||||
|
||||
let activityLog = ActivityLog.shared
|
||||
let taskNumber = activityLog.nextTaskNumberString()
|
||||
let activityID = activityLog.createActivity(owner: .account(accountID), kind: .sendArticleStatuses, detail: "Sending article statuses \(taskNumber)")
|
||||
activityLog.didStart(id: activityID)
|
||||
|
||||
Task { @MainActor in
|
||||
await selectForProcessing()
|
||||
Self.logger.debug("iCloud: Finished sending article statuses")
|
||||
activityLog.didComplete(id: activityID)
|
||||
didComplete()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ import Secrets
|
||||
}
|
||||
|
||||
let feeds = account.flattenedFeeds()
|
||||
refresher.accountID = account.accountID
|
||||
await refresher.refreshFeeds(feeds)
|
||||
account.lastRefreshCompletedDate = Date()
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import RSParser
|
||||
import RSWeb
|
||||
import Articles
|
||||
import ArticlesDatabase
|
||||
import ActivityLog
|
||||
import os
|
||||
|
||||
@MainActor protocol LocalAccountRefresherDelegate {
|
||||
@@ -30,6 +31,12 @@ import os
|
||||
}
|
||||
}
|
||||
|
||||
/// Settable by the caller (LocalAccountDelegate / CloudKitAccountDelegate) so
|
||||
/// per-refresh activities can be scoped to the right account.
|
||||
var accountID: String?
|
||||
|
||||
private var refreshActivityID: Int?
|
||||
|
||||
private var completion: (() -> Void)?
|
||||
private var isSuspended = false
|
||||
|
||||
@@ -69,12 +76,32 @@ import os
|
||||
urlToFeedDictionary[feed.url] = feed
|
||||
}
|
||||
|
||||
// Track the overall refresh and create one pending activity per feed.
|
||||
// Each feed's activity is completed (or failed) in the DownloadSessionDelegate
|
||||
// callbacks below. `didComplete` is pending-tolerant, so feeds that never
|
||||
// reach `didStart` still get cleaned up.
|
||||
if let owner = activityOwner {
|
||||
let activityLog = ActivityLog.shared
|
||||
refreshActivityID = activityLog.createActivity(owner: owner, kind: .refreshAll)
|
||||
activityLog.didStart(id: refreshActivityID!)
|
||||
for feed in filteredFeeds {
|
||||
activityLog.createActivity(owner: owner, kind: .refreshFeedContent(feedURL: feed.url), detail: feed.nameForDisplay)
|
||||
}
|
||||
}
|
||||
|
||||
let urls = filteredFeeds.compactMap { Self.url(for: $0) }
|
||||
|
||||
self.completion = completion
|
||||
downloadSession.download(Set(urls))
|
||||
}
|
||||
|
||||
private var activityOwner: ActivityOwner? {
|
||||
guard let accountID else {
|
||||
return nil
|
||||
}
|
||||
return .account(accountID)
|
||||
}
|
||||
|
||||
@MainActor public func suspend() {
|
||||
downloadSession.cancelAll()
|
||||
isSuspended = true
|
||||
@@ -132,6 +159,16 @@ import os
|
||||
}
|
||||
feed.lastCheckDate = Date()
|
||||
|
||||
// Every exit from this method represents a per-feed completion (success
|
||||
// or harmless skip — actual HTTP failures land in httpError below).
|
||||
let activityOwner = self.activityOwner
|
||||
let activityKind = ActivityKind.refreshFeedContent(feedURL: feed.url)
|
||||
defer {
|
||||
if let activityOwner {
|
||||
ActivityLog.shared.didComplete(activityOwner, kind: activityKind)
|
||||
}
|
||||
}
|
||||
|
||||
guard error == nil else {
|
||||
return
|
||||
}
|
||||
@@ -210,6 +247,10 @@ import os
|
||||
let errorMessage = "HTTP \(statusCode) \(statusDescription): \(url.absoluteString)"
|
||||
let error = NSError(domain: "NetNewsWire", code: statusCode, userInfo: [NSLocalizedDescriptionKey: errorMessage])
|
||||
|
||||
if let owner = activityOwner {
|
||||
ActivityLog.shared.didFail(owner, kind: .refreshFeedContent(feedURL: feed.url), error: error)
|
||||
}
|
||||
|
||||
let errorLogUserInfo = ErrorLogUserInfoKey.userInfo(sourceName: account.nameForDisplay, sourceID: account.type.rawValue, operation: "Downloading feed", errorMessage: AccountError.detailedErrorMessage(error))
|
||||
NotificationCenter.default.post(name: .appDidEncounterError, object: self, userInfo: errorLogUserInfo)
|
||||
}
|
||||
@@ -224,6 +265,11 @@ import os
|
||||
|
||||
func downloadSessionDidComplete(_ downloadSession: DownloadSession) {
|
||||
|
||||
if let refreshActivityID {
|
||||
ActivityLog.shared.didComplete(id: refreshActivityID)
|
||||
self.refreshActivityID = nil
|
||||
}
|
||||
|
||||
Task { @MainActor in
|
||||
completion?()
|
||||
completion = nil
|
||||
|
||||
@@ -8,10 +8,12 @@
|
||||
|
||||
import Foundation
|
||||
import Account
|
||||
import ActivityLog
|
||||
|
||||
@MainActor final class AccountRefreshTimer {
|
||||
|
||||
var shuttingDown = false
|
||||
var isSystemSleeping = false
|
||||
|
||||
private var internalTimer: Timer?
|
||||
private var lastTimedRefresh: Date?
|
||||
@@ -89,6 +91,17 @@ import Account
|
||||
return
|
||||
}
|
||||
|
||||
if isSystemSleeping {
|
||||
let activityLog = ActivityLog.shared
|
||||
let id = activityLog.createActivity(owner: .app, kind: .refreshAll)
|
||||
activityLog.didStart(id: id)
|
||||
activityLog.didComplete(id: id, message: "Skipped — computer is asleep", durationIsSignificant: false)
|
||||
|
||||
lastTimedRefresh = Date()
|
||||
update()
|
||||
return
|
||||
}
|
||||
|
||||
lastTimedRefresh = Date()
|
||||
update()
|
||||
|
||||
|
||||
Reference in new issue
Block a user