mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Upgrading stability in errors occurrences
This commit is contained in:
@@ -16,7 +16,14 @@ class ClearHandler(AbstractHandler):
|
||||
if processInfo:
|
||||
# Clear the playlist
|
||||
playlist = processInfo.getPlaylist()
|
||||
with processInfo.getLock():
|
||||
processLock = processInfo.getLock()
|
||||
acquired = processLock.acquire(timeout=self.config.ACQUIRE_LOCK_TIMEOUT)
|
||||
if acquired:
|
||||
playlist.clear()
|
||||
|
||||
processLock.release()
|
||||
processLock.release()
|
||||
else:
|
||||
processManager.resetProcess(self.guild, self.ctx)
|
||||
embed = self.embeds.PLAYER_RESTARTED()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx)
|
||||
|
||||
@@ -15,9 +15,17 @@ class HistoryHandler(AbstractHandler):
|
||||
processManager = ProcessManager()
|
||||
processInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
if processInfo:
|
||||
with processInfo.getLock():
|
||||
processLock = processInfo.getLock()
|
||||
acquired = processLock.acquire(timeout=self.config.ACQUIRE_LOCK_TIMEOUT)
|
||||
if acquired:
|
||||
playlist = processInfo.getPlaylist()
|
||||
history = playlist.getSongsHistory()
|
||||
processLock.release()
|
||||
else:
|
||||
# If the player doesn't respond in time we restart it
|
||||
processManager.resetProcess(self.guild, self.ctx)
|
||||
embed = self.embeds.PLAYER_RESTARTED()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
else:
|
||||
history = []
|
||||
|
||||
|
||||
@@ -21,13 +21,16 @@ class LoopHandler(AbstractHandler):
|
||||
|
||||
playlist = processInfo.getPlaylist()
|
||||
|
||||
with processInfo.getLock():
|
||||
processLock = processInfo.getLock()
|
||||
acquired = processLock.acquire(timeout=self.config.ACQUIRE_LOCK_TIMEOUT)
|
||||
if acquired:
|
||||
if args == '' or args is None:
|
||||
playlist.loop_all()
|
||||
embed = self.embeds.LOOP_ALL_ACTIVATED()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
args = args.lower()
|
||||
error = None
|
||||
if playlist.getCurrentSong() is None:
|
||||
embed = self.embeds.NOT_PLAYING()
|
||||
error = BadCommandUsage()
|
||||
@@ -36,16 +39,19 @@ class LoopHandler(AbstractHandler):
|
||||
if args == 'one':
|
||||
playlist.loop_one()
|
||||
embed = self.embeds.LOOP_ONE_ACTIVATED()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
elif args == 'all':
|
||||
playlist.loop_all()
|
||||
embed = self.embeds.LOOP_ALL_ACTIVATED()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
elif args == 'off':
|
||||
playlist.loop_off()
|
||||
embed = self.embeds.LOOP_DISABLE()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
else:
|
||||
error = BadCommandUsage()
|
||||
embed = self.embeds.BAD_LOOP_USE()
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
processLock.release()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
else:
|
||||
processManager.resetProcess(self.guild, self.ctx)
|
||||
embed = self.embeds.PLAYER_RESTARTED()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
@@ -20,10 +20,13 @@ class MoveHandler(AbstractHandler):
|
||||
error = BadCommandUsage()
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
with processInfo.getLock():
|
||||
processLock = processInfo.getLock()
|
||||
acquired = processLock.acquire(timeout=self.config.ACQUIRE_LOCK_TIMEOUT)
|
||||
if acquired:
|
||||
error = self.__validateInput(pos1, pos2)
|
||||
if error:
|
||||
embed = self.embeds.ERROR_EMBED(error.message)
|
||||
processLock.release()
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
playlist = processInfo.getPlaylist()
|
||||
@@ -32,17 +35,25 @@ class MoveHandler(AbstractHandler):
|
||||
if not playlist.validate_position(pos1) or not playlist.validate_position(pos2):
|
||||
error = InvalidInput()
|
||||
embed = self.embeds.PLAYLIST_RANGE_ERROR()
|
||||
processLock.release()
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
try:
|
||||
song = playlist.move_songs(pos1, pos2)
|
||||
|
||||
song_name = song.title if song.title else song.identifier
|
||||
embed = self.embeds.SONG_MOVED(song_name, pos1, pos2)
|
||||
processLock.release()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
except:
|
||||
# Release the acquired Lock
|
||||
processLock.release()
|
||||
embed = self.embeds.ERROR_MOVING()
|
||||
error = UnknownError()
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
else:
|
||||
processManager.resetProcess(self.guild, self.ctx)
|
||||
embed = self.embeds.PLAYER_RESTARTED()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
def __validateInput(self, pos1: str, pos2: str) -> Union[VulkanError, None]:
|
||||
try:
|
||||
|
||||
@@ -36,8 +36,8 @@ class PlayHandler(AbstractHandler):
|
||||
raise InvalidInput(self.messages.INVALID_INPUT, self.messages.ERROR_TITLE)
|
||||
|
||||
# Get the process context for the current guild
|
||||
manager = ProcessManager()
|
||||
processInfo = manager.getPlayerInfo(self.guild, self.ctx)
|
||||
processManager = ProcessManager()
|
||||
processInfo = processManager.getPlayerInfo(self.guild, self.ctx)
|
||||
playlist = processInfo.getPlaylist()
|
||||
process = processInfo.getProcess()
|
||||
if not process.is_alive(): # If process has not yet started, start
|
||||
@@ -56,22 +56,31 @@ class PlayHandler(AbstractHandler):
|
||||
error = DownloadingError()
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
# Add the unique song to the playlist and send a command to player process
|
||||
with processInfo.getLock():
|
||||
playlist.add_song(song)
|
||||
queue = processInfo.getQueue()
|
||||
playCommand = VCommands(VCommandsType.PLAY, None)
|
||||
queue.put(playCommand)
|
||||
|
||||
# If not playing
|
||||
if not playlist.getCurrentSong():
|
||||
embed = self.embeds.SONG_ADDED(song.title)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
response = HandlerResponse(self.ctx, embed)
|
||||
else: # If already playing
|
||||
pos = len(playlist.getSongs())
|
||||
embed = self.embeds.SONG_ADDED_TWO(song.info, pos)
|
||||
response = HandlerResponse(self.ctx, embed)
|
||||
|
||||
# Add the unique song to the playlist and send a command to player process
|
||||
processLock = processInfo.getLock()
|
||||
acquired = processLock.acquire(timeout=self.config.ACQUIRE_LOCK_TIMEOUT)
|
||||
if acquired:
|
||||
playlist.add_song(song)
|
||||
# Release the acquired Lock
|
||||
processLock.release()
|
||||
queue = processInfo.getQueue()
|
||||
playCommand = VCommands(VCommandsType.PLAY, None)
|
||||
queue.put(playCommand)
|
||||
else:
|
||||
processManager.resetProcess(self.guild, self.ctx)
|
||||
embed = self.embeds.PLAYER_RESTARTED()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
return response
|
||||
else: # If multiple songs added
|
||||
# Trigger a task to download all songs and then store them in the process playlist
|
||||
asyncio.create_task(self.__downloadSongsAndStore(songs, processInfo))
|
||||
|
||||
@@ -15,14 +15,16 @@ class QueueHandler(AbstractHandler):
|
||||
|
||||
async def run(self) -> HandlerResponse:
|
||||
# Retrieve the process of the guild
|
||||
process = ProcessManager()
|
||||
processInfo = process.getRunningPlayerInfo(self.guild)
|
||||
processManager = ProcessManager()
|
||||
processInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
if not processInfo: # If no process return empty list
|
||||
embed = self.embeds.EMPTY_QUEUE()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
# Acquire the Lock to manipulate the playlist
|
||||
with processInfo.getLock():
|
||||
processLock = processInfo.getLock()
|
||||
acquired = processLock.acquire(timeout=self.config.ACQUIRE_LOCK_TIMEOUT)
|
||||
if acquired:
|
||||
playlist = processInfo.getPlaylist()
|
||||
|
||||
if playlist.isLoopingOne():
|
||||
@@ -54,4 +56,10 @@ class QueueHandler(AbstractHandler):
|
||||
text += f"**`{pos}` - ** {song_name} - `{Utils.format_time(song.duration)}`\n"
|
||||
|
||||
embed = self.embeds.QUEUE(title, text)
|
||||
# Release the acquired Lock
|
||||
processLock.release()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
else:
|
||||
processManager.resetProcess(self.guild, self.ctx)
|
||||
embed = self.embeds.PLAYER_RESTARTED()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
@@ -15,9 +15,17 @@ class ShuffleHandler(AbstractHandler):
|
||||
processInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
if processInfo:
|
||||
try:
|
||||
with processInfo.getLock():
|
||||
processLock = processInfo.getLock()
|
||||
acquired = processLock.acquire(timeout=self.config.ACQUIRE_LOCK_TIMEOUT)
|
||||
if acquired:
|
||||
playlist = processInfo.getPlaylist()
|
||||
playlist.shuffle()
|
||||
# Release the acquired Lock
|
||||
processLock.release()
|
||||
else:
|
||||
processManager.resetProcess(self.guild, self.ctx)
|
||||
embed = self.embeds.PLAYER_RESTARTED()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
embed = self.embeds.SONGS_SHUFFLED()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
Reference in New Issue
Block a user