docs: added missing tabs in Create a Batch Job Strategy documentation (#2434)

Fixes: 2423
This commit is contained in:
Akarsh Jain
2022-10-13 15:20:50 +03:00
committed by GitHub
parent 60cd94fd60
commit 2e350b204c
@@ -1,3 +1,6 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
# Create a Batch Job Strategy # Create a Batch Job Strategy
In this document, youll learn how to create a batch job strategy on your Medusa server. In this document, youll learn how to create a batch job strategy on your Medusa server.
@@ -251,8 +254,10 @@ The first step is to create a batch job using the [Create Batch Job endpoint](ht
For example, this creates a batch job of the type `publish-products`: For example, this creates a batch job of the type `publish-products`:
<Tabs groupId="request-types">
<TabItem value="client" label="Medusa JS Client" default>
```jsx ```jsx
// using JS Client
medusa.admin.batchJobs.create({ medusa.admin.batchJobs.create({
type: 'publish-products', type: 'publish-products',
context: { }, context: { },
@@ -263,8 +268,10 @@ medusa.admin.batchJobs.create({
}); });
``` ```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```jsx ```jsx
// using Fetch API
fetch(`<YOUR_SERVER>/admin/batch-jobs`, { fetch(`<YOUR_SERVER>/admin/batch-jobs`, {
method: 'POST', method: 'POST',
headers: { headers: {
@@ -282,8 +289,10 @@ fetch(`<YOUR_SERVER>/admin/batch-jobs`, {
}); });
``` ```
</TabItem>
<TabItem value="curl" label="cURL">
```bash ```bash
# using cURL
curl --location --request POST '<YOUR_SERVER>/admin/batch-jobs' \ curl --location --request POST '<YOUR_SERVER>/admin/batch-jobs' \
--header 'Authorization: Bearer <API_TOKEN>' \ --header 'Authorization: Bearer <API_TOKEN>' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
@@ -294,6 +303,9 @@ curl --location --request POST '<YOUR_SERVER>/admin/batch-jobs' \
}' }'
``` ```
</TabItem>
</Tabs>
You set the `dry_run` to `true` to disable automatic confirmation and running of the batch job. If you want the batch job to run automatically, you can remove this body parameter. You set the `dry_run` to `true` to disable automatic confirmation and running of the batch job. If you want the batch job to run automatically, you can remove this body parameter.
Make sure to replace `<YOUR_SERVER>` with the server URL where applicable. Make sure to replace `<YOUR_SERVER>` with the server URL where applicable.
@@ -302,16 +314,20 @@ Make sure to replace `<YOUR_SERVER>` with the server URL where applicable.
You can retrieve the batch job afterward to get its status and view details about the process in the `result` property: You can retrieve the batch job afterward to get its status and view details about the process in the `result` property:
<Tabs groupId="request-type">
<TabItem value="client" label="Medusa JS Client" default>
```jsx ```jsx
// using JS Client
medusa.admin.batchJobs.retrieve(batchJobId) medusa.admin.batchJobs.retrieve(batchJobId)
.then(( batch_job ) => { .then(( batch_job ) => {
console.log(batch_job.status, batch_job.result); console.log(batch_job.status, batch_job.result);
}); });
``` ```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```jsx ```jsx
// using Fetch API
fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}`) fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}`)
.then((response) => response.json()) .then((response) => response.json())
.then(({ batch_job }) => { .then(({ batch_job }) => {
@@ -319,13 +335,18 @@ fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}`)
}); });
``` ```
</TabItem>
<TabItem value="curl" label="cURL">
```bash ```bash
# using cURL
curl --location --request GET '<YOUR_SERVER>/admin/batch-jobs/<BATCH_JOB_ID>' \ curl --location --request GET '<YOUR_SERVER>/admin/batch-jobs/<BATCH_JOB_ID>' \
--header 'Authorization: Bearer <API_TOKEN>' --header 'Authorization: Bearer <API_TOKEN>'
# <BATCH_JOB_ID> is the ID of the batch job # <BATCH_JOB_ID> is the ID of the batch job
``` ```
</TabItem>
</Tabs>
Based on the batch job strategy implemented in this documentation, the `result` property could be something like this: Based on the batch job strategy implemented in this documentation, the `result` property could be something like this:
```jsx ```jsx
@@ -346,16 +367,20 @@ Based on the batch job strategy implemented in this documentation, the `result`
To process the batch job, send a request to [confirm the batch job](https://docs.medusajs.com/api/admin/#tag/Batch-Job/operation/PostBatchJobsBatchJobConfirmProcessing): To process the batch job, send a request to [confirm the batch job](https://docs.medusajs.com/api/admin/#tag/Batch-Job/operation/PostBatchJobsBatchJobConfirmProcessing):
<Tabs groupId="request-type">
<TabItem value="client" label="Medusa JS Client" default>
```jsx ```jsx
// using JS Client
medusa.admin.batchJobs.confirm(batchJobId) medusa.admin.batchJobs.confirm(batchJobId)
.then(( batch_job ) => { .then(( batch_job ) => {
console.log(batch_job.status); console.log(batch_job.status);
}); });
``` ```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```jsx ```jsx
// using Fetch API
fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}/confirm`, { fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}/confirm`, {
method: 'POST' method: 'POST'
}) })
@@ -365,13 +390,18 @@ fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}/confirm`, {
}); });
``` ```
</TabItem>
<TabItem value="curl" label="cURL">
```bash ```bash
# using cURL
curl --location --request POST '<YOUR_SERVER>/admin/batch-jobs/<BATCH_JOB_ID>/confirm' \ curl --location --request POST '<YOUR_SERVER>/admin/batch-jobs/<BATCH_JOB_ID>/confirm' \
--header 'Authorization: Bearer <API_TOKEN>' --header 'Authorization: Bearer <API_TOKEN>'
# <BATCH_JOB_ID> is the ID of the batch job # <BATCH_JOB_ID> is the ID of the batch job
``` ```
</TabItem>
</Tabs>
The batch job will start processing afterward. Based on the batch job strategy implemented in this documentation, draft products will be published. The batch job will start processing afterward. Based on the batch job strategy implemented in this documentation, draft products will be published.
You can [retrieve the batch job](#optional-retrieve-batch-job) at any given point to check its status. You can [retrieve the batch job](#optional-retrieve-batch-job) at any given point to check its status.