Skip to content

Commit 41f0a44

Browse files
committed
fix(jobs): change function to class
1 parent 529c194 commit 41f0a44

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/jobs/RoleJob.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@ import RoleService from 'controllers/Role/service'
22
import cron from 'node-cron'
33
import ConstRoles from 'constants/ConstRoles'
44

5-
// Run this job every 30 minutes
6-
const GetRoleTask = cron.schedule('30 * * * *', async () => {
7-
const data = await RoleService.getOne(ConstRoles.ID_UMUM)
8-
console.log('Running task check get role by id', { data })
9-
})
5+
class RoleJob {
6+
/**
7+
* Get Role Task
8+
*/
9+
public static getRole() {
10+
// Run this job every 30 minutes
11+
const task = cron.schedule('30 * * * *', async () => {
12+
const data = await RoleService.getOne(ConstRoles.ID_UMUM)
13+
console.log('Running task check get role by id', { data })
14+
})
1015

11-
export { GetRoleTask }
16+
return task
17+
}
18+
}
19+
20+
export default RoleJob

src/jobs/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import { GetRoleTask } from 'jobs/RoleJob'
1+
import RoleJob from 'jobs/RoleJob'
22

33
function initialJobs() {
44
// Role Jobs
5-
GetRoleTask.start()
5+
const getRoleTask = RoleJob.getRole()
6+
getRoleTask.start()
7+
8+
// Other Jobs
69
}
710

811
export default initialJobs

0 commit comments

Comments
 (0)