Giter VIP home page Giter VIP logo

Comments (2)

TemaSM avatar TemaSM commented on June 19, 2024 3

Hi @kenenisa

That's an expected behavior of nodemon, because it starts watching changes of files: [nodemon] watching extensions: js,mjs,json.
If you look into simple example:

bot.use((new LocalSession({ database: 'example_db.json' })).middleware())

- Here is database option which defines the path for database file of sessions, for example example_db.json.
telegraf-sessin-local uses underlying library called lowdb to store and manipulate database data.
When you start your bot, lowdb creates new file descriptor for database-file and touches it (look onto file modification date-time just after starting nodemon or node), which simply fires nodemon event like 'file was modified' and nodemon performing restart of your js file, which leads to looped behavior:
--(1)-- Start js file and watch for changes by nodemon --(2)--> JS file started by node --(3)--> Bot started and touched database file --(4)--> Nodemon detected change of json file --(5)--> Nodemon re-executes js file --> (1)

To fix this, please add config for nodemon to ignore json-database file, for example by adding new block into your package.json:

"nodemonConfig": {
  "ignore": ["sessions.json", "example_db.json"]
}

sessions.json - default filename of sessions' database in telegraf-session-local:

* @param {String} [options.database] - Name or path to database file `default:` `'sessions.json'`

from telegraf-session-local.

kenenisa avatar kenenisa commented on June 19, 2024

Hi @kenenisa

That's an expected behavior of nodemon, because it starts watching changes of files: [nodemon] watching extensions: js,mjs,json. If you look into simple example:

bot.use((new LocalSession({ database: 'example_db.json' })).middleware())

  • Here is database option which defines the path for database file of sessions, for example example_db.json.
    telegraf-sessin-local uses underlying library called lowdb to store and manipulate database data.
    When you start your bot, lowdb creates new file descriptor for database-file and touches it (look onto file modification date-time just after starting nodemon or node), which simply fires nodemon event like 'file was modified' and nodemon performing restart of your js file, which leads to looped behavior:
    --(1)-- Start js file and watch for changes by nodemon --(2)--> JS file started by node --(3)--> Bot started and touched database file --(4)--> Nodemon detected change of json file --(5)--> Nodemon re-executes js file --> (1)
    To fix this, please add config for nodemon to ignore json-database file, for example by adding new block into your package.json:
{
  "...": "... other standard package.json values",
  "nodemonConfig": {
    "ignore": ["sessions.json", "example_db.json"]
  }
}

sessions.json - default filename of sessions' database in telegraf-session-local:

* @param {String} [options.database] - Name or path to database file `default:` `'sessions.json'`

The issue is resolved. It's now working as intended.

from telegraf-session-local.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.