diff --git a/packages/api/src/entity/subscription.ts b/packages/api/src/entity/subscription.ts index 2c1f271b4..32fa8e456 100644 --- a/packages/api/src/entity/subscription.ts +++ b/packages/api/src/entity/subscription.ts @@ -16,7 +16,6 @@ export enum SubscriptionStatus { Active = 'ACTIVE', Deleted = 'DELETED', Unsubscribed = 'UNSUBSCRIBED', - RefreshError = 'REFRESH_ERROR', } export enum SubscriptionType { diff --git a/packages/api/src/generated/graphql.ts b/packages/api/src/generated/graphql.ts index fd24070f3..33ecceb9b 100644 --- a/packages/api/src/generated/graphql.ts +++ b/packages/api/src/generated/graphql.ts @@ -2833,6 +2833,7 @@ export type Subscription = { count: Scalars['Int']; createdAt: Scalars['Date']; description?: Maybe; + failedAt?: Maybe; fetchContent: Scalars['Boolean']; folder: Scalars['String']; icon?: Maybe; @@ -2854,7 +2855,6 @@ export type Subscription = { export enum SubscriptionStatus { Active = 'ACTIVE', Deleted = 'DELETED', - RefreshError = 'REFRESH_ERROR', Unsubscribed = 'UNSUBSCRIBED' } @@ -3208,6 +3208,7 @@ export enum UpdateSubscriptionErrorCode { export type UpdateSubscriptionInput = { autoAddToLibrary?: InputMaybe; description?: InputMaybe; + failedAt?: InputMaybe; fetchContent?: InputMaybe; folder?: InputMaybe; id: Scalars['ID']; @@ -6190,6 +6191,7 @@ export type SubscriptionResolvers; createdAt?: SubscriptionResolver; description?: SubscriptionResolver, "description", ParentType, ContextType>; + failedAt?: SubscriptionResolver, "failedAt", ParentType, ContextType>; fetchContent?: SubscriptionResolver; folder?: SubscriptionResolver; icon?: SubscriptionResolver, "icon", ParentType, ContextType>; diff --git a/packages/api/src/generated/schema.graphql b/packages/api/src/generated/schema.graphql index e81e604d9..203d7b9bd 100644 --- a/packages/api/src/generated/schema.graphql +++ b/packages/api/src/generated/schema.graphql @@ -2229,6 +2229,7 @@ type Subscription { count: Int! createdAt: Date! description: String + failedAt: Date fetchContent: Boolean! folder: String! icon: String @@ -2250,7 +2251,6 @@ type Subscription { enum SubscriptionStatus { ACTIVE DELETED - REFRESH_ERROR UNSUBSCRIBED } @@ -2575,6 +2575,7 @@ enum UpdateSubscriptionErrorCode { input UpdateSubscriptionInput { autoAddToLibrary: Boolean description: String + failedAt: Date fetchContent: Boolean folder: String id: ID! diff --git a/packages/api/src/jobs/rss/refreshFeed.ts b/packages/api/src/jobs/rss/refreshFeed.ts index 57692d770..9a18bcce9 100644 --- a/packages/api/src/jobs/rss/refreshFeed.ts +++ b/packages/api/src/jobs/rss/refreshFeed.ts @@ -461,7 +461,7 @@ const processSubscription = async ( // fetch feed let itemCount = 0, - errorCount = 0 + failedAt: Date | undefined const feedLastBuildDate = feed.lastBuildDate console.log('Feed last build date', feedLastBuildDate) @@ -538,7 +538,7 @@ const processSubscription = async ( itemCount = itemCount + 1 } catch (error) { console.error('Error while saving RSS feed item', error, item) - errorCount = errorCount + 1 + failedAt = new Date() } } @@ -561,7 +561,7 @@ const processSubscription = async ( ) if (!created) { console.error('Failed to create task for feed item', lastValidItem.link) - errorCount = errorCount + 1 + failedAt = new Date() } lastItemFetchedAt = lastValidItem.isoDate @@ -572,7 +572,6 @@ const processSubscription = async ( const updateFrequency = getUpdateFrequency(feed) const updatePeriodInMs = getUpdatePeriodInHours(feed) * 60 * 60 * 1000 const nextScheduledAt = scheduledAt + updatePeriodInMs * updateFrequency - const status = errorCount > 0 ? SubscriptionStatus.RefreshError : undefined // update subscription mostRecentItemDate and refreshedAt const updatedSubscription = await updateSubscription(userId, subscriptionId, { @@ -580,7 +579,7 @@ const processSubscription = async ( lastFetchedChecksum: updatedLastFetchedChecksum, scheduledAt: new Date(nextScheduledAt), refreshedAt, - status, + failedAt, }) console.log('Updated subscription', updatedSubscription) } @@ -681,10 +680,11 @@ export const _refreshFeed = async (request: RefreshFeedRequest) => { error, }) + const now = new Date() // mark subscriptions as error if we failed to get the feed await updateSubscriptions(subscriptionIds, { - status: SubscriptionStatus.RefreshError, - refreshedAt: new Date(), + refreshedAt: now, + failedAt: now, }) return false diff --git a/packages/api/src/resolvers/subscriptions/index.ts b/packages/api/src/resolvers/subscriptions/index.ts index 06256b8bc..a13529325 100644 --- a/packages/api/src/resolvers/subscriptions/index.ts +++ b/packages/api/src/resolvers/subscriptions/index.ts @@ -217,10 +217,7 @@ export const subscribeResolver = authorized< type: SubscriptionType.Rss, }) if (existingSubscription) { - if ( - existingSubscription.status === SubscriptionStatus.Active || - existingSubscription.status === SubscriptionStatus.RefreshError - ) { + if (existingSubscription.status === SubscriptionStatus.Active) { return { errorCodes: [SubscribeErrorCode.AlreadySubscribed], } diff --git a/packages/api/src/schema.ts b/packages/api/src/schema.ts index 298904d62..877b4bfb4 100755 --- a/packages/api/src/schema.ts +++ b/packages/api/src/schema.ts @@ -1688,13 +1688,13 @@ const schema = gql` folder: String! mostRecentItemDate: Date refreshedAt: Date + failedAt: Date } enum SubscriptionStatus { ACTIVE UNSUBSCRIBED DELETED - REFRESH_ERROR } type SubscriptionsError { @@ -2609,6 +2609,7 @@ const schema = gql` folder: String refreshedAt: Date mostRecentItemDate: Date + failedAt: Date } union UpdateSubscriptionResult = diff --git a/packages/api/src/services/update_subscription.ts b/packages/api/src/services/update_subscription.ts index b6d1a51da..bcc077291 100644 --- a/packages/api/src/services/update_subscription.ts +++ b/packages/api/src/services/update_subscription.ts @@ -25,6 +25,7 @@ type UpdateSubscriptionData = { scheduledAt?: Date | null status?: SubscriptionStatus | null refreshedAt?: Date | null + failedAt?: Date | null } export const updateSubscription = async ( @@ -44,13 +45,14 @@ export const updateSubscription = async ( lastFetchedChecksum: newData.lastFetchedChecksum || undefined, status: newData.status || undefined, scheduledAt: newData.scheduledAt || undefined, + failedAt: newData.failedAt || undefined, autoAddToLibrary: newData.autoAddToLibrary ?? undefined, isPrivate: newData.isPrivate ?? undefined, fetchContent: newData.fetchContent ?? undefined, folder: newData.folder ?? undefined, }) - return await getRepository(Subscription).findOneByOrFail({ + return await repo.findOneByOrFail({ id: subscriptionId, user: { id: userId }, }) @@ -70,6 +72,7 @@ export const updateSubscriptions = async ( lastFetchedChecksum: newData.lastFetchedChecksum || undefined, status: newData.status || undefined, scheduledAt: newData.scheduledAt || undefined, + failedAt: newData.failedAt || undefined, autoAddToLibrary: newData.autoAddToLibrary ?? undefined, isPrivate: newData.isPrivate ?? undefined, fetchContent: newData.fetchContent ?? undefined, diff --git a/packages/db/migrations/0159.do.alter_subscriptions.sql b/packages/db/migrations/0159.do.alter_subscriptions.sql index 4b15c50fa..e4050eec5 100755 --- a/packages/db/migrations/0159.do.alter_subscriptions.sql +++ b/packages/db/migrations/0159.do.alter_subscriptions.sql @@ -4,10 +4,8 @@ BEGIN; -ALTER TYPE subscription_status_type - ADD VALUE IF NOT EXISTS 'REFRESH_ERROR'; - ALTER TABLE omnivore.subscriptions + ADD COLUMN failed_at timestamptz, ADD COLUMN refreshed_at timestamptz; UPDATE omnivore.subscriptions SET refreshed_at = last_fetched_at diff --git a/packages/db/migrations/0159.undo.alter_subscriptions.sql b/packages/db/migrations/0159.undo.alter_subscriptions.sql index 7e4e59f4a..6c9f8c3ca 100755 --- a/packages/db/migrations/0159.undo.alter_subscriptions.sql +++ b/packages/db/migrations/0159.undo.alter_subscriptions.sql @@ -8,6 +8,7 @@ ALTER TABLE omnivore.subscriptions RENAME COLUMN most_recent_item_date TO last_fetched_at; ALTER TABLE omnivore.subscriptions + DROP COLUMN failed_at, DROP COLUMN refreshed_at; COMMIT;