mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
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:
parent
2ce992ed00
commit
74067f23bd
@ -3,6 +3,7 @@ module.exports = {
|
|||||||
const debug = require('@tryghost/debug')('mediaInliner');
|
const debug = require('@tryghost/debug')('mediaInliner');
|
||||||
const MediaInliner = require('@tryghost/external-media-inliner');
|
const MediaInliner = require('@tryghost/external-media-inliner');
|
||||||
const models = require('../../models');
|
const models = require('../../models');
|
||||||
|
const jobsService = require('../jobs');
|
||||||
|
|
||||||
const mediaStorage = require('../../adapters/storage').getStorage('media');
|
const mediaStorage = require('../../adapters/storage').getStorage('media');
|
||||||
const imageStorage = require('../../adapters/storage').getStorage('images');
|
const imageStorage = require('../../adapters/storage').getStorage('images');
|
||||||
@ -27,7 +28,7 @@ module.exports = {
|
|||||||
|
|
||||||
this.api = {
|
this.api = {
|
||||||
|
|
||||||
startMediaInliner: (domains) => {
|
startMediaInliner: async (domains) => {
|
||||||
if (!domains || !domains.length) {
|
if (!domains || !domains.length) {
|
||||||
// default domains to inline from if none are provided
|
// default domains to inline from if none are provided
|
||||||
domains = [
|
domains = [
|
||||||
@ -38,9 +39,16 @@ module.exports = {
|
|||||||
|
|
||||||
debug('[Inliner] Starting media inlining job for domains: ', domains);
|
debug('[Inliner] Starting media inlining job for domains: ', domains);
|
||||||
|
|
||||||
// @NOTE: the inlining should become an offloaded job
|
// @NOTE: the job is "inline" (aka non-offloaded into a thread), because usecases are currently
|
||||||
// startMediaInliner: mediaInliner.inlineMedia
|
// limited to migrational, so there is no expectations for site's availability etc.
|
||||||
mediaInliner.inline(domains);
|
await jobsService.addJob({
|
||||||
|
name: 'external-media-inliner',
|
||||||
|
job: (data) => {
|
||||||
|
return mediaInliner.inline(data.domains);
|
||||||
|
},
|
||||||
|
data: {domains},
|
||||||
|
offloaded: false
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: 'success'
|
status: 'success'
|
||||||
|
Loading…
Reference in New Issue
Block a user