-
Notifications
You must be signed in to change notification settings - Fork 45
Playlist management functions some times silently fail #149
Comments
I've put some relevant extracts from the bot codebase in a gist here: |
Could this possibly be related to plug returning a 429 response code if the client sends too many api requests in a short interval? |
I rewrote the bot code a bit, and made it rerun the PlugAPI call if the callback was not executed within 2 seconds, and this is what I got:
For reference, this is my current iteration of the function toPromise(call, autoretry)
{
let resolved = false;
return new Promise(
(resolve, reject) =>
{
var caller = () =>
{
let retry = null;
if(autoretry)
{
let doRetry = () =>
{
logger.data('WARN', 'PlugAPI call timed out, retrying..');
caller();
};
retry = setTimeout(doRetry, 2000);
}
call((err, data) =>
{
if(retry) clearTimeout(retry);
if(resolved) return;
resolved = true;
if(err)
{
logger.data('ERR', 'PlugAPI: ' + err);
reject(err);
}
else
resolve(data)
});
};
caller();
}
);
} Which is then used like so: function joinBooth()
{
if(amDJ() || amWaitlisted()) return Promise.reject('Redundant enqueue');
logger.debug('GODJ', 'Ready to join');
return toPromise(bot.joinBooth, true);
} And the top level execution flow is defined like this: new Promise(
(resolve, reject) => clearPlaylist(playlist)
.then(() => addMedia(playlist, createMedia(song)), reject)
.then(joinBooth, reject)
.then(resolve, reject)
); The first sequence of retries is due to toPromise((callback) => bot.getPlaylistMedias(playlist.id, callback), true) The last one is due to toPromise((callback) => bot.addSongToPlaylist(playlist.id, media, callback), true) |
This seems to be 100% reproducible on startup, but after the bot has been running a while, it is rarer. |
For some reason I'm unable to retrieve any data for getPlaylist() or getPlaylistMedias(), bot return "undefined" while getPlaylists() returns everything just fine. Not sure if this issue is related to what you mentioned above? Edit: seems to be the same undefined for getActivePlaylist()... Example: console.log("PLAYLIST MEDIA", bot.getPlaylists(), bot.getPlaylist(11630973), bot.getPlaylistMedias(11630973)) returns: PLAYLIST MEDIA [ { active: true, count: 4, id: 11630973, name: 'Test' } ] undefined undefined |
I've made our bot manage a playlist via PlugAPI, but some times, the callback is never called.
It seems to happen most frequently with
getPlaylistMedias
, but it has also happened withjoinBooth
.To work around this, I made it automatically retry after 10 seconds of no callback happening, and after 6 retries, the operations completed successfully.
The "Ready to join" message is logged just before calling
joinBooth
, the "Playlist exists" message is logged just beforegetPlaylistMedias
.After
getPlaylistMedias
calls back, the message "playlist contains N items" is logged, and after joinBooth calls back, the timer that retries the join is cancelled.The text was updated successfully, but these errors were encountered: