namtran3005/zeromq-broker

View on GitHub

Showing 49 of 49 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  const mockWorkerFn = jest.fn().mockImplementation(async function workerHandler(msg) {
    const objWork: any = msg;
    winston.debug("Worker receive works \n", objWork);
    /* sample do work */
    if (objWork && objWork.message.current) {
Severity: Major
Found in _test/Broker_dispatcher.test.ts and 1 other location - About 6 hrs to fix
_test/Broker_frontendReq.test.ts on lines 77..89

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 166.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  const mockWorkerFn = jest.fn().mockImplementation(async function workerHander(msg) {
    const objWork: any = msg;
    winston.debug("Worker receive works \n", objWork);
    /* sample do work */
    if (objWork && objWork.message.current) {
Severity: Major
Found in _test/Broker_frontendReq.test.ts and 1 other location - About 6 hrs to fix
_test/Broker_dispatcher.test.ts on lines 82..94

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 166.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  onUpdateMsg: (payload) => {
    if (payload &&
        payload._id && typeof payload._id === "string" &&
        payload.tries && typeof payload.tries === "number" &&
        payload.message && payload.message.current.result
Severity: Major
Found in _test/Broker_frontendReq.test.ts and 1 other location - About 5 hrs to fix
_test/Broker_dispatcher.test.ts on lines 47..65

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 143.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  onUpdateMsg: (payload) => {
    if (payload &&
        payload._id && typeof payload._id === "string" &&
        payload.tries && typeof payload.tries === "number" &&
        payload.message && payload.message.current.result
Severity: Major
Found in _test/Broker_dispatcher.test.ts and 1 other location - About 5 hrs to fix
_test/Broker_frontendReq.test.ts on lines 36..54

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 143.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    this.backend.on("message", (...reqMsg) => {
      const [reqAddress, delimiter, payload] = reqMsg;
      const parsed = JSON.parse(payload.toString());
      winston.debug("Backend received payload with info\n", {
        delimiter: delimiter.toString(),
Severity: Major
Found in src/Broker.ts and 1 other location - About 5 hrs to fix
src/Broker.ts on lines 131..141

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 139.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    this.frontend.on("message", (...reqMsg) => {
      const [reqAddress, delimiter, payload] = reqMsg;
      const parsed = JSON.parse(payload.toString());
      winston.debug("Frontend received task with info\n", {
        delimiter: delimiter.toString(),
Severity: Major
Found in src/Broker.ts and 1 other location - About 5 hrs to fix
src/Broker.ts on lines 142..152

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 139.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  const sentMsg = {
    message: {
      current: {
        params: [
          0, 1,
Severity: Major
Found in _test/Broker_frontendReq.test.ts and 1 other location - About 3 hrs to fix
_test/Broker_dispatcher.test.ts on lines 107..136

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 95.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  const msg = {
    message: {
      current: {
        params: [
          0, 1,
Severity: Major
Found in _test/Broker_dispatcher.test.ts and 1 other location - About 3 hrs to fix
_test/Broker_frontendReq.test.ts on lines 141..170

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 95.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

File Broker.ts has 281 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import MongoSMQ from "mongo-message";
import * as winston from "winston";
import * as zeromq from "zeromq";
import Client from "./Client";

Severity: Minor
Found in src/Broker.ts - About 2 hrs to fix

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        winston.debug("%j", {
          clientAddress: (respAddress && (typeof respAddress === "object")) ? respAddress.toString("hex") : respAddress,
          delimiter: (delimiter && (typeof delimiter === "object")) ? delimiter.toString() : delimiter,
          payload,
        });
    Severity: Major
    Found in src/ClientAck.ts and 1 other location - About 2 hrs to fix
    src/Broker.ts on lines 270..274

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 75.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        winston.debug("%j", {
          clientAddress: (respAddress && (typeof respAddress === "object")) ? respAddress.toString("hex") : respAddress,
          delimiter: (delimiter && (typeof delimiter === "object")) ? delimiter.toString() : delimiter,
          payload,
        });
    Severity: Major
    Found in src/Broker.ts and 1 other location - About 2 hrs to fix
    src/ClientAck.ts on lines 77..81

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 75.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

      public _increaseTask(): void {
        const after = this.numTask + 1;
        winston.debug(` increaseTask \n %j`, {
          after,
          before: this.numTask,
    Severity: Major
    Found in src/Broker.ts and 1 other location - About 1 hr to fix
    src/Broker.ts on lines 187..194

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 70.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

      public _decreaseTask(): void {
        const after = this.numTask - 1;
        winston.debug(` decreaseTask \n %j`, {
          after,
          before: this.numTask,
    Severity: Major
    Found in src/Broker.ts and 1 other location - About 1 hr to fix
    src/Broker.ts on lines 178..185

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 70.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function initBroker has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      public async initBroker() {
        await this.initQueue();
        if (this.nextDest) {
          this.deliver = await new Client({
            queueUrl: this.nextDest,
    Severity: Minor
    Found in src/Broker.ts - About 1 hr to fix

      Function registerNextDest has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        public async registerNextDest() {
          const sendNextAndAck = async () => {
            const doneTask = await this.queueInst.Message.find(this.doneDef);
            winston.debug("Deliver retrived a done work with info %j\n", doneTask[0]);
            if (doneTask && doneTask.length !== 0) {
      Severity: Minor
      Found in src/Broker.ts - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function init has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        public async init() {
          this.requester = zeromq.socket(this._type);
          this.requester.connect(this.queueUrl);
          this.requester.setsockopt("linger", 0);
          this.requester.on("message", (...args) => {
      Severity: Minor
      Found in src/ClientAck.ts - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

            if (payload &&
                payload._id && typeof payload._id === "string" &&
                payload.tries && typeof payload.tries === "number" &&
                payload.message && payload.message.result
            ) {
        Severity: Major
        Found in src/Broker.ts - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

              if (payload &&
                  payload._id && typeof payload._id === "string" &&
                  payload.tries && typeof payload.tries === "number" &&
                  payload.message && payload.message.current.result
              ) {
          Severity: Major
          Found in _test/Broker_dispatcher.test.ts - About 1 hr to fix

            Consider simplifying this complex logical expression.
            Open

                if (payload &&
                    payload._id && typeof payload._id === "string" &&
                    payload.tries && typeof payload.tries === "number" &&
                    payload.message && payload.message.current.result
                ) {
            Severity: Major
            Found in _test/Broker_frontendReq.test.ts - About 1 hr to fix

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                  onUpdateMsg: (payload: any) => {
                    query: { _id: string, tries: number},
                    update: any,
                  } | void;
              Severity: Minor
              Found in src/Broker.ts and 1 other location - About 35 mins to fix
              src/Broker.ts on lines 27..30

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 47.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Severity
              Category
              Status
              Source
              Language