timgit / pg-boss

Queueing jobs in Postgres from Node.js like a boss
MIT License
2.13k stars 158 forks source link

I am having an error when trying to create a simple job #2

Closed diazod closed 8 years ago

diazod commented 8 years ago

When I run this code:

async function setupJobs() {
  const postgresURL = config.get('datasources:postgresql:url');
  const boss = new PgBoss(postgresURL);
  await boss.start();
  log.debug('Ready');
  boss.publish('work', () => {
    console.log('STUFF');
  });
}

I get:

Web server listening at: http://0.0.0.0:3000
  collectai:boot:jobs:debug Ready +0ms
Unhandled rejection error: syntax error at or near "ON"
    at [object Object].Connection.parseE (/User/Seinh/Project/node_modules/pg-boss/node_modules/pg/lib/connection.js:543:11)
    at [object Object].Connection.parseMessage (/User/Seinh/Project/node_modules/pg-boss/node_modules/pg/lib/connection.js:370:17)
    at Socket.<anonymous> (/User/Seinh/Project/node_modules/pg-boss/node_modules/pg/lib/connection.js:109:22)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at Socket.Readable.push (_stream_readable.js:110:10)
    at TCP.onread (net.js:523:20)
From previous event:
    at Db.execute (/User/Seinh/Project/node_modules/pg-boss/lib/db.js:36:20)
    at Db.executeSql (/User/Seinh/Project/node_modules/pg-boss/lib/db.js:27:25)
    at insertJob (/User/Seinh/Project/node_modules/pg-boss/lib/manager.js:225:29)
    at deferred (/User/Seinh/Project/node_modules/pg-boss/lib/manager.js:184:17)
From previous event:
    at Manager.publish (/User/Seinh/Project/node_modules/pg-boss/lib/manager.js:176:20)
    at PgBoss.publish (/User/Seinh/Project/node_modules/pg-boss/lib/index.js:137:41)
    at Object._callee$ (jobs.js:10:8)
    at tryCatch (/User/Seinh/Project/node_modules/regenerator-runtime/runtime.js:62:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/User/Seinh/Project/node_modules/regenerator-runtime/runtime.js:336:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/User/Seinh/Project/node_modules/regenerator-runtime/runtime.js:95:21)
    at step (/User/Seinh/Project/server/boot/jobs.js:34:191)
    at /User/Seinh/Project/server/boot/jobs.js:34:368
    at run (/User/Seinh/Project/node_modules/core-js/modules/es6.promise.js:89:22)
    at /User/Seinh/Project/node_modules/core-js/modules/es6.promise.js:102:28
    at flush (/User/Seinh/Project/node_modules/core-js/modules/_microtask.js:18:9)
    at doNTCallback0 (node.js:407:9)
    at process._tickDomainCallback (node.js:377:13)
    at process.fallback (/User/Seinh/Project/node_modules/async-listener/index.js:450:15)
timgit commented 8 years ago

You're passing a callback function to publish instead of a data payload. You should publish an object for example, then use a callback via subscribe.

Try copying/pasting the example in the readme to make sure all is working.

I will leave this issue open until I add more error handling to this, though. Thanks!

mwcbrent commented 7 years ago

I'm running into the same thing running exactly what is in the readme example. I'm running Postgres 9.6.1.

mwcbrent commented 7 years ago

I take that back, I was running psql 9.6.1. This error will happen if you're running postgres 9.4...