Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

server-socket-framework-jps

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

server-socket-framework-jps - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1-1

dist/job/AbstractJob.d.ts

2

dist/index.d.ts

@@ -9,1 +9,3 @@ export { InviteType, DataMessageType } from './socket/SocketTypes';

export { CompositeJob } from './job/CompositeJob';
export { AbstractJob } from './job/AbstractJob';
export { FileMoverJob } from './job/FileMoverJob';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CompositeJob = exports.JobManager = exports.JobStatus = exports.JobErrorPriority = exports.MessageQueueManager = exports.SocketManager = exports.DataMessageType = exports.InviteType = void 0;
exports.FileMoverJob = exports.AbstractJob = exports.CompositeJob = exports.JobManager = exports.JobStatus = exports.JobErrorPriority = exports.MessageQueueManager = exports.SocketManager = exports.DataMessageType = exports.InviteType = void 0;
var SocketTypes_1 = require("./socket/SocketTypes");

@@ -18,2 +18,6 @@ Object.defineProperty(exports, "InviteType", { enumerable: true, get: function () { return SocketTypes_1.InviteType; } });

Object.defineProperty(exports, "CompositeJob", { enumerable: true, get: function () { return CompositeJob_1.CompositeJob; } });
var AbstractJob_1 = require("./job/AbstractJob");
Object.defineProperty(exports, "AbstractJob", { enumerable: true, get: function () { return AbstractJob_1.AbstractJob; } });
var FileMoverJob_1 = require("./job/FileMoverJob");
Object.defineProperty(exports, "FileMoverJob", { enumerable: true, get: function () { return FileMoverJob_1.FileMoverJob; } });
//# sourceMappingURL=index.js.map

14

dist/job/CompositeJob.d.ts

@@ -1,13 +0,11 @@

import { Job, jobCompleteCallback, JobConfig, JobError, JobStatus } from "./Job";
export declare class CompositeJob implements Job {
import { Job, JobConfig, JobError, JobStatus } from "./Job";
import { AbstractJob } from "./AbstractJob";
export declare class CompositeJob extends AbstractJob {
private componentJobs;
private config;
private currentJobIndex;
private currentRunErrors;
private runCB;
constructor(config: JobConfig);
constructor();
addComponentJob(job: Job): void;
executeJob(runId: string, cb: jobCompleteCallback): void;
getConfig(): JobConfig;
cb(runId: string, config: JobConfig, status: JobStatus, errors: JobError[] | null): void;
executeJob(runId: string): void;
jobCB(runId: string, config: JobConfig, status: JobStatus, errors: JobError[] | null): void;
}

@@ -5,10 +5,10 @@ "use strict";

const Job_1 = require("./Job");
class CompositeJob {
constructor(config) {
const AbstractJob_1 = require("./AbstractJob");
class CompositeJob extends AbstractJob_1.AbstractJob {
constructor() {
super();
this.componentJobs = [];
this.currentJobIndex = 0;
this.currentRunErrors = [];
this.runCB = null;
this.config = config;
this.cb = this.cb.bind(this);
this.jobCB = this.jobCB.bind(this);
this.executeJob = this.executeJob.bind(this);

@@ -18,16 +18,13 @@ }

this.componentJobs.push(job);
job.setCallback(this.cb);
}
executeJob(runId, cb) {
executeJob(runId) {
this.currentJobIndex = 0;
this.currentRunErrors = [];
this.runCB = cb;
if (this.componentJobs.length > 0) {
const firstJob = this.componentJobs[0];
firstJob.executeJob(runId, this.cb);
firstJob.executeJob(runId);
}
}
getConfig() {
return this.config;
}
cb(runId, config, status, errors) {
jobCB(runId, config, status, errors) {
if (errors) {

@@ -41,8 +38,8 @@ errors.forEach((error) => {

if (this.currentRunErrors.length > 0) {
if (this.runCB)
this.runCB(runId, config, Job_1.JobStatus.completedWithErrors, this.currentRunErrors);
if (this.cb)
this.cb(runId, config, Job_1.JobStatus.completedWithErrors, this.currentRunErrors);
}
else {
if (this.runCB)
this.runCB(runId, config, Job_1.JobStatus.completed, null);
if (this.cb)
this.cb(runId, config, Job_1.JobStatus.completed, null);
}

@@ -53,3 +50,3 @@ }

const nextJob = this.componentJobs[this.currentJobIndex];
nextJob.executeJob(runId, this.cb);
nextJob.executeJob(runId);
}

@@ -56,0 +53,0 @@ }

@@ -1,11 +0,9 @@

import { Job, jobCompleteCallback, JobConfig } from "./Job";
export declare class FileMoverJob implements Job {
import { AbstractJob } from "./AbstractJob";
export declare class FileMoverJob extends AbstractJob {
private originDir;
private destDir;
private fileTypes;
private config;
private removeFromOrigin;
constructor(config: JobConfig, originDir: string, destDir: string, fileTypes: string[], removeFromOrigin?: boolean);
getConfig(): JobConfig;
executeJob(runId: string, cb: jobCompleteCallback): void;
constructor(originDir: string, destDir: string, fileTypes: string[], removeFromOrigin?: boolean);
executeJob(runId: string): void;
}

@@ -9,5 +9,6 @@ "use strict";

const fs_1 = __importDefault(require("fs"));
class FileMoverJob {
constructor(config, originDir, destDir, fileTypes, removeFromOrigin = false) {
this.config = config;
const AbstractJob_1 = require("./AbstractJob");
class FileMoverJob extends AbstractJob_1.AbstractJob {
constructor(originDir, destDir, fileTypes, removeFromOrigin = false) {
super();
this.originDir = originDir;

@@ -19,6 +20,3 @@ this.destDir = destDir;

}
getConfig() {
return this.config;
}
executeJob(runId, cb) {
executeJob(runId) {
const originExists = fs_1.default.existsSync(this.originDir);

@@ -31,3 +29,3 @@ const destExists = fs_1.default.existsSync(this.destDir);

if (file[0] !== '.') {
const foundFileType = file.substr(file.length - 3, 3);
const foundFileType = file.substr(file.length - 3, 3).toLowerCase();
const foundIndex = this.fileTypes.findIndex((fileType) => fileType === foundFileType);

@@ -53,6 +51,8 @@ if (foundIndex >= 0) {

if (errors.length > 0) {
cb(runId, this.config, Job_1.JobStatus.completed, null);
if (this.cb)
this.cb(runId, this.config, Job_1.JobStatus.completedWithErrors, errors);
}
else {
cb(runId, this.config, Job_1.JobStatus.completedWithErrors, errors);
if (this.cb)
this.cb(runId, this.config, Job_1.JobStatus.completed, null);
}

@@ -62,11 +62,14 @@ }

// no dest do not execute
cb(runId, this.config, Job_1.JobStatus.failed, [{ runId: runId, jobName: this.config.name, message: `Destination directory ${this.destDir} does not exist`, errorPriority: Job_1.JobErrorPriority.processFail }]);
if (this.cb)
this.cb(runId, this.config, Job_1.JobStatus.failed, [{ runId: runId, jobName: this.config.name, message: `Destination directory ${this.destDir} does not exist`, errorPriority: Job_1.JobErrorPriority.processFail }]);
}
else if (destExists) {
// no origin do not execute
cb(runId, this.config, Job_1.JobStatus.failed, [{ runId: runId, jobName: this.config.name, message: `Origin directory ${this.originDir} does not exist`, errorPriority: Job_1.JobErrorPriority.processFail }]);
if (this.cb)
this.cb(runId, this.config, Job_1.JobStatus.failed, [{ runId: runId, jobName: this.config.name, message: `Origin directory ${this.originDir} does not exist`, errorPriority: Job_1.JobErrorPriority.processFail }]);
}
else {
// no dest do not execute
cb(runId, this.config, Job_1.JobStatus.failed, [{ runId: runId, jobName: this.config.name, message: `Neither origin or destination directories [${this.originDir},${this.destDir}] exist`, errorPriority: Job_1.JobErrorPriority.processFail }]);
if (this.cb)
this.cb(runId, this.config, Job_1.JobStatus.failed, [{ runId: runId, jobName: this.config.name, message: `Neither origin or destination directories [${this.originDir},${this.destDir}] exist`, errorPriority: Job_1.JobErrorPriority.processFail }]);
}

@@ -73,0 +76,0 @@ }

@@ -6,3 +6,3 @@ export declare type JobConfig = {

executeEveryMinutes: number;
job: Job;
job?: Job;
};

@@ -28,4 +28,7 @@ export declare enum JobErrorPriority {

export interface Job {
executeJob(runId: string, cb: jobCompleteCallback): void;
setCallback(cb: jobCompleteCallback | undefined): void;
executeJob(runId: string): void;
getConfig(): JobConfig;
setConfig(config: JobConfig): void;
cron(): void;
}

@@ -32,0 +35,0 @@ export interface JobListener {

@@ -14,4 +14,4 @@ import { JobConfig, JobError, JobListener, JobStatus } from "./Job";

addListener(listener: JobListener): void;
protected calculateNextExecuteTime(config: JobConfig): number;
protected calculateNextExecuteTime(config: JobConfig, isAboutToRun?: boolean): number;
addJob(config: JobConfig): void;
}

@@ -11,2 +11,3 @@ "use strict";

const logger = (0, debug_1.default)('job-manager');
const loggerDetail = (0, debug_1.default)('job-manager-detail');
class JobManager {

@@ -40,5 +41,9 @@ constructor() {

// execute the job
queueItem.nextRunTime = this.calculateNextExecuteTime(queueItem.config);
logger(`Executing job ${queueItem.config.name}, next execution time will be ${(0, moment_1.default)(queueItem.nextRunTime, 'YYYYMMDDHHmm').format('DD/MM/YYYY HH:mm')}`);
queueItem.config.job.executeJob((0, uuid_1.v4)(), this.jobCallback);
queueItem.nextRunTime = this.calculateNextExecuteTime(queueItem.config, true);
loggerDetail(`Executing job ${queueItem.config.name}, next execution time will be ${(0, moment_1.default)(queueItem.nextRunTime, 'YYYYMMDDHHmm').format('DD/MM/YYYY HH:mm')}`);
const job = queueItem.config.job;
if (job) {
job.setCallback(this.jobCallback);
job.executeJob((0, uuid_1.v4)());
}
}

@@ -53,10 +58,15 @@ });

}
calculateNextExecuteTime(config) {
calculateNextExecuteTime(config, isAboutToRun = false) {
let nextExecuteTime = 0;
if (config.isDailyJob) {
const now = parseFloat((0, moment_1.default)().format('YYYYMMDDHHmm'));
nextExecuteTime = parseFloat((0, moment_1.default)(`${(0, moment_1.default)().format('YYYYMMDD')}${config.executeDailyAtTime}`, 'YYYYMMDDHHmm').format('YYYYMMDDHHmm'));
if (nextExecuteTime < now) {
if (isAboutToRun) {
nextExecuteTime = parseFloat((0, moment_1.default)(`${(0, moment_1.default)().add(1, 'day').format('YYYYMMDD')}${config.executeDailyAtTime}`, 'YYYYMMDDHHmm').format('YYYYMMDDHHmm'));
}
else {
const now = parseFloat((0, moment_1.default)().format('YYYYMMDDHHmm'));
nextExecuteTime = parseFloat((0, moment_1.default)(`${(0, moment_1.default)().format('YYYYMMDD')}${config.executeDailyAtTime}`, 'YYYYMMDDHHmm').format('YYYYMMDDHHmm'));
if (nextExecuteTime < now) {
nextExecuteTime = parseFloat((0, moment_1.default)(`${(0, moment_1.default)().add(1, 'day').format('YYYYMMDD')}${config.executeDailyAtTime}`, 'YYYYMMDDHHmm').format('YYYYMMDDHHmm'));
}
}
}

@@ -80,3 +90,3 @@ else {

config: config,
nextRunTime: this.calculateNextExecuteTime(config)
nextRunTime: this.calculateNextExecuteTime(config, false)
};

@@ -89,3 +99,3 @@ logger(`Adding daily job ${queueItem.config.name} to queue, next execution time will be ${(0, moment_1.default)(queueItem.nextRunTime, 'YYYYMMDDHHmm').format('DD/MM/YYYY HH:mm')}`);

config: config,
nextRunTime: this.calculateNextExecuteTime(config)
nextRunTime: this.calculateNextExecuteTime(config, false)
};

@@ -92,0 +102,0 @@ logger(`Adding job ${queueItem.config.name} to queue, next execution time will be ${(0, moment_1.default)(queueItem.nextRunTime, 'YYYYMMDDHHmm').format('DD/MM/YYYY HH:mm')}`);

@@ -5,6 +5,6 @@ /// <reference types="node" />

import { ChatMessage, ChatRoom, ChatUser, DataMessage, InviteMessage, QueuedMessages } from "./SocketTypes";
import { Job, jobCompleteCallback, JobConfig } from "../job/Job";
export declare class SocketManager implements Job {
import { JobConfig } from "../job/Job";
import { AbstractJob } from "../job/AbstractJob";
export declare class SocketManager extends AbstractJob {
private static _instance;
private config;
static getInstance(): SocketManager;

@@ -15,3 +15,3 @@ protected io: Server | null;

private constructor();
executeJob(runId: string, cb: jobCompleteCallback): void;
executeJob(runId: string): void;
connectToServer(httpServer: httpServer): void;

@@ -18,0 +18,0 @@ getConfig(): JobConfig;

@@ -14,5 +14,7 @@ "use strict";

const JobManager_1 = require("../job/JobManager");
const AbstractJob_1 = require("../job/AbstractJob");
const socketDebug = debug('socket');
class SocketManager {
class SocketManager extends AbstractJob_1.AbstractJob {
constructor() {
super();
this.rooms = [];

@@ -45,7 +47,8 @@ this.users = [];

}
executeJob(runId, cb) {
executeJob(runId) {
//socketDebug(`Checking for expired rooms and persisting state`);
this.checkForExpiredRooms();
MessageQueueManager_1.MessageQueueManager.getInstance().persistQueueAndRooms(this.rooms);
cb(runId, this.config, Job_1.JobStatus.completed, null);
if (this.cb)
this.cb(runId, this.config, Job_1.JobStatus.completed, null);
}

@@ -52,0 +55,0 @@ connectToServer(httpServer) {

{
"name": "server-socket-framework-jps",
"version": "1.1.0",
"version": "1.1.1-1",
"description": "A simple socket framework for persistent chat rooms and data messages",

@@ -11,3 +11,3 @@ "main": "dist/index.js",

"scripts": {
"compile": "tsc",
"build": "tsc",
"compile.watch": "tsc-watch",

@@ -14,0 +14,0 @@ "lint": "eslint --ext js,jsx,tsx,ts --fix src"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc