/* UPDATE NOTIFICATION IN QUEUE AS SENT */
/* =============================================================================================================== */
drop procedure if exists updateNotificationAsSent;
commit;

delimiter //

CREATE PROCEDURE `updateNotificationAsSent`(`p_queueId` int, `p_ticket` varchar(255))
BEGIN

DECLARE errno int;

DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
	GET CURRENT DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO;

	INSERT INTO debug_log(activity, ts_when, log) 
  SELECT 'PROC ERR: notifSent', now(), errno; 

	RESIGNAL;
END;

UPDATE `NotificationQueue`
SET `status` = 'sent',
  `ticket` = p_ticket,
  `attempts` = `attempts` + 1,
  `sentAt` = NOW(),
  `updatedAt` = NOW()
WHERE `_id` = p_queueId;

CALL getNextNotificationInQueue();

END
//

commit //

delimiter ;

