docs: Improve Loaders documentation (#5205)
This commit is contained in:
@@ -39,12 +39,12 @@ When the loader is defined in a module, it receives the following parameters:
|
||||
For example, this loader function resolves the `ProductService` and logs in the console the count of products in the Medusa backend:
|
||||
|
||||
```ts title=src/loaders/my-loader.ts
|
||||
import { ProductService } from "@medusajs/medusa"
|
||||
import { ProductService, ConfigModule } from "@medusajs/medusa"
|
||||
import { AwilixContainer } from "awilix"
|
||||
|
||||
export default async (
|
||||
container: AwilixContainer,
|
||||
config: Record<string, unknown>
|
||||
config: ConfigModule
|
||||
): Promise<void> => {
|
||||
console.info("Starting loader...")
|
||||
const productService = container.resolve<ProductService>(
|
||||
|
||||
@@ -23,34 +23,7 @@ Another example is the Algolia plugin, which uses a loader to update the index s
|
||||
|
||||
Loaders can be used to access the dependency container and register custom resources in it.
|
||||
|
||||
Loaders can also be used to create [scheduled jobs](../scheduled-jobs/overview.mdx) that run at a specified interval of time. For example:
|
||||
|
||||
```ts
|
||||
const publishJob = async (container, options) => {
|
||||
const jobSchedulerService =
|
||||
container.resolve("jobSchedulerService")
|
||||
jobSchedulerService.create(
|
||||
"publish-products",
|
||||
{},
|
||||
"0 0 * * *",
|
||||
async () => {
|
||||
// job to execute
|
||||
const productService = container.resolve("productService")
|
||||
const draftProducts = await productService.list({
|
||||
status: "draft",
|
||||
})
|
||||
|
||||
for (const product of draftProducts) {
|
||||
await productService.update(product.id, {
|
||||
status: "published",
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export default publishJob
|
||||
```
|
||||
Loaders can also be used to create [scheduled jobs](../scheduled-jobs/overview.mdx) that run at a specified interval of time.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -237,7 +237,8 @@ const config = {
|
||||
{
|
||||
docs: {
|
||||
sidebarPath: require.resolve("./sidebars.js"),
|
||||
editUrl: "https://github.com/medusajs/medusa/edit/develop/www/docs",
|
||||
editUrl:
|
||||
"https://github.com/medusajs/medusa/edit/develop/www/apps/docs",
|
||||
path: "content",
|
||||
routeBasePath: "/",
|
||||
remarkPlugins: [
|
||||
|
||||
Reference in New Issue
Block a user