diff options
-rw-r--r-- | server/controllers/api/server/debug.ts | 6 | ||||
-rw-r--r-- | server/helpers/database-utils.ts | 10 | ||||
-rw-r--r-- | server/tests/api/videos/resumable-upload.ts | 5 | ||||
-rw-r--r-- | shared/extra-utils/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/server/debug-command.ts | 32 | ||||
-rw-r--r-- | shared/extra-utils/server/debug.ts | 33 | ||||
-rw-r--r-- | shared/extra-utils/server/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/server/jobs.ts | 9 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 3 | ||||
-rw-r--r-- | shared/models/server/debug.model.ts | 1 |
10 files changed, 51 insertions, 50 deletions
diff --git a/server/controllers/api/server/debug.ts b/server/controllers/api/server/debug.ts index a6e9147f3..31888e963 100644 --- a/server/controllers/api/server/debug.ts +++ b/server/controllers/api/server/debug.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import * as express from 'express' | ||
1 | import { InboxManager } from '@server/lib/activitypub/inbox-manager' | 2 | import { InboxManager } from '@server/lib/activitypub/inbox-manager' |
2 | import { RemoveDanglingResumableUploadsScheduler } from '@server/lib/schedulers/remove-dangling-resumable-uploads-scheduler' | 3 | import { RemoveDanglingResumableUploadsScheduler } from '@server/lib/schedulers/remove-dangling-resumable-uploads-scheduler' |
4 | import { Debug, SendDebugCommand } from '@shared/models' | ||
3 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 5 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
4 | import { SendDebugCommand } from '@shared/models' | ||
5 | import * as express from 'express' | ||
6 | import { UserRight } from '../../../../shared/models/users' | 6 | import { UserRight } from '../../../../shared/models/users' |
7 | import { authenticate, ensureUserHasRight } from '../../../middlewares' | 7 | import { authenticate, ensureUserHasRight } from '../../../middlewares' |
8 | 8 | ||
@@ -32,7 +32,7 @@ function getDebug (req: express.Request, res: express.Response) { | |||
32 | return res.json({ | 32 | return res.json({ |
33 | ip: req.ip, | 33 | ip: req.ip, |
34 | activityPubMessagesWaiting: InboxManager.Instance.getActivityPubMessagesWaiting() | 34 | activityPubMessagesWaiting: InboxManager.Instance.getActivityPubMessagesWaiting() |
35 | }) | 35 | } as Debug) |
36 | } | 36 | } |
37 | 37 | ||
38 | async function runCommand (req: express.Request, res: express.Response) { | 38 | async function runCommand (req: express.Request, res: express.Response) { |
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index b5dc70c17..cbd7aa401 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts | |||
@@ -6,7 +6,7 @@ import { sequelizeTypescript } from '@server/initializers/database' | |||
6 | import { logger } from './logger' | 6 | import { logger } from './logger' |
7 | 7 | ||
8 | function retryTransactionWrapper <T, A, B, C, D> ( | 8 | function retryTransactionWrapper <T, A, B, C, D> ( |
9 | functionToRetry: (arg1: A, arg2: B, arg3: C, arg4: D) => Promise<T> | Bluebird<T>, | 9 | functionToRetry: (arg1: A, arg2: B, arg3: C, arg4: D) => Promise<T>, |
10 | arg1: A, | 10 | arg1: A, |
11 | arg2: B, | 11 | arg2: B, |
12 | arg3: C, | 12 | arg3: C, |
@@ -14,20 +14,20 @@ function retryTransactionWrapper <T, A, B, C, D> ( | |||
14 | ): Promise<T> | 14 | ): Promise<T> |
15 | 15 | ||
16 | function retryTransactionWrapper <T, A, B, C> ( | 16 | function retryTransactionWrapper <T, A, B, C> ( |
17 | functionToRetry: (arg1: A, arg2: B, arg3: C) => Promise<T> | Bluebird<T>, | 17 | functionToRetry: (arg1: A, arg2: B, arg3: C) => Promise<T>, |
18 | arg1: A, | 18 | arg1: A, |
19 | arg2: B, | 19 | arg2: B, |
20 | arg3: C | 20 | arg3: C |
21 | ): Promise<T> | 21 | ): Promise<T> |
22 | 22 | ||
23 | function retryTransactionWrapper <T, A, B> ( | 23 | function retryTransactionWrapper <T, A, B> ( |
24 | functionToRetry: (arg1: A, arg2: B) => Promise<T> | Bluebird<T>, | 24 | functionToRetry: (arg1: A, arg2: B) => Promise<T>, |
25 | arg1: A, | 25 | arg1: A, |
26 | arg2: B | 26 | arg2: B |
27 | ): Promise<T> | 27 | ): Promise<T> |
28 | 28 | ||
29 | function retryTransactionWrapper <T, A> ( | 29 | function retryTransactionWrapper <T, A> ( |
30 | functionToRetry: (arg1: A) => Promise<T> | Bluebird<T>, | 30 | functionToRetry: (arg1: A) => Promise<T>, |
31 | arg1: A | 31 | arg1: A |
32 | ): Promise<T> | 32 | ): Promise<T> |
33 | 33 | ||
@@ -36,7 +36,7 @@ function retryTransactionWrapper <T> ( | |||
36 | ): Promise<T> | 36 | ): Promise<T> |
37 | 37 | ||
38 | function retryTransactionWrapper <T> ( | 38 | function retryTransactionWrapper <T> ( |
39 | functionToRetry: (...args: any[]) => Promise<T> | Bluebird<T>, | 39 | functionToRetry: (...args: any[]) => Promise<T>, |
40 | ...args: any[] | 40 | ...args: any[] |
41 | ): Promise<T> { | 41 | ): Promise<T> { |
42 | return transactionRetryer<T>(callback => { | 42 | return transactionRetryer<T>(callback => { |
diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 4fc3317df..6c01c7e78 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts | |||
@@ -12,7 +12,6 @@ import { | |||
12 | flushAndRunServer, | 12 | flushAndRunServer, |
13 | getMyUserInformation, | 13 | getMyUserInformation, |
14 | prepareResumableUpload, | 14 | prepareResumableUpload, |
15 | sendDebugCommand, | ||
16 | sendResumableChunks, | 15 | sendResumableChunks, |
17 | ServerInfo, | 16 | ServerInfo, |
18 | setAccessTokensToServers, | 17 | setAccessTokensToServers, |
@@ -138,13 +137,13 @@ describe('Test resumable upload', function () { | |||
138 | }) | 137 | }) |
139 | 138 | ||
140 | it('Should not delete recent uploads', async function () { | 139 | it('Should not delete recent uploads', async function () { |
141 | await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' }) | 140 | await server.debugCommand.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } }) |
142 | 141 | ||
143 | expect(await countResumableUploads()).to.equal(2) | 142 | expect(await countResumableUploads()).to.equal(2) |
144 | }) | 143 | }) |
145 | 144 | ||
146 | it('Should delete old uploads', async function () { | 145 | it('Should delete old uploads', async function () { |
147 | await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' }) | 146 | await server.debugCommand.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } }) |
148 | 147 | ||
149 | expect(await countResumableUploads()).to.equal(0) | 148 | expect(await countResumableUploads()).to.equal(0) |
150 | }) | 149 | }) |
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 9e0f6374a..7b5835e47 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts | |||
@@ -15,7 +15,6 @@ export * from './search' | |||
15 | 15 | ||
16 | export * from './server/clients' | 16 | export * from './server/clients' |
17 | export * from './server/config' | 17 | export * from './server/config' |
18 | export * from './server/debug' | ||
19 | export * from './server/follows' | 18 | export * from './server/follows' |
20 | export * from './server/jobs' | 19 | export * from './server/jobs' |
21 | export * from './server/plugins' | 20 | export * from './server/plugins' |
diff --git a/shared/extra-utils/server/debug-command.ts b/shared/extra-utils/server/debug-command.ts new file mode 100644 index 000000000..eecbb1711 --- /dev/null +++ b/shared/extra-utils/server/debug-command.ts | |||
@@ -0,0 +1,32 @@ | |||
1 | import { Debug, SendDebugCommand } from '@shared/models' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class DebugCommand extends AbstractCommand { | ||
6 | |||
7 | getDebug (options: OverrideCommandOptions = {}) { | ||
8 | const path = '/api/v1/server/debug' | ||
9 | |||
10 | return this.getRequestBody<Debug>({ | ||
11 | ...options, | ||
12 | |||
13 | path, | ||
14 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
15 | }) | ||
16 | } | ||
17 | |||
18 | sendCommand (options: OverrideCommandOptions & { | ||
19 | body: SendDebugCommand | ||
20 | }) { | ||
21 | const { body } = options | ||
22 | const path = '/api/v1/server/debug/run-command' | ||
23 | |||
24 | return this.postBodyRequest({ | ||
25 | ...options, | ||
26 | |||
27 | path, | ||
28 | fields: body, | ||
29 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
30 | }) | ||
31 | } | ||
32 | } | ||
diff --git a/shared/extra-utils/server/debug.ts b/shared/extra-utils/server/debug.ts deleted file mode 100644 index f196812b7..000000000 --- a/shared/extra-utils/server/debug.ts +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | import { makeGetRequest, makePostBodyRequest } from '../requests/requests' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { SendDebugCommand } from '@shared/models' | ||
4 | |||
5 | function getDebug (url: string, token: string) { | ||
6 | const path = '/api/v1/server/debug' | ||
7 | |||
8 | return makeGetRequest({ | ||
9 | url, | ||
10 | path, | ||
11 | token, | ||
12 | statusCodeExpected: HttpStatusCode.OK_200 | ||
13 | }) | ||
14 | } | ||
15 | |||
16 | function sendDebugCommand (url: string, token: string, body: SendDebugCommand) { | ||
17 | const path = '/api/v1/server/debug/run-command' | ||
18 | |||
19 | return makePostBodyRequest({ | ||
20 | url, | ||
21 | path, | ||
22 | token, | ||
23 | fields: body, | ||
24 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | ||
25 | }) | ||
26 | } | ||
27 | |||
28 | // --------------------------------------------------------------------------- | ||
29 | |||
30 | export { | ||
31 | getDebug, | ||
32 | sendDebugCommand | ||
33 | } | ||
diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index 4121c8828..f0071ba72 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts | |||
@@ -1 +1,2 @@ | |||
1 | export * from './contact-form-command' | 1 | export * from './contact-form-command' |
2 | export * from './debug-command' | ||
diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index 763374e03..a3683913a 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
3 | import { getDebug, makeGetRequest } from '../../../shared/extra-utils' | 3 | import { makeGetRequest } from '../../../shared/extra-utils' |
4 | import { Job, JobState, JobType, ServerDebug } from '../../models' | 4 | import { Job, JobState, JobType } from '../../models' |
5 | import { wait } from '../miscs/miscs' | 5 | import { wait } from '../miscs/miscs' |
6 | import { ServerInfo } from './servers' | 6 | import { ServerInfo } from './servers' |
7 | 7 | ||
@@ -90,9 +90,8 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { | |||
90 | tasks.push(p) | 90 | tasks.push(p) |
91 | } | 91 | } |
92 | 92 | ||
93 | const p = getDebug(server.url, server.accessToken) | 93 | const p = server.debugCommand.getDebug() |
94 | .then(res => res.body) | 94 | .then(obj => { |
95 | .then((obj: ServerDebug) => { | ||
96 | if (obj.activityPubMessagesWaiting !== 0) { | 95 | if (obj.activityPubMessagesWaiting !== 0) { |
97 | pendingRequests = true | 96 | pendingRequests = true |
98 | } | 97 | } |
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index b58639ba6..30e712ab8 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -17,6 +17,7 @@ import { OverviewsCommand } from '../overviews' | |||
17 | import { makeGetRequest } from '../requests/requests' | 17 | import { makeGetRequest } from '../requests/requests' |
18 | import { SearchCommand } from '../search' | 18 | import { SearchCommand } from '../search' |
19 | import { ContactFormCommand } from './contact-form-command' | 19 | import { ContactFormCommand } from './contact-form-command' |
20 | import { DebugCommand } from './debug-command' | ||
20 | 21 | ||
21 | interface ServerInfo { | 22 | interface ServerInfo { |
22 | app: ChildProcess | 23 | app: ChildProcess |
@@ -79,6 +80,7 @@ interface ServerInfo { | |||
79 | overviewsCommand?: OverviewsCommand | 80 | overviewsCommand?: OverviewsCommand |
80 | searchCommand?: SearchCommand | 81 | searchCommand?: SearchCommand |
81 | contactFormCommand?: ContactFormCommand | 82 | contactFormCommand?: ContactFormCommand |
83 | debugCommand?: DebugCommand | ||
82 | } | 84 | } |
83 | 85 | ||
84 | function parallelTests () { | 86 | function parallelTests () { |
@@ -293,6 +295,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
293 | server.overviewsCommand = new OverviewsCommand(server) | 295 | server.overviewsCommand = new OverviewsCommand(server) |
294 | server.searchCommand = new SearchCommand(server) | 296 | server.searchCommand = new SearchCommand(server) |
295 | server.contactFormCommand = new ContactFormCommand(server) | 297 | server.contactFormCommand = new ContactFormCommand(server) |
298 | server.debugCommand = new DebugCommand(server) | ||
296 | 299 | ||
297 | res(server) | 300 | res(server) |
298 | }) | 301 | }) |
diff --git a/shared/models/server/debug.model.ts b/shared/models/server/debug.model.ts index 7ceff9137..2ecabdeca 100644 --- a/shared/models/server/debug.model.ts +++ b/shared/models/server/debug.model.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | export interface Debug { | 1 | export interface Debug { |
2 | ip: string | 2 | ip: string |
3 | activityPubMessagesWaiting: number | ||
3 | } | 4 | } |
4 | 5 | ||
5 | export interface SendDebugCommand { | 6 | export interface SendDebugCommand { |