docs: added dividers + see also section (#2899)
This commit is contained in:
@@ -17,6 +17,8 @@ Batch jobs can be used to perform long tasks in the background of your Medusa se
|
||||
|
||||
This documentation helps you learn how to create a batch job strategy. The batch job strategy used in this example changes the status of all draft products to `published`.
|
||||
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### Medusa Components
|
||||
@@ -31,12 +33,16 @@ Redis is required for batch jobs to work. Make sure you [install Redis](../../.
|
||||
|
||||
If you use SQLite during your development, it’s highly recommended that you use PostgreSQL when working with batch jobs. Learn how to [install PostgreSQL](../../../tutorial/0-set-up-your-development-environment.mdx#postgresql) and [configure it with your Medusa server](../../../usage/configurations.md#postgresql-configurations).
|
||||
|
||||
---
|
||||
|
||||
## 1. Create a File
|
||||
|
||||
A batch job strategy is essentially a class defined in a TypeScript or JavaScript file. You should create this file in `src/strategies`.
|
||||
|
||||
Following the example used in this documentation, create the file `src/strategies/publish.ts`.
|
||||
|
||||
---
|
||||
|
||||
## 2. Create Class
|
||||
|
||||
Batch job strategies must extend the abstract class `AbstractBatchJobStrategy` and implement its abstract methods.
|
||||
@@ -63,6 +69,8 @@ class PublishStrategy extends AbstractBatchJobStrategy {
|
||||
export default PublishStrategy
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Define Required Properties
|
||||
|
||||
A batch job strategy class must have two static properties: the `identifier` and `batchType` properties. The `identifier` must be a unique string associated with your batch job strategy, and `batchType` must be the batch job's type.
|
||||
@@ -80,6 +88,8 @@ class PublishStrategy extends AbstractBatchJobStrategy {
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Define Methods
|
||||
|
||||
### (Optional) prepareBatchJobForProcessing
|
||||
@@ -222,6 +232,8 @@ protected async handleProcessingError<T>(batchJobId: string, err: unknown, resul
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Run Build Command
|
||||
|
||||
After you create the batch job and before testing it out, you must run the build command in the directory of your Medusa server:
|
||||
@@ -230,6 +242,8 @@ After you create the batch job and before testing it out, you must run the build
|
||||
npm run build
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Test your Batch Job Strategy
|
||||
|
||||
This section covers how to test and use your batch job strategy. Make sure to start your server first:
|
||||
@@ -410,7 +424,9 @@ The batch job will start processing afterward. Based on the batch job strategy i
|
||||
|
||||
You can [retrieve the batch job](#optional-retrieve-batch-job) at any given point to check its status.
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Learn more about [batch jobs](./index.md).
|
||||
- Learn how to [import products using the Admin API](../../admin/import-products.mdx).
|
||||
## See Also
|
||||
|
||||
- [Batch Jobs Overview](./index.md).
|
||||
- [Import products using the Admin API](../../admin/import-products.mdx).
|
||||
|
||||
@@ -8,6 +8,8 @@ Product Import Strategy is essentially a batch job strategy. Medusa provides the
|
||||
|
||||
Although this documentation specifically targets import strategies, you can use the same steps to overwrite any batch job strategy in Medusa, including export strategies.
|
||||
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### Medusa Components
|
||||
@@ -22,6 +24,8 @@ Redis is required for batch jobs to work. Make sure you [install Redis](../../.
|
||||
|
||||
If you use SQLite during your development, it’s highly recommended that you use PostgreSQL when working with batch jobs. Learn how to [install PostgreSQL](../../../tutorial/0-set-up-your-development-environment.mdx#postgresql) and [configure it with your Medusa server](../../../usage/configurations.md#postgresql-configurations).
|
||||
|
||||
---
|
||||
|
||||
## Overwrite Batch Job Strategy
|
||||
|
||||
The steps required for overwriting a batch job strategy are essentially the same steps required to create a batch job strategy with a minor difference. For that reason, this documentation does not cover the basics of a batch job strategy.
|
||||
@@ -103,13 +107,17 @@ Specifically, since you create batch jobs using the [Create Batch Job](https://d
|
||||
|
||||
If you overwrote the import functionality, you can follow [these steps to learn how to import products using the Admin APIs](../../admin/import-products.mdx).
|
||||
|
||||
---
|
||||
|
||||
## Create Custom Batch Job Strategy
|
||||
|
||||
If you don’t want to overwrite Medusa’s batch job strategy, you can create a custom batch job strategy with a different `batchType` value. Then, use that type when you send a request to [Create a Batch Job](https://docs.medusajs.com/api/admin/#tag/Batch-Job).
|
||||
|
||||
For more details on creating custom batch job strategies, please check out the [Create Batch Job Strategy documentation](create.md).
|
||||
|
||||
---
|
||||
|
||||
## What’s Next
|
||||
|
||||
- Learn more about [batch jobs](./index.md).
|
||||
- Learn [how to use the Import Product APIs](../../admin/import-products.mdx).
|
||||
- [Batch Jobs Overview](./index.md).
|
||||
- [Use the Import Product APIs](../../admin/import-products.mdx).
|
||||
|
||||
@@ -26,6 +26,8 @@ A batch job is stored in the database as a [BatchJob](https://docs.medusajs.com/
|
||||
- `count`: A number that includes the total count of records related to the operation. For example, in the case of product exports, it is used to indicate the total number of products exported.
|
||||
- `advancement_count`: A number that indicates the number of records processed so far. Can be helpful when retrying a batch job.
|
||||
|
||||
---
|
||||
|
||||
## What are Batch Job Strategies
|
||||
|
||||
Batch jobs are handled by batch job strategies. A batch job strategy is a class that extends the `AbstractBatchJobStrategy` abstract class and implements the methods defined in that class to handle the different states of a batch job.
|
||||
@@ -34,6 +36,8 @@ A batch job strategy must implement the necessary methods to handle the preparat
|
||||
|
||||
When you create a batch job strategy, the `batchType` class property indicates the batch job types this strategy handles. Then, when you create a new batch job, you set the batch job’s type to the value of `batchType` in your strategy.
|
||||
|
||||
---
|
||||
|
||||
## How Batch Jobs Work
|
||||
|
||||
A batch job’s flow from creation to completion is:
|
||||
@@ -56,6 +60,8 @@ If the batch job fails at any point in this flow, its status is changed to `fail
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## What’s Next
|
||||
|
||||
- Learn about the [Batch Job’s events](../subscribers/events-list.md#batch-jobs-events).
|
||||
- [Batch Job’s Events Reference](../subscribers/events-list.md#batch-jobs-events).
|
||||
|
||||
Reference in New Issue
Block a user