-
Notifications
You must be signed in to change notification settings - Fork 13.6k
feat: agenda Jobs admin page #40699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Khizarshah01
wants to merge
18
commits into
RocketChat:develop
Choose a base branch
from
Khizarshah01:feat/agenda-jobs-admin
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: agenda Jobs admin page #40699
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9f97bb2
feat: create cronjobs model and typings
Khizarshah01 678e28d
feat: implement cronjobs service and status derivation logic
Khizarshah01 63e4dd1
feat: added cron.jobs api endpoint
Khizarshah01 342df5a
feat: added cron.appjobs api endpoint
Khizarshah01 63bd57d
feat: added cron.history api endpoint
Khizarshah01 9dea259
feat: add pagination to cron API endpoints
Khizarshah01 60a71ed
refactor: rewrite the endpoint into new way AJV schema
Khizarshah01 57baa54
feat: added enable and disable api endpoint
Khizarshah01 4a1b58e
feat: added cron.trigger job api endpoint
Khizarshah01 15ad020
feat: added history logging for system and app jobs
Khizarshah01 ddc1a6d
feat: added history logging for omnichannel schedulers
Khizarshah01 bc7db57
feat: added permission manage-scheduled-jobs for endpoints
Khizarshah01 ab78bd0
fix: remove unique constraint and fix cron history index order
Khizarshah01 bd67e2d
feat: add i18n translation keys
Khizarshah01 bc1629e
refactor: implement strict AJV schemas for cron jobs API
Khizarshah01 4bfde0d
test: add integration and unit tests for cron jobs
Khizarshah01 ba88d56
chore: fix prettier and import order linting errors
Khizarshah01 ce6b0a3
chore: fix formatting in packages
Khizarshah01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,232 @@ | ||
| import { CronJobsSvc } from '@rocket.chat/core-services'; | ||
| import type { ICronJobItem, ICronHistoryItem } from '@rocket.chat/core-typings'; | ||
| import { ajv, ajvQuery, validateUnauthorizedErrorResponse, validateBadRequestErrorResponse } from '@rocket.chat/rest-typings'; | ||
|
|
||
| import type { ExtractRoutesFromAPI } from '../ApiClass'; | ||
| import { API } from '../api'; | ||
| import { getPaginationItems } from '../helpers/getPaginationItems'; | ||
|
|
||
| const isCronJobsListParams = ajvQuery.compile<{ | ||
| offset?: number; | ||
| count?: number; | ||
| }>({ | ||
| type: 'object', | ||
| properties: { | ||
| offset: { type: 'number', nullable: true }, | ||
| count: { type: 'number', nullable: true }, | ||
| }, | ||
| additionalProperties: false, | ||
| }); | ||
|
|
||
| const isCronJobsActionParams = ajv.compile<{ | ||
| jobName: string; | ||
| }>({ | ||
| type: 'object', | ||
| properties: { | ||
| jobName: { type: 'string' }, | ||
| }, | ||
| required: ['jobName'], | ||
| additionalProperties: false, | ||
| }); | ||
|
|
||
| const isCronJobsHistoryParams = ajvQuery.compile<{ | ||
| jobName: string; | ||
| offset?: number; | ||
| count?: number; | ||
| }>({ | ||
| type: 'object', | ||
| properties: { | ||
| jobName: { type: 'string' }, | ||
| offset: { type: 'number' }, | ||
| count: { type: 'number' }, | ||
| }, | ||
| required: ['jobName'], | ||
| additionalProperties: false, | ||
| }); | ||
|
|
||
| const isCronJobsListResponse = ajv.compile<{ jobs: ICronJobItem[]; count: number; offset: number; total: number; success: boolean }>({ | ||
| type: 'object', | ||
| properties: { | ||
| jobs: { type: 'array' }, | ||
| count: { type: 'number' }, | ||
| offset: { type: 'number' }, | ||
| total: { type: 'number' }, | ||
| success: { type: 'boolean', enum: [true] }, | ||
| }, | ||
| required: ['jobs', 'count', 'offset', 'total', 'success'], | ||
| additionalProperties: false, | ||
| }); | ||
|
|
||
| const isCronJobsHistoryResponse = ajv.compile<{ | ||
| history: ICronHistoryItem[]; | ||
| count: number; | ||
| offset: number; | ||
| total: number; | ||
| success: boolean; | ||
| }>({ | ||
| type: 'object', | ||
| properties: { | ||
| history: { type: 'array' }, | ||
| count: { type: 'number' }, | ||
| offset: { type: 'number' }, | ||
| total: { type: 'number' }, | ||
| success: { type: 'boolean', enum: [true] }, | ||
| }, | ||
| required: ['history', 'count', 'offset', 'total', 'success'], | ||
| additionalProperties: false, | ||
| }); | ||
|
|
||
| const isCronJobsActionResponse = ajv.compile<void>({ | ||
| type: 'object', | ||
| properties: { | ||
| success: { type: 'boolean', enum: [true] }, | ||
| }, | ||
| required: ['success'], | ||
| additionalProperties: false, | ||
| }); | ||
|
|
||
| const cronJobsEndpoints = API.v1 | ||
| .get( | ||
| 'cron.jobs', | ||
| { | ||
| authRequired: true, | ||
| permissionsRequired: ['manage-scheduled-jobs'], | ||
| query: isCronJobsListParams, | ||
| response: { | ||
| 200: isCronJobsListResponse, | ||
| 401: validateUnauthorizedErrorResponse, | ||
| }, | ||
| }, | ||
| async function action() { | ||
| const { offset, count } = await getPaginationItems(this.queryParams); | ||
| const { jobs, total } = await CronJobsSvc.getCoreJobs({ offset, count }); | ||
|
|
||
| return API.v1.success({ | ||
| jobs, | ||
| count: jobs.length, | ||
| offset, | ||
| total, | ||
| }); | ||
| }, | ||
| ) | ||
| .get( | ||
| 'cron.appjobs', | ||
| { | ||
| authRequired: true, | ||
| permissionsRequired: ['manage-scheduled-jobs'], | ||
| query: isCronJobsListParams, | ||
| response: { | ||
| 200: isCronJobsListResponse, | ||
| 401: validateUnauthorizedErrorResponse, | ||
| }, | ||
| }, | ||
| async function action() { | ||
| const { offset, count } = await getPaginationItems(this.queryParams); | ||
| const { jobs, total } = await CronJobsSvc.getAppJobs({ offset, count }); | ||
|
|
||
| return API.v1.success({ | ||
| jobs, | ||
| count: jobs.length, | ||
| offset, | ||
| total, | ||
| }); | ||
| }, | ||
| ) | ||
| .get( | ||
| 'cron.history', | ||
| { | ||
| authRequired: true, | ||
| permissionsRequired: ['manage-scheduled-jobs'], | ||
| query: isCronJobsHistoryParams, | ||
| response: { | ||
| 200: isCronJobsHistoryResponse, | ||
| 401: validateUnauthorizedErrorResponse, | ||
| }, | ||
| }, | ||
| async function action() { | ||
| const { offset, count } = await getPaginationItems(this.queryParams); | ||
| const { jobName } = this.queryParams; | ||
| const { history, total } = await CronJobsSvc.getHistory(jobName, { offset, count }); | ||
|
|
||
| return API.v1.success({ | ||
| history, | ||
| count: history.length, | ||
| offset, | ||
| total, | ||
| }); | ||
| }, | ||
| ) | ||
| .post( | ||
| 'cron.enable', | ||
| { | ||
| authRequired: true, | ||
| permissionsRequired: ['manage-scheduled-jobs'], | ||
| body: isCronJobsActionParams, | ||
| response: { | ||
| 200: isCronJobsActionResponse, | ||
| 400: validateBadRequestErrorResponse, | ||
| 401: validateUnauthorizedErrorResponse, | ||
| }, | ||
| }, | ||
| async function action() { | ||
| const { jobName } = this.bodyParams; | ||
| const success = await CronJobsSvc.enable(jobName); | ||
|
|
||
| if (!success) { | ||
| return API.v1.failure('error-job-not-found'); | ||
| } | ||
| return API.v1.success(); | ||
| }, | ||
| ) | ||
| .post( | ||
| 'cron.disable', | ||
| { | ||
| authRequired: true, | ||
| permissionsRequired: ['manage-scheduled-jobs'], | ||
| body: isCronJobsActionParams, | ||
| response: { | ||
| 200: isCronJobsActionResponse, | ||
| 400: validateBadRequestErrorResponse, | ||
| 401: validateUnauthorizedErrorResponse, | ||
| }, | ||
| }, | ||
| async function action() { | ||
| const { jobName } = this.bodyParams; | ||
| const success = await CronJobsSvc.disable(jobName); | ||
|
|
||
| if (!success) { | ||
| return API.v1.failure('error-job-not-found'); | ||
| } | ||
| return API.v1.success(); | ||
| }, | ||
| ) | ||
| .post( | ||
| 'cron.trigger', | ||
| { | ||
| authRequired: true, | ||
| permissionsRequired: ['manage-scheduled-jobs'], | ||
| body: isCronJobsActionParams, | ||
| response: { | ||
| 200: isCronJobsActionResponse, | ||
| 400: validateBadRequestErrorResponse, | ||
| 401: validateUnauthorizedErrorResponse, | ||
| }, | ||
| }, | ||
| async function action() { | ||
| const { jobName } = this.bodyParams; | ||
| const success = await CronJobsSvc.trigger(jobName); | ||
|
|
||
| if (!success) { | ||
| return API.v1.failure('error-job-not-found'); | ||
| } | ||
|
|
||
| return API.v1.success(); | ||
| }, | ||
| ); | ||
|
|
||
| export type CronJobsEndpoints = ExtractRoutesFromAPI<typeof cronJobsEndpoints>; | ||
|
|
||
| declare module '@rocket.chat/rest-typings' { | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface | ||
| interface Endpoints extends CronJobsEndpoints {} | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Substantial duplicated endpoint logic across cron.enable, cron.disable, and cron.trigger increases maintenance drift risk. All three share identical auth/permission/body/response configuration and identical action handler error-handling structure, differing only in the service method called. Consider consolidating via a shared handler factory.
Prompt for AI agents