Skip to content

Commit

Permalink
Remove zomby bulk imports
Browse files Browse the repository at this point in the history
  • Loading branch information
pozylon committed Oct 31, 2024
1 parent 5a1193a commit 17e2635
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/plugins/src/worker/bulk-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import JSONStream from 'JSONStream';
import { EventIterator } from 'event-iterator';
import { UnchainedCore } from '@unchainedshop/types/core.js';

const logger = createLogger('unchained:platform:bulk-import');
const logger = createLogger('unchained:worker:bulk-import');

const streamPayloadToBulkImporter = async (bulkImporter, payloadId, unchainedAPI: UnchainedCore) => {
logger.profile(`parseAsync`, { level: LogLevel.Verbose, message: 'parseAsync' });
Expand Down
6 changes: 2 additions & 4 deletions packages/plugins/src/worker/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { IWorkerAdapter } from '@unchainedshop/types/worker.js';
import open from 'open';
import nodemailer from 'nodemailer';

const logger = createLogger('unchained:plugins:worker:email');
const logger = createLogger('unchained:worker:email');

export const checkEmailInterceptionEnabled = () => {
return process.env.NODE_ENV !== 'production' && !process.env.UNCHAINED_DISABLE_EMAIL_INTERCEPTION;
Expand Down Expand Up @@ -73,8 +73,6 @@ const EmailWorkerPlugin: IWorkerAdapter<
type: 'EMAIL',

doWork: async ({ from, to, subject, ...rest }) => {
logger.debug(`${EmailWorkerPlugin.key} -> doWork: ${from} -> ${to} (${subject})`);

if (!to) {
return {
success: false,
Expand All @@ -93,7 +91,7 @@ const EmailWorkerPlugin: IWorkerAdapter<
...rest,
};
if (checkEmailInterceptionEnabled()) {
logger.verbose('unchained:platform -> Mailman detected an outgoing email');
logger.verbose('Mailman detected an outgoing email');
await openInBrowser(sendMailOptions);
return { success: true, result: { intercepted: true } };
}
Expand Down
4 changes: 0 additions & 4 deletions packages/plugins/src/worker/http-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ const HttpRequestWorkerPlugin: IWorkerAdapter<
type: 'HTTP_REQUEST',

async doWork({ url, data = {}, headers, method = 'POST' } = { method: 'POST' }) {
log(`${this.key} -> doWork: ${method} ${url} ${data}`, {
level: LogLevel.Debug,
});

if (!url) {
return {
success: false,
Expand Down
3 changes: 1 addition & 2 deletions packages/plugins/src/worker/push-notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import webPush from 'web-push';

const { PUSH_NOTIFICATION_PUBLIC_KEY, PUSH_NOTIFICATION_PRIVATE_KEY } = process.env;

const logger = createLogger('unchained:plugins:worker:push-notification');
const logger = createLogger('unchained:worker:push-notification');

type NotificationOptions = {
vapidDetails: {
Expand Down Expand Up @@ -38,7 +38,6 @@ const PushNotificationWorkerPlugin: IWorkerAdapter<
type: 'PUSH',

doWork: async ({ subscription, subject, payload, urgency = null, topic = null }) => {
logger.debug(`${PushNotificationWorkerPlugin.key} -> doWork: Push -> ${subject}`);
if (!PUSH_NOTIFICATION_PUBLIC_KEY)
return {
success: false,
Expand Down
4 changes: 1 addition & 3 deletions packages/plugins/src/worker/sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Twilio from 'twilio';

const { TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_SMS_FROM } = process.env;

const logger = createLogger('unchained:plugins:worker:sms');
const logger = createLogger('unchained:worker:sms');

/* Potential: no need for twilio npm
curl -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json" \
Expand All @@ -32,8 +32,6 @@ const SmsWorkerPlugin: IWorkerAdapter<
type: 'SMS',

doWork: async ({ from, to, text }) => {
logger.debug(`${SmsWorkerPlugin.key} -> doWork: ${from} -> ${to}`);

if (!TWILIO_SMS_FROM && !from) {
return {
success: false,
Expand Down
24 changes: 19 additions & 5 deletions packages/plugins/src/worker/zombie-killer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { IWorkerAdapter } from '@unchainedshop/types/worker.js';
import { WorkerDirector, WorkerAdapter } from '@unchainedshop/core-worker';
import { createLogger } from '@unchainedshop/logger';

const logger = createLogger('unchained:platform:zombie-killer');
const logger = createLogger('unchained:worker:zombie-killer');

export const ZombieKillerWorker: IWorkerAdapter<
never,
{ bulkImportMaxAgeInDays: number },
{
deletedProductMediaCount: number;
deletedAssortmentMediaCount: number;
deletedFilesCount: number;
deletedFilterTextsCount: number;
deletedProductTextsCount: number;
deletedProductVariationsCount: number;
deletedAssortmentTextsCount: number;
}
> = {
...WorkerAdapter,
Expand All @@ -19,7 +23,7 @@ export const ZombieKillerWorker: IWorkerAdapter<
version: '1.0.0',
type: 'ZOMBIE_KILLER',

doWork: async (_, unchainedAPI) => {
doWork: async ({ bulkImportMaxAgeInDays } = { bulkImportMaxAgeInDays: 5 }, unchainedAPI) => {
const { modules, services } = unchainedAPI;

try {
Expand Down Expand Up @@ -82,8 +86,18 @@ export const ZombieKillerWorker: IWorkerAdapter<
)
).map((a) => a._id);

const fileIdsToRemove = allFileIdsRelevant.filter((fileId) => {
return !allFileIdsLinked.includes(fileId);
const fileIdsToRemove =
allFileIdsRelevant.filter((fileId) => {
return !allFileIdsLinked.includes(fileId);
}) || [];

// Remove bulk import streams older than X days
const bulkImportMedia = await await modules.files.findFiles({
path: 'bulk-import-streams',
created: { $lt: new Date(Date.now() - 1000 * 60 * 60 * 24 * bulkImportMaxAgeInDays) },
});
bulkImportMedia.forEach(async (media) => {
fileIdsToRemove.push(media._id);
});

logger.verbose(`File Id's to remove: ${fileIdsToRemove.join(', ')}`);
Expand Down

0 comments on commit 17e2635

Please sign in to comment.