-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
387 additions
and
239 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 66 additions & 76 deletions
142
packages/api/src/functions/refreshMetadataCollectionLongProcess/handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/api/src/functions/refreshMetadataCollectionLongProcess/src/collections.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { atomicUpdate } from "@libs/couch/dbHelpers" | ||
import { CollectionDocType } from "@oboku/shared/src/db/docTypes" | ||
import nano from "nano" | ||
import { from } from "rxjs" | ||
|
||
export const markCollectionAsFetching = ({ | ||
db, | ||
collectionId | ||
}: { | ||
db: nano.DocumentScope<unknown> | ||
collectionId: string | ||
}) => | ||
from( | ||
atomicUpdate(db, "obokucollection", collectionId, (old) => { | ||
const wasAlreadyInitialized = | ||
old.metadataUpdateStatus === "fetching" && old.lastMetadataStartedAt | ||
|
||
if (wasAlreadyInitialized) return old | ||
|
||
return { | ||
...old, | ||
metadataUpdateStatus: "fetching" as const, | ||
lastMetadataStartedAt: new Date().toISOString() | ||
} | ||
}) | ||
) | ||
|
||
export const markCollectionAsError = ({ | ||
db, | ||
collectionId | ||
}: { | ||
db: nano.DocumentScope<unknown> | ||
collectionId: string | ||
}) => | ||
from( | ||
atomicUpdate( | ||
db, | ||
"obokucollection", | ||
collectionId, | ||
(old) => | ||
({ | ||
...old, | ||
metadataUpdateStatus: "idle", | ||
lastMetadataUpdateError: "unknown" | ||
}) satisfies CollectionDocType | ||
) | ||
) |
37 changes: 37 additions & 0 deletions
37
packages/api/src/functions/refreshMetadataCollectionLongProcess/src/parameters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { map } from "rxjs/operators" | ||
|
||
import { from } from "rxjs" | ||
|
||
import { getParametersValue } from "@libs/ssm" | ||
import { defer } from "rxjs" | ||
|
||
export const parameters$ = defer(() => | ||
from( | ||
getParametersValue({ | ||
Names: [ | ||
"GOOGLE_CLIENT_ID", | ||
"GOOGLE_CLIENT_SECRET", | ||
"GOOGLE_API_KEY", | ||
"jwt-private-key", | ||
"COMiCVINE_API_KEY" | ||
], | ||
WithDecryption: true | ||
}) | ||
).pipe( | ||
map( | ||
([ | ||
client_id = ``, | ||
client_secret = ``, | ||
googleApiKey = ``, | ||
jwtPrivateKey = ``, | ||
comicVineApiKey = `` | ||
]) => ({ | ||
client_id, | ||
client_secret, | ||
googleApiKey, | ||
jwtPrivateKey, | ||
comicVineApiKey | ||
}) | ||
) | ||
) | ||
) |
Oops, something went wrong.