mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-01 01:40:22 +00:00
Add activity reporting to Feedly operations.
This commit is contained in:
1 parent
d889b7c18d
commit
a0359f17fa
10 files changed
+82
-1
No files matched your search
+1
@@ -33,6 +33,7 @@ final class FeedlyDownloadArticlesOperation: FeedlyOperation {
|
||||
}
|
||||
|
||||
override func run() {
|
||||
startActivityIfNeeded()
|
||||
var articleIds = missingArticleEntryIdProvider.entryIDs
|
||||
articleIds.formUnion(updatedArticleEntryIdProvider.entryIDs)
|
||||
|
||||
|
||||
+1
@@ -20,6 +20,7 @@ final class FeedlyFetchIdsForMissingArticlesOperation: FeedlyOperation, FeedlyEn
|
||||
}
|
||||
|
||||
override func run() {
|
||||
startActivityIfNeeded()
|
||||
Task {
|
||||
do {
|
||||
let articleIDs = try await account.fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDateAsync()
|
||||
|
||||
@@ -26,6 +26,7 @@ final class FeedlyGetCollectionsOperation: FeedlyOperation, FeedlyCollectionProv
|
||||
|
||||
override func run() {
|
||||
Feedly.logger.info("Feedly: Requesting collections")
|
||||
startActivityIfNeeded()
|
||||
|
||||
service.getCollections { result in
|
||||
Task { @MainActor in
|
||||
|
||||
+1
@@ -40,6 +40,7 @@ final class FeedlyGetUpdatedArticleIdsOperation: FeedlyOperation, FeedlyEntryIde
|
||||
private var storedUpdatedArticleIds = Set<String>()
|
||||
|
||||
override func run() {
|
||||
startActivityIfNeeded()
|
||||
getStreamIds(nil)
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -38,6 +38,7 @@ final class FeedlyIngestStarredArticleIdsOperation: FeedlyOperation {
|
||||
}
|
||||
|
||||
override func run() {
|
||||
startActivityIfNeeded()
|
||||
getStreamIds(nil)
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -33,6 +33,7 @@ final class FeedlyIngestStreamArticleIdsOperation: FeedlyOperation {
|
||||
}
|
||||
|
||||
override func run() {
|
||||
startActivityIfNeeded()
|
||||
getStreamIds(nil)
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -39,6 +39,7 @@ final class FeedlyIngestUnreadArticleIdsOperation: FeedlyOperation {
|
||||
}
|
||||
|
||||
override func run() {
|
||||
startActivityIfNeeded()
|
||||
getStreamIds(nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ActivityLog
|
||||
import RSWeb
|
||||
import RSCore
|
||||
|
||||
@@ -28,6 +29,14 @@ protocol FeedlyOperationDelegate: AnyObject {
|
||||
}
|
||||
}
|
||||
|
||||
/// Set these before adding the op to its queue to have it report an
|
||||
/// Activity Log entry — started on `run()`, completed in `didFinish()`,
|
||||
/// failed in `didFinish(with:)`.
|
||||
var activityKind: ActivityKind?
|
||||
var activityDetail: String?
|
||||
var activityAccountID: String?
|
||||
private var activityID: Int?
|
||||
|
||||
// FeedlyMainThreadOperation
|
||||
public var isCanceled = false {
|
||||
didSet {
|
||||
@@ -44,7 +53,20 @@ protocol FeedlyOperationDelegate: AnyObject {
|
||||
public func run() {
|
||||
}
|
||||
|
||||
/// Starts the configured activity (if any). Subclasses call this at the
|
||||
/// top of their `run()` override.
|
||||
func startActivityIfNeeded() {
|
||||
guard activityID == nil, let kind = activityKind, let accountID = activityAccountID else {
|
||||
return
|
||||
}
|
||||
let log = ActivityLog.shared
|
||||
let id = log.createActivity(owner: .account(accountID), kind: kind, detail: activityDetail)
|
||||
log.didStart(id: id)
|
||||
activityID = id
|
||||
}
|
||||
|
||||
func didFinish() {
|
||||
completeActivityIfNeeded()
|
||||
if !isCanceled {
|
||||
operationDelegate?.operationDidComplete(self)
|
||||
}
|
||||
@@ -52,11 +74,35 @@ protocol FeedlyOperationDelegate: AnyObject {
|
||||
}
|
||||
|
||||
func didFinish(with error: Error) {
|
||||
failActivityIfNeeded(error: error)
|
||||
delegate?.feedlyOperation(self, didFailWith: error)
|
||||
didFinish()
|
||||
if !isCanceled {
|
||||
operationDelegate?.operationDidComplete(self)
|
||||
}
|
||||
downloadProgress?.completeTask()
|
||||
}
|
||||
|
||||
public func didCancel() {
|
||||
// On cancel, mark the activity failed so it doesn't linger as "started".
|
||||
if activityID != nil {
|
||||
failActivityIfNeeded(error: CocoaError(.userCancelled))
|
||||
}
|
||||
didFinish()
|
||||
}
|
||||
|
||||
private func completeActivityIfNeeded() {
|
||||
guard let id = activityID else {
|
||||
return
|
||||
}
|
||||
ActivityLog.shared.didComplete(id: id)
|
||||
activityID = nil
|
||||
}
|
||||
|
||||
private func failActivityIfNeeded(error: Error) {
|
||||
guard let id = activityID else {
|
||||
return
|
||||
}
|
||||
ActivityLog.shared.didFail(id: id, error: error)
|
||||
activityID = nil
|
||||
}
|
||||
}
|
||||
+1
@@ -25,6 +25,7 @@ final class FeedlySendArticleStatusesOperation: FeedlyOperation {
|
||||
|
||||
override func run() {
|
||||
Feedly.logger.info("Feedly: Sending article statuses")
|
||||
startActivityIfNeeded()
|
||||
|
||||
Task {
|
||||
do {
|
||||
|
||||
@@ -12,6 +12,7 @@ import SyncDatabase
|
||||
import RSWeb
|
||||
import RSCore
|
||||
import Secrets
|
||||
import ActivityLog
|
||||
|
||||
/// Compose the operations necessary to get the entire set of articles, feeds and folders with the statuses the user expects between now and a certain date in the past.
|
||||
final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
@@ -41,10 +42,15 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
|
||||
self.downloadProgress = downloadProgress
|
||||
|
||||
let accountID = account.accountID
|
||||
|
||||
// Send any read/unread/starred article statuses to Feedly before anything else.
|
||||
let sendArticleStatuses = FeedlySendArticleStatusesOperation(database: database, service: markArticlesService)
|
||||
sendArticleStatuses.delegate = self
|
||||
sendArticleStatuses.downloadProgress = downloadProgress
|
||||
sendArticleStatuses.activityKind = .sendArticleStatuses
|
||||
sendArticleStatuses.activityDetail = "Sending Feedly statuses"
|
||||
sendArticleStatuses.activityAccountID = accountID
|
||||
self.operationQueue.add(sendArticleStatuses)
|
||||
|
||||
// Get all the Collections the user has.
|
||||
@@ -52,6 +58,9 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
getCollections.delegate = self
|
||||
getCollections.downloadProgress = downloadProgress
|
||||
getCollections.addDependency(sendArticleStatuses)
|
||||
getCollections.activityKind = .refreshFeedList
|
||||
getCollections.activityDetail = "Fetching collections"
|
||||
getCollections.activityAccountID = accountID
|
||||
self.operationQueue.add(getCollections)
|
||||
|
||||
// Ensure a folder exists for each Collection, removing Folders without a corresponding Collection.
|
||||
@@ -70,6 +79,9 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
getAllArticleIds.delegate = self
|
||||
getAllArticleIds.downloadProgress = downloadProgress
|
||||
getAllArticleIds.addDependency(createFeedsOperation)
|
||||
getAllArticleIds.activityKind = .refreshArticleStatuses
|
||||
getAllArticleIds.activityDetail = "Fetching all article IDs"
|
||||
getAllArticleIds.activityAccountID = accountID
|
||||
self.operationQueue.add(getAllArticleIds)
|
||||
|
||||
// Get each page of unread article ids in the global.all stream for the last 31 days (nil = Feedly API default).
|
||||
@@ -77,6 +89,9 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
getUnread.delegate = self
|
||||
getUnread.addDependency(getAllArticleIds)
|
||||
getUnread.downloadProgress = downloadProgress
|
||||
getUnread.activityKind = .refreshArticleStatuses
|
||||
getUnread.activityDetail = "Fetching unread article IDs"
|
||||
getUnread.activityAccountID = accountID
|
||||
self.operationQueue.add(getUnread)
|
||||
|
||||
// Get each page of the article ids which have been update since the last successful fetch start date.
|
||||
@@ -85,6 +100,9 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
getUpdated.delegate = self
|
||||
getUpdated.downloadProgress = downloadProgress
|
||||
getUpdated.addDependency(createFeedsOperation)
|
||||
getUpdated.activityKind = .refreshArticleStatuses
|
||||
getUpdated.activityDetail = "Fetching updated article IDs"
|
||||
getUpdated.activityAccountID = accountID
|
||||
self.operationQueue.add(getUpdated)
|
||||
|
||||
// Get each page of the article ids for starred articles.
|
||||
@@ -92,6 +110,9 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
getStarred.delegate = self
|
||||
getStarred.downloadProgress = downloadProgress
|
||||
getStarred.addDependency(createFeedsOperation)
|
||||
getStarred.activityKind = .refreshArticleStatuses
|
||||
getStarred.activityDetail = "Fetching starred article IDs"
|
||||
getStarred.activityAccountID = accountID
|
||||
self.operationQueue.add(getStarred)
|
||||
|
||||
// Now all the possible article ids we need have a status, fetch the article ids for missing articles.
|
||||
@@ -102,6 +123,9 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
getMissingIds.addDependency(getUnread)
|
||||
getMissingIds.addDependency(getStarred)
|
||||
getMissingIds.addDependency(getUpdated)
|
||||
getMissingIds.activityKind = .refreshMissingArticles
|
||||
getMissingIds.activityDetail = "Finding missing article IDs"
|
||||
getMissingIds.activityAccountID = accountID
|
||||
self.operationQueue.add(getMissingIds)
|
||||
|
||||
// Download all the missing and updated articles
|
||||
@@ -115,6 +139,9 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
downloadMissingArticles.downloadProgress = downloadProgress
|
||||
downloadMissingArticles.addDependency(getMissingIds)
|
||||
downloadMissingArticles.addDependency(getUpdated)
|
||||
downloadMissingArticles.activityKind = .refreshMissingArticles
|
||||
downloadMissingArticles.activityDetail = "Downloading articles"
|
||||
downloadMissingArticles.activityAccountID = accountID
|
||||
self.operationQueue.add(downloadMissingArticles)
|
||||
|
||||
// Once this operation's dependencies, their dependencies etc finish, we can finish.
|
||||
|
||||
Reference in new issue
Block a user