docs: Improve Loaders documentation (#5205)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2023-09-25 19:03:00 +03:00
1 parent 797cd48bd3
commit 07e65f5aba
3 files changed
+5 -31

No files matched your search

@@ -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: 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 ```ts title=src/loaders/my-loader.ts
import { ProductService } from "@medusajs/medusa" import { ProductService, ConfigModule } from "@medusajs/medusa"
import { AwilixContainer } from "awilix" import { AwilixContainer } from "awilix"
export default async ( export default async (
container: AwilixContainer, container: AwilixContainer,
config: Record<string, unknown> config: ConfigModule
): Promise<void> => { ): Promise<void> => {
console.info("Starting loader...") console.info("Starting loader...")
const productService = container.resolve<ProductService>( 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 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: Loaders can also be used to create [scheduled jobs](../scheduled-jobs/overview.mdx) that run at a specified interval of time.
```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
```
--- ---
+2 -1
View File
@@ -237,7 +237,8 @@ const config = {
{ {
docs: { docs: {
sidebarPath: require.resolve("./sidebars.js"), 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", path: "content",
routeBasePath: "/", routeBasePath: "/",
remarkPlugins: [ remarkPlugins: [