diff --git a/404.html b/404.html index b1a7ad53..e22e35da 100644 --- a/404.html +++ b/404.html @@ -18,7 +18,7 @@ - +
diff --git a/assets/js/1b2a18d5.56c143d3.js b/assets/js/1b2a18d5.3697ed96.js similarity index 93% rename from assets/js/1b2a18d5.56c143d3.js rename to assets/js/1b2a18d5.3697ed96.js index d074ad8e..c6c57937 100644 --- a/assets/js/1b2a18d5.56c143d3.js +++ b/assets/js/1b2a18d5.3697ed96.js @@ -1 +1 @@ -"use strict";(self.webpackChunk_athenna_docs=self.webpackChunk_athenna_docs||[]).push([[6927],{7181:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>l,contentTitle:()=>a,default:()=>u,frontMatter:()=>i,metadata:()=>o,toc:()=>d});var s=r(4848),t=r(8453),c=r(7049);const i={title:"Schedulers",sidebar_position:1,description:"See how to create and configure your CRON job schedulers."},a="Schedulers",o={id:"cron-application/schedulers",title:"Schedulers",description:"See how to create and configure your CRON job schedulers.",source:"@site/docs/cron-application/schedulers.mdx",sourceDirName:"cron-application",slug:"/cron-application/schedulers",permalink:"/docs/cron-application/schedulers",draft:!1,unlisted:!1,editUrl:"https://github.com/AthennaIO/Docs/tree/main/docs/cron-application/schedulers.mdx",tags:[],version:"current",sidebarPosition:1,frontMatter:{title:"Schedulers",sidebar_position:1,description:"See how to create and configure your CRON job schedulers."},sidebar:"tutorialSidebar",previous:{title:"Annotations",permalink:"/docs/cli-application/annotations"},next:{title:"CRON Context",permalink:"/docs/cron-application/cron-context"}},l={},d=[{value:"Introduction",id:"introduction",level:2},{value:"Defining Schedulers",id:"defining-schedulers",level:2},{value:"Defining schedulers logic",id:"defining-schedulers-logic",level:3},{value:"Defining schedulers in route file",id:"defining-schedulers-in-route-file",level:4},{value:"Listing schedulers (Coming Soon)",id:"listing-schedulers-coming-soon",level:3},{value:"Running scheduler locally (Coming Soon)",id:"running-scheduler-locally-coming-soon",level:2},{value:"UsingrunOnInit
option",id:"using-runoninit-option",level:3},{value:"Dependency injection in schedulers",id:"dependency-injection-in-schedulers",level:2},{value:"Automatic constructor injection",id:"automatic-constructor-injection",level:3}];function h(e){const n={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",p:"p",pre:"pre",strong:"strong",...(0,t.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.header,{children:(0,s.jsx)(n.h1,{id:"schedulers",children:"Schedulers"})}),"\n",(0,s.jsx)(n.p,{children:"See how to create and configure your CRON job schedulers."}),"\n",(0,s.jsx)(n.h2,{id:"introduction",children:"Introduction"}),"\n",(0,s.jsxs)(n.p,{children:["Athenna's scheduler offers a fresh approach to managing\nscheduled tasks on your server. The scheduler allows you\nto fluently and expressively define your scheduler within\nyour Athenna application itself. When using the scheduler,\nonly a single cron entry is needed on your server. Your\ntask schedule can be defined in your application's\n",(0,s.jsx)(c.A,{father:"routes",child:"cron.ts"})," file or as a class\ninside ",(0,s.jsx)(c.A,{father:"cron",child:"schedulers/MyScheduler.ts"}),"."]}),"\n",(0,s.jsx)(n.h2,{id:"defining-schedulers",children:"Defining Schedulers"}),"\n",(0,s.jsxs)(n.p,{children:["Schedulers are typically stored in the ",(0,s.jsx)(n.code,{children:"src/cron/scheduelrs"}),"\ndirectory; however, you are free to choose your own storage\nlocation as long as your schedulers can be imported and registered."]}),"\n",(0,s.jsxs)(n.p,{children:["To create a new scheduler, you may use the ",(0,s.jsx)(n.code,{children:"make:scheduler"}),"\nArtisan command. This command will create a new command class\nin the ",(0,s.jsx)(n.code,{children:"src/cron/schedulers"})," directory and register it inside\n",(0,s.jsx)(n.code,{children:"schedulers"})," array of ",(0,s.jsx)(n.code,{children:".athennarc.json"})," file. Don't worry if\nthis directory does not exist in your application\u2014it will be\ncreated the first time you run the ",(0,s.jsx)(n.code,{children:"make:scheduler"})," Artisan command:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"node artisan make:scheduler DeleteRecentUsers\n"})}),"\n",(0,s.jsx)(n.p,{children:"This will create the schedulers file and automatically register\nit for you:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",metastring:'title=".athennarc.json"',children:'{\n "schedulers": [\n "#src/cron/schedulers/DeleteRecentUsers" \ud83d\udc48\n ]\n}\n'})}),"\n",(0,s.jsx)(n.h3,{id:"defining-schedulers-logic",children:"Defining schedulers logic"}),"\n",(0,s.jsxs)(n.p,{children:["In this example, we will schedule a ",(0,s.jsx)(n.code,{children:"handler"})," method to be called\n",(0,s.jsx)(n.strong,{children:"every day at midnight"}),". Within the method we will execute a\ndatabase query to clear a table:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Database } from '@athenna/database'\nimport { Scheduler, type Context } from '@athenna/cron'\n\n@Scheduler({ pattern: '0 0 * * *' })\nexport class DeleteRecentUsers {\n public async handler(ctx: Context) {\n await Database.table('recent_users').delete()\n }\n}\n"})}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["You can use ",(0,s.jsx)(n.a,{href:"https://crontab.guru/",children:"Crontab.guru"})," to help you\ncreate your CRON pattern, or simply ask ",(0,s.jsx)(n.a,{href:"https://chatgpt.com/",children:"ChatGPT"})," \ud83e\udd29."]})}),"\n",(0,s.jsx)(n.h4,{id:"defining-schedulers-in-route-file",children:"Defining schedulers in route file"}),"\n",(0,s.jsxs)(n.p,{children:["If you prefer, you can use the ",(0,s.jsx)(c.A,{father:"routes",child:"cron.ts"}),"\nfile to register your schedulers:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Cron } from '@athenna/cron'\nimport { Database } from '@athenna/database'\n\nCron.schedule().name('delete_recent_users')\n .pattern('0 0 * * *')\n .handler(async (ctx) => {\n await Database.table('recent_users').delete()\n })\n"})}),"\n",(0,s.jsx)(n.h3,{id:"listing-schedulers-coming-soon",children:"Listing schedulers (Coming Soon)"}),"\n",(0,s.jsxs)(n.p,{children:["If you would like to view an overview of your scheduled tasks and the\nnext time they are scheduled to run, you may use the cron",":list"," Artisan\ncommand:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-shell",children:"node artisan cron:list\n"})}),"\n",(0,s.jsx)(n.h2,{id:"running-scheduler-locally-coming-soon",children:"Running scheduler locally (Coming Soon)"}),"\n",(0,s.jsxs)(n.p,{children:["When developing or even in production you might need to\nforce the scheduler to run. To do so you can use the\n",(0,s.jsx)(n.code,{children:"node artisan cron:run"})," command:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"node artisan cron:run DeleteRecentUsers\n"})}),"\n",(0,s.jsx)(n.p,{children:"You can also use a CRON pattern, this will trigger all the\nschedulers registered with the same pattern:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:'node artisan cron:run "0 0 * * *"\n'})}),"\n",(0,s.jsxs)(n.h3,{id:"using-runoninit-option",children:["Using ",(0,s.jsx)(n.code,{children:"runOnInit"})," option"]}),"\n",(0,s.jsxs)(n.p,{children:["Another way to run your schedulers locally is to define the\n",(0,s.jsx)(n.code,{children:"runOnInit=true"})," option:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Database } from '@athenna/database'\nimport { Scheduler, type Context } from '@athenna/cron'\n\n@Scheduler({ \n runOnInit: true, \ud83d\udc48\n pattern: '0 0 * * *'\n})\nexport class DeleteRecentUsers {\n public async handler(ctx: Context) {\n await Database.table('recent_users').delete()\n }\n}\n"})}),"\n",(0,s.jsxs)(n.p,{children:["If using routes you may call the ",(0,s.jsx)(n.code,{children:"runOnInit()"})," method:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Cron } from '@athenna/cron'\nimport { Database } from '@athenna/database'\n\nCron.schedule().name('delete_recent_users')\n .runOnInit(true) \ud83d\udc48\n .pattern('0 0 * * *')\n .handler(async (ctx) => {\n await Database.table('recent_users').delete()\n })\n"})}),"\n",(0,s.jsxs)(n.p,{children:["If this option is set to ",(0,s.jsx)(n.code,{children:"true"}),", it will automatically run your\nscheduler when bootstrapping your Athenna application."]}),"\n",(0,s.jsx)(n.h2,{id:"dependency-injection-in-schedulers",children:"Dependency injection in schedulers"}),"\n",(0,s.jsxs)(n.p,{children:["When using schedulers classes you are able to use the ",(0,s.jsx)(n.code,{children:"@Inject()"}),"\nannotation to inject dependencies from you application within your\nscheduler class:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Inject } from '@athenna/ioc'\nimport { Scheduler, type Context } from '@athenna/cron'\nimport { RecentUserService } from '#src/services/RecentUserService'\n\n@Scheduler({ pattern: '0 0 * * *' })\nexport class DeleteRecentUsers {\n @Inject()\n public recentUserService: RecentUserService\n\n public async handler(ctx: Context) {\n await this.recentUserService.deleteAll()\n }\n}\n"})}),"\n",(0,s.jsx)(n.h3,{id:"automatic-constructor-injection",children:"Automatic constructor injection"}),"\n",(0,s.jsxs)(n.p,{children:["You can also use the automatic constructor injection if\nyour don't want to use the ",(0,s.jsx)(n.code,{children:"@Inject()"})," annotation:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Scheduler, type Context } from '@athenna/cron'\nimport type { RecentUserService } from '#src/services/RecentUserService'\n\n@Scheduler({ pattern: '0 0 * * *' })\nexport class DeleteRecentUsers {\n public recentUserService: RecentUserService\n\n public constructor(recentUserService: RecentUserService) {\n this.recentUserService = recentUserService\n }\n\n public async handler(ctx: Context) {\n await this.recentUserService.deleteAll()\n }\n}\n"})})]})}function u(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},7049:(e,n,r)=>{r.d(n,{A:()=>c});r(6540);const s={hoverCardContainer:"hoverCardContainer_jqUQ",hoverCardLink:"hoverCardLink_oDZU",hoverCard:"hoverCard_qTDS"};var t=r(4848);function c(e){let n=e.father;switch(e.father){case"storage":n="src/storage";break;case"logs":n="src/storage/logs";break;case"views":n="src/resources/views";break;case"locales":n="src/resources/locales";break;case"static":n="src/resources/static";break;case"config":n="src/config";break;case"database":n="src/database";break;case"seeders":n="src/database/seeders";break;case"migrations":n="src/database/migrations";break;case"console":n="src/console";break;case"commands":n="src/console/commands";break;case"cron":n="src/cron";break;case"schedulers":n="src/cron/schedulers";break;case"models":n="src/models";break;case"services":n="src/services";break;case"repositories":n="src/repositories";break;case"http":n="src/http";break;case"controllers":n="src/http/controllers";break;case"middlewares":n="src/http/middlewares";break;case"interceptors":n="src/http/interceptors";break;case"terminators":n="src/http/terminators";break;case"stubs":n="tests/stubs";break;case"fixtures":n="tests/fixtures";break;case"providers":n="src/providers";break;case"facades":n="src/facades";break;case"routes":n="src/routes"}return(0,t.jsxs)("div",{className:s.hoverCardContainer,children:[(0,t.jsx)("a",{className:s.hoverCardLink,href:`/docs/the-basics/helpers#path${e.father}`,children:(0,t.jsxs)("code",{children:["Path.",e.father,"(",e.child?`'${e.child}'`:"",")"]})}),(0,t.jsx)("div",{className:s.hoverCard,children:(0,t.jsxs)("p",{style:{margin:0},children:["./",n,e.child?`/${e.child}`:""]})})]})}},8453:(e,n,r)=>{r.d(n,{R:()=>i,x:()=>a});var s=r(6540);const t={},c=s.createContext(t);function i(e){const n=s.useContext(c);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:i(e.components),s.createElement(c.Provider,{value:n},e.children)}}}]);
\ No newline at end of file
+"use strict";(self.webpackChunk_athenna_docs=self.webpackChunk_athenna_docs||[]).push([[6927],{7181:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>l,contentTitle:()=>a,default:()=>u,frontMatter:()=>i,metadata:()=>o,toc:()=>d});var s=r(4848),t=r(8453),c=r(7049);const i={title:"Schedulers",sidebar_position:1,description:"See how to create and configure your CRON job schedulers."},a="Schedulers",o={id:"cron-application/schedulers",title:"Schedulers",description:"See how to create and configure your CRON job schedulers.",source:"@site/docs/cron-application/schedulers.mdx",sourceDirName:"cron-application",slug:"/cron-application/schedulers",permalink:"/docs/cron-application/schedulers",draft:!1,unlisted:!1,editUrl:"https://github.com/AthennaIO/Docs/tree/main/docs/cron-application/schedulers.mdx",tags:[],version:"current",sidebarPosition:1,frontMatter:{title:"Schedulers",sidebar_position:1,description:"See how to create and configure your CRON job schedulers."},sidebar:"tutorialSidebar",previous:{title:"Annotations",permalink:"/docs/cli-application/annotations"},next:{title:"CRON Context",permalink:"/docs/cron-application/cron-context"}},l={},d=[{value:"Introduction",id:"introduction",level:2},{value:"Defining Schedulers",id:"defining-schedulers",level:2},{value:"Defining schedulers logic",id:"defining-schedulers-logic",level:3},{value:"Defining schedulers in route file",id:"defining-schedulers-in-route-file",level:4},{value:"Listing schedulers (Coming Soon)",id:"listing-schedulers-coming-soon",level:3},{value:"Running scheduler locally (Coming Soon)",id:"running-scheduler-locally-coming-soon",level:2},{value:"Using runOnInit
option",id:"using-runoninit-option",level:3},{value:"Dependency injection in schedulers",id:"dependency-injection-in-schedulers",level:2},{value:"Automatic constructor injection",id:"automatic-constructor-injection",level:3}];function h(e){const n={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",p:"p",pre:"pre",strong:"strong",...(0,t.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.header,{children:(0,s.jsx)(n.h1,{id:"schedulers",children:"Schedulers"})}),"\n",(0,s.jsx)(n.p,{children:"See how to create and configure your CRON job schedulers."}),"\n",(0,s.jsx)(n.h2,{id:"introduction",children:"Introduction"}),"\n",(0,s.jsxs)(n.p,{children:["Athenna's scheduler offers a fresh approach to managing\nscheduled tasks on your server. The scheduler allows you\nto fluently and expressively define your scheduler within\nyour Athenna application itself. When using the scheduler,\nonly a single cron entry is needed on your server. Your\ntask schedule can be defined in your application's\n",(0,s.jsx)(c.A,{father:"routes",child:"cron.ts"})," file or as a class\ninside ",(0,s.jsx)(c.A,{father:"cron",child:"schedulers/MyScheduler.ts"}),"."]}),"\n",(0,s.jsx)(n.h2,{id:"defining-schedulers",children:"Defining Schedulers"}),"\n",(0,s.jsxs)(n.p,{children:["Schedulers are typically stored in the ",(0,s.jsx)(n.code,{children:"src/cron/scheduelrs"}),"\ndirectory; however, you are free to choose your own storage\nlocation as long as your schedulers can be imported and registered."]}),"\n",(0,s.jsxs)(n.p,{children:["To create a new scheduler, you may use the ",(0,s.jsx)(n.code,{children:"make:scheduler"}),"\nArtisan command. This command will create a new command class\nin the ",(0,s.jsx)(n.code,{children:"src/cron/schedulers"})," directory and register it inside\n",(0,s.jsx)(n.code,{children:"schedulers"})," array of ",(0,s.jsx)(n.code,{children:".athennarc.json"})," file. Don't worry if\nthis directory does not exist in your application\u2014it will be\ncreated the first time you run the ",(0,s.jsx)(n.code,{children:"make:scheduler"})," Artisan command:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"node artisan make:scheduler DeleteRecentUsers\n"})}),"\n",(0,s.jsx)(n.p,{children:"This will create the schedulers file and automatically register\nit for you:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",metastring:'title=".athennarc.json"',children:'{\n "schedulers": [\n "#src/cron/schedulers/DeleteRecentUsers" \ud83d\udc48\n ]\n}\n'})}),"\n",(0,s.jsx)(n.h3,{id:"defining-schedulers-logic",children:"Defining schedulers logic"}),"\n",(0,s.jsxs)(n.p,{children:["In this example, we will schedule a ",(0,s.jsx)(n.code,{children:"handler"})," method to be called\n",(0,s.jsx)(n.strong,{children:"every day at midnight"}),". Within the method we will execute a\ndatabase query to clear a table:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Database } from '@athenna/database'\nimport { Scheduler, type Context } from '@athenna/cron'\n\n@Scheduler({ pattern: '0 0 * * *' })\nexport class DeleteRecentUsers {\n public async handler(ctx: Context) {\n await Database.table('recent_users').delete()\n }\n}\n"})}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["You can use ",(0,s.jsx)(n.a,{href:"https://crontab.guru/",children:"Crontab.guru"})," to help you\ncreate your CRON pattern, or simply ask ",(0,s.jsx)(n.a,{href:"https://chatgpt.com/",children:"ChatGPT"})," \ud83e\udd29."]})}),"\n",(0,s.jsx)(n.h4,{id:"defining-schedulers-in-route-file",children:"Defining schedulers in route file"}),"\n",(0,s.jsxs)(n.p,{children:["If you prefer, you can use the ",(0,s.jsx)(c.A,{father:"routes",child:"cron.ts"}),"\nfile to register your schedulers:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Cron } from '@athenna/cron'\nimport { Database } from '@athenna/database'\n\nCron.schedule().name('delete_recent_users')\n .pattern('0 0 * * *')\n .handler(async (ctx) => {\n await Database.table('recent_users').delete()\n })\n"})}),"\n",(0,s.jsx)(n.h3,{id:"listing-schedulers-coming-soon",children:"Listing schedulers (Coming Soon)"}),"\n",(0,s.jsxs)(n.p,{children:["If you would like to view an overview of your scheduled tasks and the\nnext time they are scheduled to run, you may use the cron",":list"," Artisan\ncommand:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-shell",children:"node artisan cron:list\n"})}),"\n",(0,s.jsx)(n.h2,{id:"running-scheduler-locally-coming-soon",children:"Running scheduler locally (Coming Soon)"}),"\n",(0,s.jsxs)(n.p,{children:["When developing or even in production you might need to\nforce the scheduler to run. To do so you can use the\n",(0,s.jsx)(n.code,{children:"node artisan cron:run"})," command:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"node artisan cron:run DeleteRecentUsers\n"})}),"\n",(0,s.jsx)(n.p,{children:"You can also use a CRON pattern, this will trigger all the\nschedulers registered with the same pattern:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:'node artisan cron:run "0 0 * * *"\n'})}),"\n",(0,s.jsxs)(n.h3,{id:"using-runoninit-option",children:["Using ",(0,s.jsx)(n.code,{children:"runOnInit"})," option"]}),"\n",(0,s.jsxs)(n.p,{children:["Another way to run your schedulers locally is to define the\n",(0,s.jsx)(n.code,{children:"runOnInit=true"})," option:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Database } from '@athenna/database'\nimport { Scheduler, type Context } from '@athenna/cron'\n\n@Scheduler({ \n runOnInit: true, \ud83d\udc48\n pattern: '0 0 * * *'\n})\nexport class DeleteRecentUsers {\n public async handler(ctx: Context) {\n await Database.table('recent_users').delete()\n }\n}\n"})}),"\n",(0,s.jsxs)(n.p,{children:["If using routes you may call the ",(0,s.jsx)(n.code,{children:"runOnInit()"})," method:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Cron } from '@athenna/cron'\nimport { Database } from '@athenna/database'\n\nCron.schedule().name('delete_recent_users')\n .runOnInit(true) \ud83d\udc48\n .pattern('0 0 * * *')\n .handler(async (ctx) => {\n await Database.table('recent_users').delete()\n })\n"})}),"\n",(0,s.jsxs)(n.p,{children:["If this option is set to ",(0,s.jsx)(n.code,{children:"true"}),", it will automatically run your\nscheduler when bootstrapping your Athenna application."]}),"\n",(0,s.jsx)(n.h2,{id:"dependency-injection-in-schedulers",children:"Dependency injection in schedulers"}),"\n",(0,s.jsxs)(n.p,{children:["When using schedulers classes you are able to use the ",(0,s.jsx)(n.code,{children:"@Inject()"}),"\nannotation to inject dependencies from your application within your\nscheduler class:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Inject } from '@athenna/ioc'\nimport { Scheduler, type Context } from '@athenna/cron'\nimport { RecentUserService } from '#src/services/RecentUserService'\n\n@Scheduler({ pattern: '0 0 * * *' })\nexport class DeleteRecentUsers {\n @Inject()\n public recentUserService: RecentUserService\n\n public async handler(ctx: Context) {\n await this.recentUserService.deleteAll()\n }\n}\n"})}),"\n",(0,s.jsx)(n.h3,{id:"automatic-constructor-injection",children:"Automatic constructor injection"}),"\n",(0,s.jsxs)(n.p,{children:["You can also use the automatic constructor injection if\nyou don't want to use the ",(0,s.jsx)(n.code,{children:"@Inject()"})," annotation:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Scheduler, type Context } from '@athenna/cron'\nimport type { RecentUserService } from '#src/services/RecentUserService'\n\n@Scheduler({ pattern: '0 0 * * *' })\nexport class DeleteRecentUsers {\n public recentUserService: RecentUserService\n\n public constructor(recentUserService: RecentUserService) {\n this.recentUserService = recentUserService\n }\n\n public async handler(ctx: Context) {\n await this.recentUserService.deleteAll()\n }\n}\n"})})]})}function u(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},7049:(e,n,r)=>{r.d(n,{A:()=>c});r(6540);const s={hoverCardContainer:"hoverCardContainer_jqUQ",hoverCardLink:"hoverCardLink_oDZU",hoverCard:"hoverCard_qTDS"};var t=r(4848);function c(e){let n=e.father;switch(e.father){case"storage":n="src/storage";break;case"logs":n="src/storage/logs";break;case"views":n="src/resources/views";break;case"locales":n="src/resources/locales";break;case"static":n="src/resources/static";break;case"config":n="src/config";break;case"database":n="src/database";break;case"seeders":n="src/database/seeders";break;case"migrations":n="src/database/migrations";break;case"console":n="src/console";break;case"commands":n="src/console/commands";break;case"cron":n="src/cron";break;case"schedulers":n="src/cron/schedulers";break;case"models":n="src/models";break;case"services":n="src/services";break;case"repositories":n="src/repositories";break;case"http":n="src/http";break;case"controllers":n="src/http/controllers";break;case"middlewares":n="src/http/middlewares";break;case"interceptors":n="src/http/interceptors";break;case"terminators":n="src/http/terminators";break;case"stubs":n="tests/stubs";break;case"fixtures":n="tests/fixtures";break;case"providers":n="src/providers";break;case"facades":n="src/facades";break;case"routes":n="src/routes"}return(0,t.jsxs)("div",{className:s.hoverCardContainer,children:[(0,t.jsx)("a",{className:s.hoverCardLink,href:`/docs/the-basics/helpers#path${e.father}`,children:(0,t.jsxs)("code",{children:["Path.",e.father,"(",e.child?`'${e.child}'`:"",")"]})}),(0,t.jsx)("div",{className:s.hoverCard,children:(0,t.jsxs)("p",{style:{margin:0},children:["./",n,e.child?`/${e.child}`:""]})})]})}},8453:(e,n,r)=>{r.d(n,{R:()=>i,x:()=>a});var s=r(6540);const t={},c=s.createContext(t);function i(e){const n=s.useContext(c);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:i(e.components),s.createElement(c.Provider,{value:n},e.children)}}}]);
\ No newline at end of file
diff --git a/assets/js/runtime~main.cf6a7cff.js b/assets/js/runtime~main.2bb103db.js
similarity index 99%
rename from assets/js/runtime~main.cf6a7cff.js
rename to assets/js/runtime~main.2bb103db.js
index dcba89d4..266ccd48 100644
--- a/assets/js/runtime~main.cf6a7cff.js
+++ b/assets/js/runtime~main.2bb103db.js
@@ -1 +1 @@
-(()=>{"use strict";var e,a,c,r,d,f={},t={};function b(e){var a=t[e];if(void 0!==a)return a.exports;var c=t[e]={exports:{}};return f[e].call(c.exports,c,c.exports,b),c.exports}b.m=f,e=[],b.O=(a,c,r,d)=>{if(!c){var f=1/0;for(n=0;nWhen using schedulers classes you are able to use the @Inject()
-annotation to inject dependencies from you application within your
+annotation to inject dependencies from your application within your
scheduler class:
import { Inject } from '@athenna/ioc'
import { Scheduler, type Context } from '@athenna/cron'
import { RecentUserService } from '#src/services/RecentUserService'
@Scheduler({ pattern: '0 0 * * *' })
export class DeleteRecentUsers {
@Inject()
public recentUserService: RecentUserService
public async handler(ctx: Context) {
await this.recentUserService.deleteAll()
}
}
You can also use the automatic constructor injection if
-your don't want to use the @Inject()
annotation:
@Inject()
annotation:
import { Scheduler, type Context } from '@athenna/cron'
import type { RecentUserService } from '#src/services/RecentUserService'
@Scheduler({ pattern: '0 0 * * *' })
export class DeleteRecentUsers {
public recentUserService: RecentUserService
public constructor(recentUserService: RecentUserService) {
this.recentUserService = recentUserService
}
public async handler(ctx: Context) {
await this.recentUserService.deleteAll()
}
}