From 74067f23bd3498db314b208fa9c733a646e2560a Mon Sep 17 00:00:00 2001 From: Naz Date: Mon, 6 Mar 2023 17:10:02 +0800 Subject: [PATCH] Moved the media inliner into a job refs https://github.com/TryGhost/Toolbox/issues/523 - Media inlining is a long running piece of logic that suits perfectly for a job. It is not as critical to be offloaded into a separate thread at this point, so leaving it as "inline" while the feature is in experimental stage. --- .../server/services/media-inliner/service.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ghost/core/core/server/services/media-inliner/service.js b/ghost/core/core/server/services/media-inliner/service.js index 47a6d90c63..5ed7bd1a1c 100644 --- a/ghost/core/core/server/services/media-inliner/service.js +++ b/ghost/core/core/server/services/media-inliner/service.js @@ -3,6 +3,7 @@ module.exports = { const debug = require('@tryghost/debug')('mediaInliner'); const MediaInliner = require('@tryghost/external-media-inliner'); const models = require('../../models'); + const jobsService = require('../jobs'); const mediaStorage = require('../../adapters/storage').getStorage('media'); const imageStorage = require('../../adapters/storage').getStorage('images'); @@ -27,7 +28,7 @@ module.exports = { this.api = { - startMediaInliner: (domains) => { + startMediaInliner: async (domains) => { if (!domains || !domains.length) { // default domains to inline from if none are provided domains = [ @@ -38,9 +39,16 @@ module.exports = { debug('[Inliner] Starting media inlining job for domains: ', domains); - // @NOTE: the inlining should become an offloaded job - // startMediaInliner: mediaInliner.inlineMedia - mediaInliner.inline(domains); + // @NOTE: the job is "inline" (aka non-offloaded into a thread), because usecases are currently + // limited to migrational, so there is no expectations for site's availability etc. + await jobsService.addJob({ + name: 'external-media-inliner', + job: (data) => { + return mediaInliner.inline(data.domains); + }, + data: {domains}, + offloaded: false + }); return { status: 'success'