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.
This commit is contained in:
Naz 2023-03-06 17:10:02 +08:00
parent 2ce992ed00
commit 74067f23bd
No known key found for this signature in database

View File

@ -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'