Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set query timeout in Sequelize?

I'm looking to see how one can set the timeout time of queries in Sequelize.

I've looked into the Sequelize docs for some info but I can't quite find what I'm looking for. The closest I have found is the "pools.acquire" option, but I'm not looking to set the timeout for an incoming connection, but rather the timeout of an ongoing query so that I may short-circuit deadlocks quickly.

http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html

Here is my sample code:

const db = new Sequelize( database, username, password, {
  host   : hostname,
  dialect: "mysql",
  define : {},
  pool: {
    max : 10,
    min : 0,
    idle: 10000
  },
})

Any insight would be greatly appreciated!

like image 623
Bbbbob Avatar asked Jul 19 '19 23:07

Bbbbob


1 Answers

add dialectOptions

  const db2 = new Sequelize(database, username, password, {
    host: hostname,
    dialect: "mysql",
    define: {},
    dialectOptions: {
      options: {
        requestTimeout: 3000
      }
    },
    pool: {
      max: 10,
      min: 0,
      idle: 10000
    },
  });
like image 168
WITO Avatar answered Sep 22 '22 13:09

WITO