@messenger-box/cron-job-server-module 0.0.1-alpha.384
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/jest.config.js +26 -0
- package/lib/graphql/index.d.ts +1 -0
- package/lib/graphql/schema/index.d.ts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +672 -0
- package/lib/index.js.map +1 -0
- package/lib/interfaces/generated-models.d.ts +4506 -0
- package/lib/interfaces/index.d.ts +1 -0
- package/lib/module.d.ts +3 -0
- package/lib/plugins/index.d.ts +1 -0
- package/lib/plugins/messenger-notification-cron-moleculer-service.d.ts +10 -0
- package/package.json +62 -0
- package/src/config/env-config.ts +13 -0
- package/src/config/index.ts +1 -0
- package/src/graphql/index.ts +1 -0
- package/src/graphql/schema/index.ts +4 -0
- package/src/graphql/schema/messenger-notification-cron-moleculer-service.graphql +12 -0
- package/src/index.ts +1 -0
- package/src/interfaces/generated-models.ts +5168 -0
- package/src/interfaces/index.ts +1 -0
- package/src/module.ts +12 -0
- package/src/plugins/index.ts +1 -0
- package/src/plugins/messenger-notification-cron-moleculer-service.ts +60 -0
- package/tsconfig.json +12 -0
- package/webpack.config.js +64 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './generated-models';
|
package/src/module.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Feature } from '@common-stack/server-core';
|
|
2
|
+
import {
|
|
3
|
+
MessengerNotificationCronMoleculerService
|
|
4
|
+
} from './plugins';
|
|
5
|
+
import { schema } from './graphql';
|
|
6
|
+
|
|
7
|
+
export default new Feature({
|
|
8
|
+
schema,
|
|
9
|
+
addBrokerClientServiceClass: [
|
|
10
|
+
MessengerNotificationCronMoleculerService,
|
|
11
|
+
],
|
|
12
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './messenger-notification-cron-moleculer-service';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Service, ServiceBroker } from 'moleculer';
|
|
2
|
+
import {IMoleculerCronServiceName,IMessengerNotificationCronTaskName} from '../interfaces'
|
|
3
|
+
import {NotificationDurationUnitEnum,IMessengerNotificationService,TYPES} from '@messenger-box/platform-server'
|
|
4
|
+
import { Container } from 'inversify';
|
|
5
|
+
import { CommonType } from '@common-stack/core';
|
|
6
|
+
import CronTasks from '@skoropletov/moleculer-cron-tasks';
|
|
7
|
+
import { CdmLogger } from '@cdm-logger/core';
|
|
8
|
+
|
|
9
|
+
export class MessengerNotificationCronMoleculerService extends Service {
|
|
10
|
+
constructor(broker: ServiceBroker, { container }: { container: Container } & { settings: any }) {
|
|
11
|
+
super(broker);
|
|
12
|
+
this.container = container;
|
|
13
|
+
this.parseServiceSchema({
|
|
14
|
+
name: MessengerNotificationCronMoleculerService.name,
|
|
15
|
+
started() {
|
|
16
|
+
this.registerCronJobs(container);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private registerCronJobs(container: Container): void {
|
|
22
|
+
const logger: CdmLogger.ILogger = container.get(CommonType.LOGGER);
|
|
23
|
+
const messengerService: IMessengerNotificationService = container.get(TYPES.MessengerNotificationService);
|
|
24
|
+
this.broker.createService({
|
|
25
|
+
name: IMoleculerCronServiceName.MessengerNotificationCronJob,
|
|
26
|
+
mixins: [CronTasks],
|
|
27
|
+
tasks: [
|
|
28
|
+
{
|
|
29
|
+
name: `${IMessengerNotificationCronTaskName.SendNotificationOfUnreadMessages}`,
|
|
30
|
+
cronTime: '0 * * * *',
|
|
31
|
+
async callback() {
|
|
32
|
+
return messengerService.sendNotificationOfUnreadMessages(NotificationDurationUnitEnum.hours, 1);
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: `${IMessengerNotificationCronTaskName.SendNotificationOfAlertMessages}`,
|
|
37
|
+
cronTime: '*/10 * * * * *',
|
|
38
|
+
async callback() {
|
|
39
|
+
logger.debug('CronJob (sendNotificationOfAlertMessages) - running at', new Date());
|
|
40
|
+
await messengerService.sendNotificationOfAlertMessages(
|
|
41
|
+
NotificationDurationUnitEnum.seconds,
|
|
42
|
+
10,
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: `${IMessengerNotificationCronTaskName.SendNotificationOfUnreadServiceMessages}`,
|
|
48
|
+
cronTime: '0 */10 * * * *',
|
|
49
|
+
async callback() {
|
|
50
|
+
logger.debug('CronJob (sendNotificationOfUnreadServiceMessages) - running at', new Date());
|
|
51
|
+
await messengerService.sendNotificationOfUnreadServiceMessages(
|
|
52
|
+
NotificationDurationUnitEnum.minutes,
|
|
53
|
+
10,
|
|
54
|
+
);
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "./src",
|
|
5
|
+
"outDir": "lib",
|
|
6
|
+
"declarationDir": "lib",
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"resolveJsonModule": true
|
|
10
|
+
},
|
|
11
|
+
"exclude": ["node_modules", "lib", "dist", "webpack.config.js"]
|
|
12
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const nodeExternals = require('webpack-node-externals');
|
|
2
|
+
const webpack = require('webpack');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const webpackOpts = {
|
|
6
|
+
mode: 'development',
|
|
7
|
+
entry: {
|
|
8
|
+
index: './src/index.ts',
|
|
9
|
+
},
|
|
10
|
+
node: {
|
|
11
|
+
__dirname: true,
|
|
12
|
+
},
|
|
13
|
+
target: 'node',
|
|
14
|
+
output: {
|
|
15
|
+
path: path.join(__dirname, 'lib'),
|
|
16
|
+
filename: '[name].js',
|
|
17
|
+
libraryTarget: 'commonjs2',
|
|
18
|
+
},
|
|
19
|
+
resolve: {
|
|
20
|
+
extensions: ['.ts', '.tsx', '.js'],
|
|
21
|
+
},
|
|
22
|
+
plugins: [
|
|
23
|
+
new webpack.LoaderOptionsPlugin({
|
|
24
|
+
options: {
|
|
25
|
+
test: /\.tsx?$/,
|
|
26
|
+
ts: {
|
|
27
|
+
compiler: 'typescript',
|
|
28
|
+
configFile: 'tsconfig.json',
|
|
29
|
+
},
|
|
30
|
+
tslint: {
|
|
31
|
+
emitErrors: true,
|
|
32
|
+
failOnHint: true,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
],
|
|
37
|
+
devtool: 'source-map',
|
|
38
|
+
module: {
|
|
39
|
+
rules: [
|
|
40
|
+
{
|
|
41
|
+
test: /\.tsx?$/,
|
|
42
|
+
use: 'ts-loader',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
test: /\.(gql)$/,
|
|
46
|
+
exclude: /node_modules/,
|
|
47
|
+
use: ['graphql-tag/loader'],
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
test: /\.graphql?/,
|
|
51
|
+
exclude: /node_modules/,
|
|
52
|
+
use: 'raw-loader',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
test: /\.ejs$/,
|
|
56
|
+
exclude: /node_modules/,
|
|
57
|
+
use: 'raw-loader',
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
externals: [nodeExternals({ modulesDir: '../../../node_modules' }), nodeExternals()],
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
module.exports = webpackOpts;
|