Skip to content

Commit

Permalink
Minor request scoped instances (#31)
Browse files Browse the repository at this point in the history
* Add HOW_TO_USE.md file, Update README.md

* Add example - Hiring process

* Add request scoped process instance data in class object
Update timer logs
Update Executor
  • Loading branch information
sudhir-raut authored Dec 8, 2023
1 parent 1c2e2f5 commit 1db91a9
Show file tree
Hide file tree
Showing 11 changed files with 643 additions and 259 deletions.
4 changes: 2 additions & 2 deletions envs/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ MONGO_PASS=
MONGO_DBNAME=workflowEngine


SWAGGER_TITLE= IO Flow API Documentation
SWAGGER_DESC=This documentation is only for the REST APIs
SWAGGER_TITLE= IO Flow
SWAGGER_DESC= Documentation for REST APIs
SWAGGER_VERSION=1.0
SWAGGER_TAG
SWAGGER_BASEPATH
Expand Down
216 changes: 216 additions & 0 deletions examples/Employee Hiring/hiring.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
{
"name": "Hiring Flow",
"description": "Process to hiring a candidate",
"key": "KEY123",
"properties": [
{
"key": "name",
"value": {
"type": "string",
"default": "",
"required": true
}
},
{
"key": "job",
"value": {
"type": "string",
"default": "",
"required": true
}
},
{
"key": "emailId",
"value": {
"type": "string",
"default": "",
"required": true
}
}
],
"assigneeConnector": null,
"stages": [
{
"key": "start1",
"name": "start stage",
"description": "string",
"type": "event",
"subType": "start",
"nextStages": [
"key-2"
]
},
{
"key": "A1",
"name": "Application Recieved",
"description": "Desc",
"type": "activity",
"subType": "system-task",
"mandatory": true,
"nextStages": [
"A2"
],
"connector": {
"type": "rest",
"config": {
"url": "https://reqres.in/api/users",
"method": "post",
"data": {}
}
}
},
{
"key": "A2",
"name": "Screen Resume",
"description": "Desc",
"type": "activity",
"subType": "user-task",
"mandatory": true,
"nextStages": [
"G1"
],
"properties": [
{
"key": "qualified",
"value": {
"type": "boolean",
"default": false,
"required": true
}
}
]
},
{
"key": "G1",
"name": "Is Qalified",
"description": "string",
"type": "gateway",
"subType": "exclusive",
"nextStages": [
"end1"
],
"conditions": [
{
"name": "Qalified?",
"op": "AND",
"expressions": [
{
"lhs": "$[stages.<A2>.parameters.qualified]",
"op": "==",
"rhs": true
}
],
"onTrueNextStage": "A3"
}
]
},
{
"key": "A3",
"name": "Interview Round 1",
"description": "Desc",
"type": "activity",
"subType": "user-task",
"mandatory": true,
"nextStages": [
"G2"
],
"properties": [
{
"key": "qualified",
"value": {
"type": "boolean",
"default": false,
"required": true
}
}
]
},
{
"key": "G2",
"name": "Is Qalified",
"description": "string",
"type": "gateway",
"subType": "exclusive",
"nextStages": [
"end1"
],
"conditions": [
{
"name": "Qalified?",
"op": "AND",
"expressions": [
{
"lhs": "$[stages.<A3>.parameters.qualified]",
"op": "==",
"rhs": true
}
],
"onTrueNextStage": "A4"
}
]
},
{
"key": "A4",
"name": "Final Round",
"description": "Desc",
"type": "activity",
"subType": "user-task",
"mandatory": true,
"nextStages": [
"G3"
],
"properties": [
{
"key": "qualified",
"value": {
"type": "boolean",
"default": false,
"required": true
}
}
]
},
{
"key": "G3",
"name": "Is Qalified",
"description": "string",
"type": "gateway",
"subType": "exclusive",
"nextStages": [
"end1"
],
"conditions": [
{
"name": "Qalified?",
"op": "AND",
"expressions": [
{
"lhs": "$[stages.<A4>.parameters.qualified]",
"op": "==",
"rhs": true
}
],
"onTrueNextStage": "A5"
}
]
},
{
"key": "A5",
"name": "Send Offer Letter",
"description": "Trigger communication",
"type": "activity",
"subType": "system-task",
"mandatory": false,
"nextStages": [
"end1"
]
},
{
"key": "end1",
"name": "end stage",
"description": "end process",
"type": "event",
"subType": "end"
}
]
}
Binary file added examples/Employee Hiring/hiring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/common/const/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export class Constants {
ERROR: 'error',
STARTED: 'started',
ON_HOLD: 'on-hold',
CANCELLED: 'cancelled'
CANCELLED: 'cancelled',
RUNNING: 'running'
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/common/interceptors/response.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ export class ResponseInterceptor implements NestInterceptor {

const { ip, method, originalUrl, body } = request;
const userAgent = request.get('user-agent') || '';
const tenantId = request.get('x-tenant-id') || '';

response.on('close', () => {
const { statusCode } = response;
if (statusCode < 400) {
if (statusCode < 400 && originalUrl !== '/v1/timer') {
const contentLength = response.get('content-length');
this.logger.log(`[${tenantId}]: ${method} ${originalUrl} --> ${statusCode} ${contentLength} - ${userAgent} ${ip}`);
this.logger.log(`${method} ${originalUrl} --> ${statusCode} ${contentLength} - ${userAgent} ${ip}`);
}
});
// if (response.status === 201)
Expand Down
1 change: 1 addition & 0 deletions src/common/middlewares/http-request-headers.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Request, Response, NextFunction } from 'express';
import jwt_decode from 'jwt-decode'
@Injectable()
export class HttpRequestHeadersMiddleware implements NestMiddleware {

async use(request: Request, _response: Response, next: NextFunction) {
let tenantId = request.headers['x-tenant-id'] || request.headers['X-TENANT-ID'];

Expand Down
3 changes: 2 additions & 1 deletion src/common/middlewares/logger.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export class AppLoggerMiddleware implements NestMiddleware {
const tenantId = request.get('x-tenant-id') || '';

response.on('close', () => {
console.log('&&&&&&&&&&&&&& ', originalUrl);
const { statusCode } = response;
if (statusCode < 400) {
if (statusCode < 400 && originalUrl !== '/v1/timer') {
const contentLength = response.get('content-length');
this.logger.log(`[${tenantId}]: ${method} ${originalUrl} --> ${statusCode} ${contentLength} - ${userAgent} ${ip}`);
}
Expand Down
14 changes: 7 additions & 7 deletions src/common/providers/execute-only-once.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import { firstValueFrom } from 'rxjs';
export class ExecuteOnlyOnce {
private readonly logger = new Logger(ExecuteOnlyOnce.name);

handleTimerEventCron ( name, seconds ) {
const job = new CronJob( `0/${ seconds } * * * * *`, () => {
const url = `http://localhost:${ process.env.TCP_PORT }${ process.env.APP_BASEPATH ? `/${ process.env.APP_BASEPATH }` : '' }/timer`;
handleTimerEventCron(name, seconds) {
const job = new CronJob(`0/${seconds} * * * * *`, () => {
const url = `http://localhost:${process.env.TCP_PORT}${process.env.APP_BASEPATH ? `/${process.env.APP_BASEPATH}` : ''}/timer`;
const httpService = new HttpService();
const axiosConfig = {
url,
method: 'get'
};
firstValueFrom( httpService.request( axiosConfig ) );
firstValueFrom(httpService.request(axiosConfig));

} );
});
const schedulerRegistry = new SchedulerRegistry();
schedulerRegistry.addCronJob( name, job );
schedulerRegistry.addCronJob(name, job);
job.start();

this.logger.debug(
`job [${ name }] added for every ${ seconds } seconds!`,
`Job [${name}] has been added for every ${seconds} seconds!`,
);
}
}
Loading

0 comments on commit 1db91a9

Please sign in to comment.