diff --git a/x-pack/legacy/plugins/reporting/common/get_absolute_url.ts b/x-pack/legacy/plugins/reporting/common/get_absolute_url.ts index 79c5a274d8c77..1d34189abcb24 100644 --- a/x-pack/legacy/plugins/reporting/common/get_absolute_url.ts +++ b/x-pack/legacy/plugins/reporting/common/get_absolute_url.ts @@ -5,10 +5,9 @@ */ import url from 'url'; -import { oncePerServer } from '../server/lib/once_per_server'; import { ServerFacade } from '../types'; -function getAbsoluteUrlFn(server: ServerFacade) { +export function getAbsoluteUrlFactory(server: ServerFacade) { const config = server.config(); return function getAbsoluteUrl({ @@ -27,5 +26,3 @@ function getAbsoluteUrlFn(server: ServerFacade) { }); }; } - -export const getAbsoluteUrlFactory = oncePerServer(getAbsoluteUrlFn); diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/server/create_job.ts b/x-pack/legacy/plugins/reporting/export_types/csv/server/create_job.ts index f9542279f52d9..7cfed0d09a4fb 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/server/create_job.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv/server/create_job.ts @@ -4,12 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { oncePerServer } from '../../../server/lib/once_per_server'; import { cryptoFactory } from '../../../server/lib/crypto'; -import { ConditionalHeaders, CreateJobFactory, ServerFacade, RequestFacade } from '../../../types'; -import { JobParamsDiscoverCsv, ESQueueCreateJobFnDiscoverCsv } from '../types'; +import { ConditionalHeaders, ServerFacade, RequestFacade } from '../../../types'; +import { JobParamsDiscoverCsv } from '../types'; -function createJobFn(server: ServerFacade) { +export const createJobFactory = function createJobFn(server: ServerFacade) { const crypto = cryptoFactory(server); return async function createJob( @@ -32,8 +31,4 @@ function createJobFn(server: ServerFacade) { ...jobParams, }; }; -} - -export const createJobFactory: CreateJobFactory = oncePerServer( - createJobFn as (server: ServerFacade) => ESQueueCreateJobFnDiscoverCsv -); +}; diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/server/execute_job.js b/x-pack/legacy/plugins/reporting/export_types/csv/server/execute_job.js index ff49daced4a65..19656a94c6a46 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/server/execute_job.js +++ b/x-pack/legacy/plugins/reporting/export_types/csv/server/execute_job.js @@ -5,12 +5,12 @@ */ import { CSV_JOB_TYPE, PLUGIN_ID } from '../../../common/constants'; -import { cryptoFactory, oncePerServer, LevelLogger } from '../../../server/lib'; +import { cryptoFactory, LevelLogger } from '../../../server/lib'; import { createGenerateCsv } from './lib/generate_csv'; import { fieldFormatMapFactory } from './lib/field_format_map'; import { i18n } from '@kbn/i18n'; -function executeJobFn(server) { +export function executeJobFactory(server) { const { callWithRequest } = server.plugins.elasticsearch.getCluster('data'); const crypto = cryptoFactory(server); const config = server.config(); @@ -126,5 +126,3 @@ function executeJobFn(server) { }; }; } - -export const executeJobFactory = oncePerServer(executeJobFn); diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/create_job.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/create_job.ts index 0bcfc6f1ca07c..a3e531d16a2e6 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/create_job.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/create_job.ts @@ -7,8 +7,8 @@ import { notFound, notImplemented } from 'boom'; import { get } from 'lodash'; import { PLUGIN_ID, CSV_FROM_SAVEDOBJECT_JOB_TYPE } from '../../../../common/constants'; -import { cryptoFactory, LevelLogger, oncePerServer } from '../../../../server/lib'; -import { ServerFacade, RequestFacade } from '../../../../types'; +import { cryptoFactory, LevelLogger } from '../../../../server/lib'; +import { ImmediateCreateJobFn, ServerFacade, RequestFacade } from '../../../../types'; import { SavedObject, SavedObjectServiceError, @@ -27,13 +27,7 @@ interface VisData { panel: SearchPanel; } -type CreateJobFn = ( - jobParams: JobParamsPanelCsv, - headers: any, - req: RequestFacade -) => Promise; - -function createJobFn(server: ServerFacade): CreateJobFn { +export function createJobFactory(server: ServerFacade): ImmediateCreateJobFn { const crypto = cryptoFactory(server); const logger = LevelLogger.createForServer(server, [ PLUGIN_ID, @@ -100,5 +94,3 @@ function createJobFn(server: ServerFacade): CreateJobFn { }; }; } - -export const createJobFactory = oncePerServer(createJobFn); diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/execute_job.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/execute_job.ts index 9d4bcf1e4b27a..d2284b73c7673 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/execute_job.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/execute_job.ts @@ -5,11 +5,11 @@ */ import { i18n } from '@kbn/i18n'; -import { cryptoFactory, LevelLogger, oncePerServer } from '../../../server/lib'; +import { cryptoFactory, LevelLogger } from '../../../server/lib'; import { + ImmediateExecuteFn, JobDocOutputExecuted, ServerFacade, - ExecuteImmediateJobFactory, RequestFacade, } from '../../../types'; import { @@ -17,16 +17,16 @@ import { CSV_FROM_SAVEDOBJECT_JOB_TYPE, PLUGIN_ID, } from '../../../common/constants'; -import { CsvResultFromSearch, JobDocPayloadPanelCsv, FakeRequest } from '../types'; +import { + CsvResultFromSearch, + JobParamsPanelCsv, + SearchPanel, + JobDocPayloadPanelCsv, + FakeRequest, +} from '../types'; import { createGenerateCsv } from './lib'; -type ExecuteJobFn = ( - jobId: string | null, - job: JobDocPayloadPanelCsv, - realRequest?: RequestFacade -) => Promise; - -function executeJobFactoryFn(server: ServerFacade): ExecuteJobFn { +export function executeJobFactory(server: ServerFacade): ImmediateExecuteFn { const crypto = cryptoFactory(server); const logger = LevelLogger.createForServer(server, [ PLUGIN_ID, @@ -45,7 +45,14 @@ function executeJobFactoryFn(server: ServerFacade): ExecuteJobFn { const jobLogger = logger.clone([jobId === null ? 'immediate' : jobId]); const { jobParams } = job; - const { isImmediate, panel, visType } = jobParams; + const { isImmediate, panel, visType } = jobParams as JobParamsPanelCsv & { panel: SearchPanel }; + + if (!panel) { + i18n.translate( + 'xpack.reporting.exportTypes.csv_from_savedobject.executeJob.failedToAccessPanel', + { defaultMessage: 'Failed to access panel metadata for job execution' } + ); + } jobLogger.debug(`Execute job generating [${visType}] csv`); @@ -112,7 +119,3 @@ function executeJobFactoryFn(server: ServerFacade): ExecuteJobFn { }; }; } - -export const executeJobFactory: ExecuteImmediateJobFactory = oncePerServer( - executeJobFactoryFn as ExecuteImmediateJobFactory -); diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_job_params_from_request.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_job_params_from_request.ts index 774e430d593cd..8e5440b700d1e 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_job_params_from_request.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_job_params_from_request.ts @@ -10,7 +10,7 @@ import { JobParamsPostPayloadPanelCsv, JobParamsPanelCsv } from '../../types'; export function getJobParamsFromRequest( request: RequestFacade, opts: { isImmediate: boolean } -): Partial { +): JobParamsPanelCsv { const { savedObjectType, savedObjectId } = request.params; const { timerange, state } = request.payload as JobParamsPostPayloadPanelCsv; const post = timerange || state ? { timerange, state } : undefined; diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/types.d.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/types.d.ts index 72caf551d2a3d..a90b7e713e3ef 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/types.d.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/types.d.ts @@ -20,14 +20,13 @@ export interface JobParamsPanelCsv { savedObjectType: string; savedObjectId: string; isImmediate: boolean; - panel: SearchPanel; + panel?: SearchPanel; post?: JobParamsPostPayloadPanelCsv; visType?: string; } export interface JobDocPayloadPanelCsv extends JobDocPayload { type: string | null; - objects: null; jobParams: JobParamsPanelCsv; } diff --git a/x-pack/legacy/plugins/reporting/export_types/png/server/create_job/index.ts b/x-pack/legacy/plugins/reporting/export_types/png/server/create_job/index.ts index f1008a4866fd7..a5b6c37b20c18 100644 --- a/x-pack/legacy/plugins/reporting/export_types/png/server/create_job/index.ts +++ b/x-pack/legacy/plugins/reporting/export_types/png/server/create_job/index.ts @@ -4,18 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - ServerFacade, - RequestFacade, - ConditionalHeaders, - CreateJobFactory, -} from '../../../../types'; +import { ServerFacade, RequestFacade, ConditionalHeaders } from '../../../../types'; import { validateUrls } from '../../../../common/validate_urls'; import { cryptoFactory } from '../../../../server/lib/crypto'; -import { oncePerServer } from '../../../../server/lib/once_per_server'; -import { JobParamsPNG, ESQueueCreateJobFnPNG } from '../../types'; +import { JobParamsPNG } from '../../types'; -function createJobFn(server: ServerFacade) { +export const createJobFactory = function createJobFn(server: ServerFacade) { const crypto = cryptoFactory(server); return async function createJob( @@ -38,8 +32,4 @@ function createJobFn(server: ServerFacade) { forceNow: new Date().toISOString(), }; }; -} - -export const createJobFactory: CreateJobFactory = oncePerServer( - createJobFn as (server: ServerFacade) => ESQueueCreateJobFnPNG -); +}; diff --git a/x-pack/legacy/plugins/reporting/export_types/png/server/execute_job/index.js b/x-pack/legacy/plugins/reporting/export_types/png/server/execute_job/index.js index 2642d88983ecf..7c6ca8520c51e 100644 --- a/x-pack/legacy/plugins/reporting/export_types/png/server/execute_job/index.js +++ b/x-pack/legacy/plugins/reporting/export_types/png/server/execute_job/index.js @@ -8,7 +8,7 @@ import * as Rx from 'rxjs'; import { i18n } from '@kbn/i18n'; import { mergeMap, catchError, map, takeUntil } from 'rxjs/operators'; import { PLUGIN_ID, PNG_JOB_TYPE } from '../../../../common/constants'; -import { LevelLogger, oncePerServer } from '../../../../server/lib'; +import { LevelLogger } from '../../../../server/lib'; import { generatePngObservableFactory } from '../lib/generate_png'; import { decryptJobHeaders, @@ -17,7 +17,7 @@ import { getFullUrls, } from '../../../common/execute_job/'; -function executeJobFn(server) { +export function executeJobFactory(server) { const generatePngObservable = generatePngObservableFactory(server); const logger = LevelLogger.createForServer(server, [PLUGIN_ID, PNG_JOB_TYPE, 'execute']); @@ -67,5 +67,3 @@ function executeJobFn(server) { return process$.pipe(takeUntil(stop$)).toPromise(); }; } - -export const executeJobFactory = oncePerServer(executeJobFn); diff --git a/x-pack/legacy/plugins/reporting/export_types/png/server/lib/generate_png.ts b/x-pack/legacy/plugins/reporting/export_types/png/server/lib/generate_png.ts index 5980f1884ab2f..81b37ecf74f73 100644 --- a/x-pack/legacy/plugins/reporting/export_types/png/server/lib/generate_png.ts +++ b/x-pack/legacy/plugins/reporting/export_types/png/server/lib/generate_png.ts @@ -8,7 +8,6 @@ import * as Rx from 'rxjs'; import { toArray, mergeMap } from 'rxjs/operators'; import { LevelLogger } from '../../../../server/lib'; import { ServerFacade, ConditionalHeaders } from '../../../../types'; -import { oncePerServer } from '../../../../server/lib/once_per_server'; import { screenshotsObservableFactory } from '../../../common/lib/screenshots'; import { PreserveLayout } from '../../../common/layouts/preserve_layout'; import { LayoutParams } from '../../../common/layouts/layout'; @@ -21,7 +20,7 @@ interface UrlScreenshot { screenshots: ScreenshotData[]; } -function generatePngObservableFn(server: ServerFacade) { +export function generatePngObservableFactory(server: ServerFacade) { const screenshotsObservable = screenshotsObservableFactory(server); const captureConcurrency = 1; @@ -68,5 +67,3 @@ function generatePngObservableFn(server: ServerFacade) { ); }; } - -export const generatePngObservableFactory = oncePerServer(generatePngObservableFn); diff --git a/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/create_job/index.js b/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/create_job/index.js index 1fb980396c8d3..d6c6eb7eb2007 100644 --- a/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/create_job/index.js +++ b/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/create_job/index.js @@ -6,11 +6,11 @@ import { PLUGIN_ID, PDF_JOB_TYPE } from '../../../../common/constants'; import { validateUrls } from '../../../../common/validate_urls'; -import { LevelLogger, oncePerServer } from '../../../../server/lib'; +import { LevelLogger } from '../../../../server/lib'; import { cryptoFactory } from '../../../../server/lib/crypto'; import { compatibilityShimFactory } from './compatibility_shim'; -function createJobFactoryFn(server) { +export function createJobFactory(server) { const logger = LevelLogger.createForServer(server, [PLUGIN_ID, PDF_JOB_TYPE, 'create']); const compatibilityShim = compatibilityShimFactory(server, logger); const crypto = cryptoFactory(server); @@ -36,5 +36,3 @@ function createJobFactoryFn(server) { }; }); } - -export const createJobFactory = oncePerServer(createJobFactoryFn); diff --git a/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.js b/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.js index d340a09728ca7..d55ee95ff215b 100644 --- a/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.js +++ b/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.js @@ -8,7 +8,7 @@ import * as Rx from 'rxjs'; import { mergeMap, catchError, map, takeUntil } from 'rxjs/operators'; import { i18n } from '@kbn/i18n'; import { PLUGIN_ID, PDF_JOB_TYPE } from '../../../../common/constants'; -import { LevelLogger, oncePerServer } from '../../../../server/lib'; +import { LevelLogger } from '../../../../server/lib'; import { generatePdfObservableFactory } from '../lib/generate_pdf'; import { decryptJobHeaders, @@ -18,7 +18,7 @@ import { getCustomLogo, } from '../../../common/execute_job/'; -function executeJobFn(server) { +export function executeJobFactory(server) { const generatePdfObservable = generatePdfObservableFactory(server); const logger = LevelLogger.createForServer(server, [PLUGIN_ID, PDF_JOB_TYPE, 'execute']); @@ -71,5 +71,3 @@ function executeJobFn(server) { return process$.pipe(takeUntil(stop$)).toPromise(); }; } - -export const executeJobFactory = oncePerServer(executeJobFn); diff --git a/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/lib/generate_pdf.ts b/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/lib/generate_pdf.ts index 0d2243acfef9b..52e867cc471ce 100644 --- a/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/lib/generate_pdf.ts +++ b/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/lib/generate_pdf.ts @@ -11,7 +11,6 @@ import { LevelLogger } from '../../../../server/lib'; import { ServerFacade, ConditionalHeaders } from '../../../../types'; // @ts-ignore untyped module import { pdf } from './pdf'; -import { oncePerServer } from '../../../../server/lib/once_per_server'; import { screenshotsObservableFactory } from '../../../common/lib/screenshots'; import { createLayout } from '../../../common/layouts'; import { TimeRange } from '../../../common/lib/screenshots/types'; @@ -38,7 +37,7 @@ const getTimeRange = (urlScreenshots: UrlScreenshot[]) => { return null; }; -function generatePdfObservableFn(server: ServerFacade) { +export function generatePdfObservableFactory(server: ServerFacade) { const screenshotsObservable = screenshotsObservableFactory(server); const captureConcurrency = 1; @@ -87,5 +86,3 @@ function generatePdfObservableFn(server: ServerFacade) { ); }; } - -export const generatePdfObservableFactory = oncePerServer(generatePdfObservableFn); diff --git a/x-pack/legacy/plugins/reporting/server/lib/create_queue.ts b/x-pack/legacy/plugins/reporting/server/lib/create_queue.ts index a7e81093c136a..174c6d587e523 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/create_queue.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/create_queue.ts @@ -9,12 +9,11 @@ import { ServerFacade, QueueConfig } from '../../types'; // @ts-ignore import { Esqueue } from './esqueue'; import { createWorkerFactory } from './create_worker'; -import { oncePerServer } from './once_per_server'; import { LevelLogger } from './level_logger'; // @ts-ignore import { createTaggedLogger } from './create_tagged_logger'; // TODO remove createTaggedLogger once esqueue is removed -function createQueueFn(server: ServerFacade): Esqueue { +export function createQueueFactory(server: ServerFacade): Esqueue { const queueConfig: QueueConfig = server.config().get('xpack.reporting.queue'); const index = server.config().get('xpack.reporting.index'); @@ -45,5 +44,3 @@ function createQueueFn(server: ServerFacade): Esqueue { return queue; } - -export const createQueueFactory = oncePerServer(createQueueFn); diff --git a/x-pack/legacy/plugins/reporting/server/lib/create_worker.ts b/x-pack/legacy/plugins/reporting/server/lib/create_worker.ts index 1cfc967cb31d1..0a86f9d1d4ff5 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/create_worker.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/create_worker.ts @@ -21,9 +21,8 @@ import { // @ts-ignore untyped dependency import { events as esqueueEvents } from './esqueue'; import { LevelLogger } from './level_logger'; -import { oncePerServer } from './once_per_server'; -function createWorkerFn(server: ServerFacade) { +export function createWorkerFactory(server: ServerFacade) { const config = server.config(); const logger = LevelLogger.createForServer(server, [PLUGIN_ID, 'queue-worker']); const queueConfig: QueueConfig = config.get('xpack.reporting.queue'); @@ -79,5 +78,3 @@ function createWorkerFn(server: ServerFacade) { }); }; } - -export const createWorkerFactory = oncePerServer(createWorkerFn); diff --git a/x-pack/legacy/plugins/reporting/server/lib/enqueue_job.ts b/x-pack/legacy/plugins/reporting/server/lib/enqueue_job.ts index c264c0ca7e0eb..9b1d7992283a5 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/enqueue_job.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/enqueue_job.ts @@ -7,8 +7,8 @@ import { get } from 'lodash'; // @ts-ignore import { events as esqueueEvents } from './esqueue'; -import { oncePerServer } from './once_per_server'; import { + Job, ServerFacade, RequestFacade, Logger, @@ -24,7 +24,7 @@ interface ConfirmedJob { _primary_term: number; } -function enqueueJobFn(server: ServerFacade) { +export function enqueueJobFactory(server: ServerFacade) { const config = server.config(); const captureConfig: CaptureConfig = config.get('xpack.reporting.capture'); const browserType = captureConfig.browser.type; @@ -37,9 +37,9 @@ function enqueueJobFn(server: ServerFacade) { exportTypeId: string, jobParams: object, user: string, - headers: ConditionalHeaders, + headers: ConditionalHeaders['headers'], request: RequestFacade - ) { + ): Promise { const logger = parentLogger.clone(['queue-job']); const exportType = exportTypesRegistry.getById(exportTypeId); const createJob = exportType.createJobFactory(server); @@ -65,5 +65,3 @@ function enqueueJobFn(server: ServerFacade) { }); }; } - -export const enqueueJobFactory = oncePerServer(enqueueJobFn); diff --git a/x-pack/legacy/plugins/reporting/server/lib/get_user.js b/x-pack/legacy/plugins/reporting/server/lib/get_user.js index 2c4f3bcb2dd36..04c9516cb99d4 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/get_user.js +++ b/x-pack/legacy/plugins/reporting/server/lib/get_user.js @@ -4,9 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { oncePerServer } from './once_per_server'; - -function getUserFn(server) { +export function getUserFactory(server) { return async request => { if (!server.plugins.security) { return null; @@ -20,5 +18,3 @@ function getUserFn(server) { } }; } - -export const getUserFactory = oncePerServer(getUserFn); diff --git a/x-pack/legacy/plugins/reporting/server/lib/jobs_query.js b/x-pack/legacy/plugins/reporting/server/lib/jobs_query.js index e4f501e2c9518..fef9a529f7a2c 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/jobs_query.js +++ b/x-pack/legacy/plugins/reporting/server/lib/jobs_query.js @@ -5,11 +5,10 @@ */ import { get } from 'lodash'; -import { oncePerServer } from './once_per_server'; const defaultSize = 10; -function jobsQueryFn(server) { +export function jobsQueryFactory(server) { const index = server.config().get('xpack.reporting.index'); const { callWithInternalUser, errors: esErrors } = server.plugins.elasticsearch.getCluster('admin'); @@ -138,5 +137,3 @@ function jobsQueryFn(server) { } }; } - -export const jobsQueryFactory = oncePerServer(jobsQueryFn); diff --git a/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject_immediate.ts b/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject_immediate.ts index 557f7c3702038..2303fddf555e0 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject_immediate.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject_immediate.ts @@ -12,10 +12,10 @@ import { ResponseFacade, ReportingResponseToolkit, Logger, - JobDocPayload, JobIDForImmediate, JobDocOutputExecuted, } from '../../types'; +import { JobDocPayloadPanelCsv } from '../../export_types/csv_from_savedobject/types'; import { getRouteOptionsCsv } from './lib/route_config_factories'; import { getJobParamsFromRequest } from '../../export_types/csv_from_savedobject/server/lib/get_job_params_from_request'; @@ -48,7 +48,11 @@ export function registerGenerateCsvFromSavedObjectImmediate( const jobParams = getJobParamsFromRequest(request, { isImmediate: true }); const createJobFn = createJobFactory(server); const executeJobFn = executeJobFactory(server); - const jobDocPayload: JobDocPayload = await createJobFn(jobParams, request.headers, request); + const jobDocPayload: JobDocPayloadPanelCsv = await createJobFn( + jobParams, + request.headers, + request + ); const { content_type: jobOutputContentType, content: jobOutputContent, diff --git a/x-pack/legacy/plugins/reporting/server/routes/lib/get_document_payload.ts b/x-pack/legacy/plugins/reporting/server/routes/lib/get_document_payload.ts index d3e9981a62b6e..9952cbb980778 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/lib/get_document_payload.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/lib/get_document_payload.ts @@ -13,7 +13,6 @@ import { JobDocExecuted, JobDocOutputExecuted, } from '../../../types'; -import { oncePerServer } from '../../lib/once_per_server'; import { CSV_JOB_TYPE } from '../../../common/constants'; interface ICustomHeaders { @@ -39,7 +38,7 @@ const getReportingHeaders = (output: JobDocOutputExecuted, exportType: ExportTyp return metaDataHeaders; }; -function getDocumentPayloadFn(server: ServerFacade) { +export function getDocumentPayloadFactory(server: ServerFacade) { const exportTypesRegistry = server.plugins.reporting!.exportTypesRegistry; function encodeContent(content: string | null, exportType: ExportTypeDefinition) { @@ -105,5 +104,3 @@ function getDocumentPayloadFn(server: ServerFacade) { return getIncomplete(status); }; } - -export const getDocumentPayloadFactory = oncePerServer(getDocumentPayloadFn); diff --git a/x-pack/legacy/plugins/reporting/server/routes/lib/job_response_handler.js b/x-pack/legacy/plugins/reporting/server/routes/lib/job_response_handler.js index 75bffcafc5c33..758c50816c381 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/lib/job_response_handler.js +++ b/x-pack/legacy/plugins/reporting/server/routes/lib/job_response_handler.js @@ -5,12 +5,11 @@ */ import boom from 'boom'; -import { oncePerServer } from '../../lib/once_per_server'; import { jobsQueryFactory } from '../../lib/jobs_query'; import { WHITELISTED_JOB_CONTENT_TYPES } from '../../../common/constants'; import { getDocumentPayloadFactory } from './get_document_payload'; -function jobResponseHandlerFn(server) { +export function jobResponseHandlerFactory(server) { const jobsQuery = jobsQueryFactory(server); const getDocumentPayload = getDocumentPayloadFactory(server); @@ -45,5 +44,3 @@ function jobResponseHandlerFn(server) { }); }; } - -export const jobResponseHandlerFactory = oncePerServer(jobResponseHandlerFn); diff --git a/x-pack/legacy/plugins/reporting/types.d.ts b/x-pack/legacy/plugins/reporting/types.d.ts index 6d2808c5b560d..7d05811ef4aa6 100644 --- a/x-pack/legacy/plugins/reporting/types.d.ts +++ b/x-pack/legacy/plugins/reporting/types.d.ts @@ -16,7 +16,12 @@ import { CancellationToken } from './common/cancellation_token'; import { HeadlessChromiumDriverFactory } from './server/browsers/chromium/driver_factory'; import { BrowserType } from './server/browsers/types'; -type Job = EventEmitter & { id: string }; +export type Job = EventEmitter & { + id: string; + toJSON: () => { + id: string; + }; +}; export interface ReportingPlugin { queue: { @@ -193,9 +198,10 @@ export interface JobParamPostPayload { export interface JobDocPayload { headers?: Record; - jobParams: object; + jobParams: any; title: string; type: string | null; + objects?: null | object[]; } export interface JobSource { @@ -245,11 +251,29 @@ export interface ESQueueWorker { on: (event: string, handler: any) => void; } +type JobParamsUrl = object; + +interface JobParamsSavedObject { + savedObjectType: string; + savedObjectId: string; + isImmediate: boolean; +} + export type ESQueueCreateJobFn = ( - jobParams: object, - headers: ConditionalHeaders, + jobParams: JobParamsSavedObject | JobParamsUrl, + headers: Record, request: RequestFacade -) => Promise; +) => Promise; + +export type ImmediateCreateJobFn = ( + jobParams: any, + headers: Record, + req: RequestFacade +) => Promise<{ + type: string | null; + title: string; + jobParams: any; +}>; export type ESQueueWorkerExecuteFn = ( jobId: string, @@ -258,9 +282,10 @@ export type ESQueueWorkerExecuteFn = ( ) => void; export type JobIDForImmediate = null; + export type ImmediateExecuteFn = ( jobId: JobIDForImmediate, - jobDocPayload: JobDocPayload, + job: JobDocPayload, request: RequestFacade ) => Promise; @@ -279,9 +304,8 @@ export interface ESQueueInstance { ) => ESQueueWorker; } -export type CreateJobFactory = (server: ServerFacade) => ESQueueCreateJobFn; -export type ExecuteJobFactory = (server: ServerFacade) => ESQueueWorkerExecuteFn; -export type ExecuteImmediateJobFactory = (server: ServerFacade) => ImmediateExecuteFn; +export type CreateJobFactory = (server: ServerFacade) => ESQueueCreateJobFn | ImmediateCreateJobFn; +export type ExecuteJobFactory = (server: ServerFacade) => ESQueueWorkerExecuteFn | ImmediateExecuteFn; // prettier-ignore export interface ExportTypeDefinition { id: string; @@ -290,7 +314,7 @@ export interface ExportTypeDefinition { jobContentEncoding?: string; jobContentExtension: string; createJobFactory: CreateJobFactory; - executeJobFactory: ExecuteJobFactory | ExecuteImmediateJobFactory; + executeJobFactory: ExecuteJobFactory; validLicenses: string[]; }