botpress / v12

Botpress OSS – v12
https://v12.botpress.com
GNU Affero General Public License v3.0
69 stars 83 forks source link

Tasks falling off scheduler #508

Closed mhjb closed 5 years ago

mhjb commented 5 years ago

I create a new scheduled task:

screen shot 2018-11-13 at 4 31 11 pm

It turns up in the list of upcoming tasks:

screen shot 2018-11-13 at 4 31 18 pm

It runs once, successfully, but also gives this error:

screen shot 2018-11-13 at 4 32 17 pm

… and then it's no longer in the scheduled task list:

screen shot 2018-11-13 at 4 32 23 pm

Can you help?

epaminond commented 5 years ago

@mhjb , are you also getting this with postgres-db?

mhjb commented 5 years ago

Yes:

2018-11-14 13:00:00error: Unhandled Rejection in Promise: Promise { _bitField: 18087936, _fulfillmentHandler0: { error: duplicate key value violates unique constraint "scheduler_tasks_scheduleid_scheduledon_unique" at Connection.parseE (/app/node_modules/pg/lib/connection.js:567:11) at Connection.parseMessage (/app/node_modules/pg/lib/connection.js:391:17) at Socket. (/app/node_modules/pg/lib/connection.js:129:22) at Socket.emit (events.js:182:13) at Socket.EventEmitter.emit (domain.js:442:20) at addChunk (_stream_readable.js:283:12) at readableAddChunk (_stream_readable.js:264:11) at Socket.Readable.push (_stream_readable.js:219:10) at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17) name: 'error', length: 321, severity: 'ERROR', code: '23505', detail: 'Key ("scheduleId", "scheduledOn")=(test-schedule, 2018-11-14 00:00:00+00) already exists.', hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: 'public', table: 'scheduler_tasks', column: undefined, dataType: undefined, constraint: 'scheduler_tasks_scheduleid_scheduledon_unique', file: 'nbtinsert.c', line: '434', routine: '_bt_check_unique' }, _rejectionHandler0: undefined, _promise0: undefined, _receiver0: undefined } Reason: (meta={"name":"error","length":321,"severity":"ERROR","code":"23505","detail":"Key (\"scheduleId\", \"scheduledOn\")=(test-schedule, 2018-11-14 00:00:00+00) already exists.","schema":"public","table":"scheduler_tasks","constraint":"scheduler_tasks_scheduleid_scheduledon_unique","file":"nbtinsert.c","line":"434","routine":"_bt_check_unique"})

dmk23 commented 5 years ago

Confirmed - getting the same problem, error conditions and error messages as @mhjb

Looks like some synchronization bugs with delete/insert running out of order

Just FYI these look very similar to the issues I had to fix for loading contexts https://github.com/botpress/botpress/pull/891/commits/d26a0f385e95450670cf2ca1c84ee0a1d855a914

dmk23 commented 5 years ago

Problem fixed https://github.com/botpress/botpress/pull/891/commits/205133950153a791eb5c12d561350b70f2d49c14

dmk23 commented 5 years ago

Now the final/real/tested fix...

Synchronization wasn't the problem (though I added https://github.com/botpress/botpress/pull/891/commits/1a0593d7942edfffc91d82b5dc8be65f86d7bb76 to improve it further)

The tasks were failing because the same event could be re-triggered at the same moment. This was finally fixed by adding 5 seconds to "now" for calculating the next event https://github.com/botpress/botpress/pull/891/commits/1858edb5c4a627687435e3914cfc37ccba7c4b08

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.