mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
save the timestamp when feed fails
This commit is contained in:
parent
9e55fe0d7b
commit
1563b44197
9 changed files with 21 additions and 19 deletions
|
|
@ -16,7 +16,6 @@ export enum SubscriptionStatus {
|
|||
Active = 'ACTIVE',
|
||||
Deleted = 'DELETED',
|
||||
Unsubscribed = 'UNSUBSCRIBED',
|
||||
RefreshError = 'REFRESH_ERROR',
|
||||
}
|
||||
|
||||
export enum SubscriptionType {
|
||||
|
|
|
|||
|
|
@ -2833,6 +2833,7 @@ export type Subscription = {
|
|||
count: Scalars['Int'];
|
||||
createdAt: Scalars['Date'];
|
||||
description?: Maybe<Scalars['String']>;
|
||||
failedAt?: Maybe<Scalars['Date']>;
|
||||
fetchContent: Scalars['Boolean'];
|
||||
folder: Scalars['String'];
|
||||
icon?: Maybe<Scalars['String']>;
|
||||
|
|
@ -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<Scalars['Boolean']>;
|
||||
description?: InputMaybe<Scalars['String']>;
|
||||
failedAt?: InputMaybe<Scalars['Date']>;
|
||||
fetchContent?: InputMaybe<Scalars['Boolean']>;
|
||||
folder?: InputMaybe<Scalars['String']>;
|
||||
id: Scalars['ID'];
|
||||
|
|
@ -6190,6 +6191,7 @@ export type SubscriptionResolvers<ContextType = ResolverContext, ParentType exte
|
|||
count?: SubscriptionResolver<ResolversTypes['Int'], "count", ParentType, ContextType>;
|
||||
createdAt?: SubscriptionResolver<ResolversTypes['Date'], "createdAt", ParentType, ContextType>;
|
||||
description?: SubscriptionResolver<Maybe<ResolversTypes['String']>, "description", ParentType, ContextType>;
|
||||
failedAt?: SubscriptionResolver<Maybe<ResolversTypes['Date']>, "failedAt", ParentType, ContextType>;
|
||||
fetchContent?: SubscriptionResolver<ResolversTypes['Boolean'], "fetchContent", ParentType, ContextType>;
|
||||
folder?: SubscriptionResolver<ResolversTypes['String'], "folder", ParentType, ContextType>;
|
||||
icon?: SubscriptionResolver<Maybe<ResolversTypes['String']>, "icon", ParentType, ContextType>;
|
||||
|
|
|
|||
|
|
@ -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!
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue