Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(application-generic): move shared services to application-generic package #3088

Conversation

LetItRock
Copy link
Contributor

What change does this PR introduce?

Moved some shared services to the application-generic package:

  • caching service
  • performance
  • storage

Why was this change needed?

We want to move the jobs processing logic into a separate service that will be easier to dynamically scale based on the queue size.

Other information (Screenshots)

@LetItRock LetItRock self-assigned this Mar 27, 2023
@linear
Copy link

linear bot commented Mar 27, 2023

@@ -11,7 +11,7 @@ import {
UserRepository,
} from '@novu/dal';
import { AuthProviderEnum, IJwtPayload, ISubscriberJwt, MemberRoleEnum, SignUpOriginEnum } from '@novu/shared';
import { AnalyticsService } from '@novu/application-generic';
import { AnalyticsService, CacheKeyPrefixEnum, Cached } from '@novu/application-generic';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved caching service and all the interceptors to the application-generic package

import { CancelDelayed, CancelDelayedCommand } from './usecases/cancel-delayed';
import { SendMessageCommand, SendTestEmail, SendTestEmailCommand } from './usecases/send-message';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SendMessageCommand was unused

import { Injectable, Logger } from '@nestjs/common';
import * as Sentry from '@sentry/node';
import { JobEntity, JobRepository, NotificationTemplateEntity, NotificationTemplateRepository } from '@novu/dal';
import { ChannelTypeEnum, InAppProviderIdEnum, STEP_TYPE_TO_CHANNEL_TYPE } from '@novu/shared';
import { EventsPerformanceService } from '@novu/application-generic';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

events performance service was also moved to application-generic package

Comment on lines -116 to -121
{
provide: PerformanceService,
useFactory: () => {
return new PerformanceService();
},
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the PerformanceService is not injected into any other services in the constructor, so no need to add it to the Nest DI context

@@ -20,7 +20,8 @@
"lint": "eslint src",
"lint:fix": "pnpm lint -- --fix",
"test": "cross-env TS_NODE_COMPILER_OPTIONS='{\"strictNullChecks\": false}' TZ=UTC NODE_ENV=test E2E_RUNNER=true mocha --timeout 10000 --require ts-node/register --exit --file e2e/setup.ts src/**/**/*.spec.ts",
"test:e2e": "cross-env TS_NODE_COMPILER_OPTIONS='{\"strictNullChecks\": false}' TZ=UTC NODE_ENV=test E2E_RUNNER=true mocha --timeout 10000 --require ts-node/register --exit --file e2e/setup.ts src/**/*.e2e.ts"
"test:e2e": "cross-env TS_NODE_COMPILER_OPTIONS='{\"strictNullChecks\": false}' TZ=UTC NODE_ENV=test E2E_RUNNER=true mocha --timeout 10000 --require ts-node/register --exit --file e2e/setup.ts src/**/*.e2e.ts",
"test:performance": "cross-env TS_NODE_COMPILER_OPTIONS='{\"strictNullChecks\": false}' TZ=UTC NODE_ENV=test E2E_RUNNER=true mocha --timeout 10000 --require ts-node/register --exit --file e2e/setup.ts performance/**/*.performance.ts src/**/*.performance.ts"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied from the API package

import { CachingConfig, ICacheService } from './cache.service';

describe('cache-service', function () {
let cacheService: ICacheService;
before(function () {

beforeEach(function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to rewrite it to jest test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djabarovgeorge just to get your second eyes here

keyPrefix: this.config.keyPrefix ?? this.DEFAULT_KEY_PREFIX,
tls: this.config.tls,
});
this.client = new Redis(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems quite harsh change, do we have different prettier config here? (width)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've found the problem, the ESLint config has 'max-len': ['warn', { code: 140 }], and Prettier "printWidth": 120,
So it looks like when the code is not formatted and is committed to Git the ESLint prefers its own rules ;)

@@ -0,0 +1,245 @@
import { File } from '@google-cloud/storage';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to rewrite it to jest test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we should continue to use mocha here and rewrite the old tests to use mocha aswell. But maybe not now. Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it will be more consistent with the rest...

Copy link
Contributor

@scopsy scopsy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work, added a few comments

@@ -31,7 +26,7 @@ describe('Performance - Events', () => {
let subscriber: SubscriberEntity;
let subscriberService: SubscribersService;
const jobRepository = new JobRepository();
let workflowQueueProducerService: WorkflowQueueProducerService;
let workflowQueueService: WorkflowQueueService;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you previous change is reverted? Or is it ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file was moved from the API folder where the queue service I called WorkflowQueueProducerService, but in this package worker-service it's called WorkflowQueueService :)

import { CachingConfig, ICacheService } from './cache.service';

describe('cache-service', function () {
let cacheService: ICacheService;
before(function () {

beforeEach(function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djabarovgeorge just to get your second eyes here

keyPrefix: this.config.keyPrefix ?? this.DEFAULT_KEY_PREFIX,
tls: this.config.tls,
});
this.client = new Redis(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems quite harsh change, do we have different prettier config here? (width)

@@ -0,0 +1,245 @@
import { File } from '@google-cloud/storage';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we should continue to use mocha here and rewrite the old tests to use mocha aswell. But maybe not now. Wdyt?

Base automatically changed from nv-1893-move-job-processing-logic to nv-1892-jobs-processing-service April 4, 2023 12:30
@LetItRock LetItRock merged commit b8b612c into nv-1892-jobs-processing-service Apr 4, 2023
@LetItRock LetItRock deleted the nv-1916-move-shared-services-to-application-generic-folder branch April 4, 2023 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants