docs: update sanity guide + marketplace recipe to use permanentFailure (#10310)
This commit is contained in:
@@ -703,9 +703,9 @@ export const syncStep = createStep(
|
||||
const batchSize = 200
|
||||
const hasMore = true
|
||||
const offset = 0
|
||||
const filters = {
|
||||
id: input.product_ids || [],
|
||||
}
|
||||
let filters = input.product_ids ? {
|
||||
id: input.product_ids
|
||||
} : {}
|
||||
|
||||
while (hasMore) {
|
||||
const {
|
||||
@@ -719,7 +719,6 @@ export const syncStep = createStep(
|
||||
// @ts-ignore
|
||||
"sanity_product.*",
|
||||
],
|
||||
// @ts-ignore
|
||||
filters,
|
||||
pagination: {
|
||||
skip: offset,
|
||||
@@ -777,22 +776,29 @@ export const syncStep = createStep(
|
||||
|
||||
while (hasMore) {
|
||||
// ...
|
||||
await promiseAll(
|
||||
products.map(async (prod) => {
|
||||
const after = await sanityModule.upsertSyncDocument(
|
||||
"product",
|
||||
prod as ProductDTO
|
||||
)
|
||||
|
||||
upsertMap.push({
|
||||
// @ts-ignore
|
||||
before: prod.sanity_product,
|
||||
after,
|
||||
})
|
||||
|
||||
return after
|
||||
})
|
||||
)
|
||||
try {
|
||||
await promiseAll(
|
||||
products.map(async (prod) => {
|
||||
const after = await sanityModule.upsertSyncDocument(
|
||||
"product",
|
||||
prod as ProductDTO
|
||||
);
|
||||
|
||||
upsertMap.push({
|
||||
// @ts-ignore
|
||||
before: prod.sanity_product,
|
||||
after
|
||||
})
|
||||
|
||||
return after
|
||||
}),
|
||||
)
|
||||
} catch (e) {
|
||||
return StepResponse.permanentFailure(
|
||||
`An error occurred while syncing documents: ${e}`,
|
||||
upsertMap
|
||||
)
|
||||
}
|
||||
|
||||
offset += batchSize
|
||||
hasMore = offset < count
|
||||
@@ -808,7 +814,9 @@ In the `while` loop, you loop over the array of products to sync them to Sanity.
|
||||
|
||||
For each product, you upsert it into Sanity, then push its document before and after the update to the `upsertMap`. You'll learn more about its use later.
|
||||
|
||||
The step returns an instance of `StepResponse`, which must be returned by any step. It accepts as a first parameter the data to return to the workflow that executed this step.
|
||||
You also wrap the `promiseAll` function within a try-catch block. In the catch block, you invoke and return `StepResponse.permanentFailure` which indicates that the step has failed but still invokes the rollback mechanism that you'll implement in a bit. The first parameter of `permanentFailure` is the error message, and the second is the data to use in the rollback mechanism.
|
||||
|
||||
If no errors occur, the step returns an instance of `StepResponse`, which must be returned by any step. It accepts as a first parameter the data to return to the workflow that executed this step.
|
||||
|
||||
#### Add Compensation Function
|
||||
|
||||
|
||||
Reference in New Issue
Block a user