Skip to content

[fix] Bree Job not able to resolve the dependencies #7

Open
@AdnanHussainTurki

Description

@AdnanHussainTurki

The Bree Job not able to resolve the dependencies and throwing JS errors which are potentially referring to JS compiled code (not the actual code). May be the alias resolving issue.

Kind-of stuck, any help would be greatly appreciated.

Node.js version: v18.19.0

OS version: MacOS Sanoma 14.0

Description: Inability to resolve the dependencies

Actual behavior

image

OR If I strip the job to the provided one below, getting this:

image

Expected behavior

The expected behaviour would be to atleast run the code and throw sensible erros.

Code to reproduce

Structure:
image

engage-scheduler.ts

import process from 'process'
import * as path from 'path'
import Bree from 'bree'

Bree.extend(require('@breejs/ts-worker'))
const jobs = [
  {
    name: 'auto-process-new-transactions-through-llm',
    cron: '* * * * *',
    // interval: '5m',
  },
]
const bree = new Bree({
  jobs,
  defaultExtension: 'ts',
  root: path.join(__dirname, 'jobs'),
  defaultRootIndex: 'index.ts',
  outputWorkerMetadata: true,
})

export default bree

auto-process-new-transactions-through-llm.ts

import { parentPort } from 'worker_threads'
import process from 'process'
import { Transaction } from 'models/Transaction'
import { Company } from 'models/Company'

const jobName = 'auto-process-new-transactions-through-llm'
const maximumNumberOfTransactionsToProcess = 100
async function main(): Promise<void> {
  const transactionsToProcessOfTheFirstCompany: Transaction[] = await Transaction.query().limit(
    maximumNumberOfTransactionsToProcess
  )
  const company: Company = await Company.query().findById(1)

  return
}

main()
  .then(async () => {
    // signal to parent that the job is done
    if (parentPort) {
      parentPort.postMessage(jobName + ' done at ' + new Date().toLocaleString())
    }
    // eslint-disable-next-line unicorn/no-process-exit
    else {
      parentPort.postMessage(jobName + ' exiting at ' + new Date().toLocaleString())
      process.exit(0)
    }
  })
  .catch((error) => {
    console.log(jobName + ' error in main', error)
    parentPort.postMessage(jobName + ' error: ' + error.message)
    process.exit(0)
  })

tsconfig.json

{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs",
    "lib": ["es2019", "dom", "dom.iterable", "scripthost"],
    "outDir": "./dist",
    "esModuleInterop": true,
    "allowJs": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "skipLibCheck": true,
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "types": ["webpack-env", "jest", "node"],
    "baseUrl": "./src",
    "forceConsistentCasingInFileNames": false,
    "paths": {
      "fyo/*": ["fyo/*"],
      "schemas/*": ["schemas/*"],
      "backend/*": ["backend/*"],
      "models/*": ["models/*"],
      "auth/*": ["auth/*"],
      "utils/*": ["utils/*"],
      "scheduler/*": ["scheduler/*"],
      "controllers/*": ["controllers/*"],
      "middlewares/*": ["middlewares/*"],
      "acl/*": ["acl/*"]
      // "utils/db/*": ["src/utils/db/*"],
    }
  },
  "ts-node": {
    "files": true
  },
  "include": [
    "tests/**/*.ts",
    "src/**/*.ts",
    "src/**/*.vue",
    "src/schemas/**/*.ts",
    "src/backend/**/*.ts",
    "src/fyo/**/*.ts",
    "src/models/**/*.ts",
    "src/controllers/**/*.ts",
    "src/utils/**/*.ts",
    "src/scheduler/jobs/**/*.ts",
    "src/scheduler/jobs/**/*.js",
    "src/scheduler/**/*.js",
    "src/scheduler/**/*.js",
    "src/services/acl/**/*.ts"
  ],
  "exclude": ["node_modules"]
}

package.json

{
  "version": "0.0.1",
  "license": "MIT",
  "author": "REDACTED",
  "scripts": {
    "start": "TS_NODE=true NODE_ENV=development ts-node-dev  ./src/index.ts",
    "build": "tsc",
    "build:sm": "tsc --sourcemap",
    "pm2": "NODE_ENV=production pm2 start dist/src/index.js --watch -i max",
    "db:migrate": "knex migrate:latest",
    "db:seed": "knex seed:run",
    "db:rb": "knex migrate:rollback",
    "db:mc": "knex migrate:make",
    "test": "jest tests",
    "prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write"
  },
  "dependencies": {
    "@breejs/ts-worker": "^2.0.0",
    "@types/assert": "^1.5.6",
    "axe": "^12.2.3",
    "axios": "^1.6.0",
    "big.js": "^6.2.1",
    "bree": "^9.1.3",
    "cabin": "^13.2.5",
    "cookie-parser": "^1.4.6",
    "cors": "^2.8.5",
    "csv-parse": "^5.5.2",
    "dayjs": "^1.11.10",
    "express": "^4.17.3",
    "express-session": "^1.17.3",
    "fastest-levenshtein": "^1.0.16",
    "jsonwebtoken": "^9.0.2",
    "knex": "^2.4.0",
    "knex-paginate": "^3.1.1",
    "knex-paginator": "^2.0.0",
    "lodash": "^4.17.21",
    "luxon": "^2.5.2",
    "module-alias": "^2.2.3",
    "moment": "^2.29.4",
    "multer": "^1.4.5-lts.1",
    "mysql": "^2.18.1",
    "mysql2": "^1.6.1",
    "net": "^1.0.2",
    "node-fetch": "2",
    "nodemon": "^1.18.5",
    "objection": "^3.1.1",
    "openai": "^4.19.0",
    "passport": "^0.6.0",
    "passport-http-bearer": "^1.0.1",
    "passport-jwt": "^4.0.1",
    "passport-local": "^1.0.0",
    "pbkdf2": "^3.1.2",
    "pdfjs-dist": "^4.0.269",
    "pesa": "^1.1.13",
    "request": "^2.88.0",
    "request-promise-native": "^1.0.5",
    "signale": "^1.4.0",
    "source-map-support": "^0.5.21",
    "uuidv4": "^6.2.13",
    "xlsx": "^0.18.5",
    "yup": "^1.3.1"
  },
  "devDependencies": {
    "@types/assert": "^1.5.6",
    "@types/better-sqlite3": "^7.6.4",
    "@types/cors": "^2.8.14",
    "@types/electron-devtools-installer": "^2.2.0",
    "@types/express": "^4.16.0",
    "@types/jest": "^29.5.5",
    "@types/knex": "^0.14.26",
    "@types/lodash": "^4.14.179",
    "@types/luxon": "^2.3.1",
    "@types/multer": "^1.4.11",
    "@types/mysql": "^2.15.5",
    "@types/node": "^17.0.23",
    "@types/node-fetch": "^2.6.1",
    "@types/request": "^2.47.1",
    "@types/request-promise-native": "^1.0.15",
    "@types/tape": "^4.13.2",
    "@types/webpack-env": "^1.18.2",
    "@typescript-eslint/eslint-plugin": "5.60.0",
    "@typescript-eslint/parser": "5.60.0",
    "dotenv": "^16.3.1",
    "dotenv-extended": "^2.9.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-prettier": "^5.0.1",
    "jest": "^29.7.0",
    "pdf2pic": "^3.1.0",
    "prettier": "^3.1.0",
    "ts-jest": "^29.1.1",
    "ts-node": "^10.7.0",
    "ts-node-dev": "^2.0.0",
    "tsconfig-paths": "^3.14.1",
    "tslib": "^2.3.1",
    "typescript": "^4.9.5",
    "webpack-env": "^0.8.0"
  }
}

Checklist

  • [Y] I have searched through GitHub issues for similar issues.
  • [Y] I have completely read through the README and documentation.
  • [Y] I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions