Introduce debug command
This commit is contained in:
parent
a9c58393d3
commit
883a901908
|
@ -1,8 +1,8 @@
|
||||||
|
import * as express from 'express'
|
||||||
import { InboxManager } from '@server/lib/activitypub/inbox-manager'
|
import { InboxManager } from '@server/lib/activitypub/inbox-manager'
|
||||||
import { RemoveDanglingResumableUploadsScheduler } from '@server/lib/schedulers/remove-dangling-resumable-uploads-scheduler'
|
import { RemoveDanglingResumableUploadsScheduler } from '@server/lib/schedulers/remove-dangling-resumable-uploads-scheduler'
|
||||||
|
import { Debug, SendDebugCommand } from '@shared/models'
|
||||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||||
import { SendDebugCommand } from '@shared/models'
|
|
||||||
import * as express from 'express'
|
|
||||||
import { UserRight } from '../../../../shared/models/users'
|
import { UserRight } from '../../../../shared/models/users'
|
||||||
import { authenticate, ensureUserHasRight } from '../../../middlewares'
|
import { authenticate, ensureUserHasRight } from '../../../middlewares'
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ function getDebug (req: express.Request, res: express.Response) {
|
||||||
return res.json({
|
return res.json({
|
||||||
ip: req.ip,
|
ip: req.ip,
|
||||||
activityPubMessagesWaiting: InboxManager.Instance.getActivityPubMessagesWaiting()
|
activityPubMessagesWaiting: InboxManager.Instance.getActivityPubMessagesWaiting()
|
||||||
})
|
} as Debug)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runCommand (req: express.Request, res: express.Response) {
|
async function runCommand (req: express.Request, res: express.Response) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { sequelizeTypescript } from '@server/initializers/database'
|
||||||
import { logger } from './logger'
|
import { logger } from './logger'
|
||||||
|
|
||||||
function retryTransactionWrapper <T, A, B, C, D> (
|
function retryTransactionWrapper <T, A, B, C, D> (
|
||||||
functionToRetry: (arg1: A, arg2: B, arg3: C, arg4: D) => Promise<T> | Bluebird<T>,
|
functionToRetry: (arg1: A, arg2: B, arg3: C, arg4: D) => Promise<T>,
|
||||||
arg1: A,
|
arg1: A,
|
||||||
arg2: B,
|
arg2: B,
|
||||||
arg3: C,
|
arg3: C,
|
||||||
|
@ -14,20 +14,20 @@ function retryTransactionWrapper <T, A, B, C, D> (
|
||||||
): Promise<T>
|
): Promise<T>
|
||||||
|
|
||||||
function retryTransactionWrapper <T, A, B, C> (
|
function retryTransactionWrapper <T, A, B, C> (
|
||||||
functionToRetry: (arg1: A, arg2: B, arg3: C) => Promise<T> | Bluebird<T>,
|
functionToRetry: (arg1: A, arg2: B, arg3: C) => Promise<T>,
|
||||||
arg1: A,
|
arg1: A,
|
||||||
arg2: B,
|
arg2: B,
|
||||||
arg3: C
|
arg3: C
|
||||||
): Promise<T>
|
): Promise<T>
|
||||||
|
|
||||||
function retryTransactionWrapper <T, A, B> (
|
function retryTransactionWrapper <T, A, B> (
|
||||||
functionToRetry: (arg1: A, arg2: B) => Promise<T> | Bluebird<T>,
|
functionToRetry: (arg1: A, arg2: B) => Promise<T>,
|
||||||
arg1: A,
|
arg1: A,
|
||||||
arg2: B
|
arg2: B
|
||||||
): Promise<T>
|
): Promise<T>
|
||||||
|
|
||||||
function retryTransactionWrapper <T, A> (
|
function retryTransactionWrapper <T, A> (
|
||||||
functionToRetry: (arg1: A) => Promise<T> | Bluebird<T>,
|
functionToRetry: (arg1: A) => Promise<T>,
|
||||||
arg1: A
|
arg1: A
|
||||||
): Promise<T>
|
): Promise<T>
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ function retryTransactionWrapper <T> (
|
||||||
): Promise<T>
|
): Promise<T>
|
||||||
|
|
||||||
function retryTransactionWrapper <T> (
|
function retryTransactionWrapper <T> (
|
||||||
functionToRetry: (...args: any[]) => Promise<T> | Bluebird<T>,
|
functionToRetry: (...args: any[]) => Promise<T>,
|
||||||
...args: any[]
|
...args: any[]
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
return transactionRetryer<T>(callback => {
|
return transactionRetryer<T>(callback => {
|
||||||
|
|
|
@ -12,7 +12,6 @@ import {
|
||||||
flushAndRunServer,
|
flushAndRunServer,
|
||||||
getMyUserInformation,
|
getMyUserInformation,
|
||||||
prepareResumableUpload,
|
prepareResumableUpload,
|
||||||
sendDebugCommand,
|
|
||||||
sendResumableChunks,
|
sendResumableChunks,
|
||||||
ServerInfo,
|
ServerInfo,
|
||||||
setAccessTokensToServers,
|
setAccessTokensToServers,
|
||||||
|
@ -138,13 +137,13 @@ describe('Test resumable upload', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not delete recent uploads', async function () {
|
it('Should not delete recent uploads', async function () {
|
||||||
await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' })
|
await server.debugCommand.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } })
|
||||||
|
|
||||||
expect(await countResumableUploads()).to.equal(2)
|
expect(await countResumableUploads()).to.equal(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should delete old uploads', async function () {
|
it('Should delete old uploads', async function () {
|
||||||
await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' })
|
await server.debugCommand.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } })
|
||||||
|
|
||||||
expect(await countResumableUploads()).to.equal(0)
|
expect(await countResumableUploads()).to.equal(0)
|
||||||
})
|
})
|
||||||
|
|
|
@ -15,7 +15,6 @@ export * from './search'
|
||||||
|
|
||||||
export * from './server/clients'
|
export * from './server/clients'
|
||||||
export * from './server/config'
|
export * from './server/config'
|
||||||
export * from './server/debug'
|
|
||||||
export * from './server/follows'
|
export * from './server/follows'
|
||||||
export * from './server/jobs'
|
export * from './server/jobs'
|
||||||
export * from './server/plugins'
|
export * from './server/plugins'
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
import { Debug, SendDebugCommand } from '@shared/models'
|
||||||
|
import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
|
||||||
|
import { AbstractCommand, OverrideCommandOptions } from '../shared'
|
||||||
|
|
||||||
|
export class DebugCommand extends AbstractCommand {
|
||||||
|
|
||||||
|
getDebug (options: OverrideCommandOptions = {}) {
|
||||||
|
const path = '/api/v1/server/debug'
|
||||||
|
|
||||||
|
return this.getRequestBody<Debug>({
|
||||||
|
...options,
|
||||||
|
|
||||||
|
path,
|
||||||
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
sendCommand (options: OverrideCommandOptions & {
|
||||||
|
body: SendDebugCommand
|
||||||
|
}) {
|
||||||
|
const { body } = options
|
||||||
|
const path = '/api/v1/server/debug/run-command'
|
||||||
|
|
||||||
|
return this.postBodyRequest({
|
||||||
|
...options,
|
||||||
|
|
||||||
|
path,
|
||||||
|
fields: body,
|
||||||
|
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,33 +0,0 @@
|
||||||
import { makeGetRequest, makePostBodyRequest } from '../requests/requests'
|
|
||||||
import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
|
|
||||||
import { SendDebugCommand } from '@shared/models'
|
|
||||||
|
|
||||||
function getDebug (url: string, token: string) {
|
|
||||||
const path = '/api/v1/server/debug'
|
|
||||||
|
|
||||||
return makeGetRequest({
|
|
||||||
url,
|
|
||||||
path,
|
|
||||||
token,
|
|
||||||
statusCodeExpected: HttpStatusCode.OK_200
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendDebugCommand (url: string, token: string, body: SendDebugCommand) {
|
|
||||||
const path = '/api/v1/server/debug/run-command'
|
|
||||||
|
|
||||||
return makePostBodyRequest({
|
|
||||||
url,
|
|
||||||
path,
|
|
||||||
token,
|
|
||||||
fields: body,
|
|
||||||
statusCodeExpected: HttpStatusCode.NO_CONTENT_204
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export {
|
|
||||||
getDebug,
|
|
||||||
sendDebugCommand
|
|
||||||
}
|
|
|
@ -1 +1,2 @@
|
||||||
export * from './contact-form-command'
|
export * from './contact-form-command'
|
||||||
|
export * from './debug-command'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import * as request from 'supertest'
|
import * as request from 'supertest'
|
||||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||||
import { getDebug, makeGetRequest } from '../../../shared/extra-utils'
|
import { makeGetRequest } from '../../../shared/extra-utils'
|
||||||
import { Job, JobState, JobType, ServerDebug } from '../../models'
|
import { Job, JobState, JobType } from '../../models'
|
||||||
import { wait } from '../miscs/miscs'
|
import { wait } from '../miscs/miscs'
|
||||||
import { ServerInfo } from './servers'
|
import { ServerInfo } from './servers'
|
||||||
|
|
||||||
|
@ -90,9 +90,8 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) {
|
||||||
tasks.push(p)
|
tasks.push(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
const p = getDebug(server.url, server.accessToken)
|
const p = server.debugCommand.getDebug()
|
||||||
.then(res => res.body)
|
.then(obj => {
|
||||||
.then((obj: ServerDebug) => {
|
|
||||||
if (obj.activityPubMessagesWaiting !== 0) {
|
if (obj.activityPubMessagesWaiting !== 0) {
|
||||||
pendingRequests = true
|
pendingRequests = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { OverviewsCommand } from '../overviews'
|
||||||
import { makeGetRequest } from '../requests/requests'
|
import { makeGetRequest } from '../requests/requests'
|
||||||
import { SearchCommand } from '../search'
|
import { SearchCommand } from '../search'
|
||||||
import { ContactFormCommand } from './contact-form-command'
|
import { ContactFormCommand } from './contact-form-command'
|
||||||
|
import { DebugCommand } from './debug-command'
|
||||||
|
|
||||||
interface ServerInfo {
|
interface ServerInfo {
|
||||||
app: ChildProcess
|
app: ChildProcess
|
||||||
|
@ -79,6 +80,7 @@ interface ServerInfo {
|
||||||
overviewsCommand?: OverviewsCommand
|
overviewsCommand?: OverviewsCommand
|
||||||
searchCommand?: SearchCommand
|
searchCommand?: SearchCommand
|
||||||
contactFormCommand?: ContactFormCommand
|
contactFormCommand?: ContactFormCommand
|
||||||
|
debugCommand?: DebugCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
function parallelTests () {
|
function parallelTests () {
|
||||||
|
@ -293,6 +295,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
|
||||||
server.overviewsCommand = new OverviewsCommand(server)
|
server.overviewsCommand = new OverviewsCommand(server)
|
||||||
server.searchCommand = new SearchCommand(server)
|
server.searchCommand = new SearchCommand(server)
|
||||||
server.contactFormCommand = new ContactFormCommand(server)
|
server.contactFormCommand = new ContactFormCommand(server)
|
||||||
|
server.debugCommand = new DebugCommand(server)
|
||||||
|
|
||||||
res(server)
|
res(server)
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
export interface Debug {
|
export interface Debug {
|
||||||
ip: string
|
ip: string
|
||||||
|
activityPubMessagesWaiting: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SendDebugCommand {
|
export interface SendDebugCommand {
|
||||||
|
|
Loading…
Reference in New Issue