@@ -848,6 +848,11 @@ taskmanager.deleteResult = function(options, callback) {
848848 if ( task . gridfs ) {
849849 countlyFs . gridfs . deleteFile ( "task_results" , options . id , { id : options . id } , function ( ) { } ) ;
850850 }
851+
852+ // Delete additional results specific to task type
853+ taskmanager . deleteAdditionalResults ( task , options , function ( ) {
854+ // Continue with normal task deletion
855+ } ) ;
851856 options . db . collection ( "long_tasks" ) . remove ( { _id : options . id } , function ( ) {
852857 callback ( null , task ) ;
853858 } ) ;
@@ -863,6 +868,45 @@ taskmanager.deleteResult = function(options, callback) {
863868 } ) ;
864869} ;
865870
871+ /**
872+ * Delete additional results specific to task type
873+ * @param {object } task - the task object
874+ * @param {object } options - options for the task
875+ * @param {function } callback - callback for the result
876+ */
877+ taskmanager . deleteAdditionalResults = function ( task , options , callback ) {
878+ if ( task . type === "journey_engine" ) {
879+ const collectionName = "journey_task_data_" + options . id ;
880+ options . db . collection ( collectionName ) . drop ( function ( dropErr ) {
881+ if ( dropErr && dropErr . code !== 26 ) { // 26 = namespace not found, which is fine
882+ log . w ( "Failed to drop journey task data collection:" , collectionName , dropErr ) ;
883+ }
884+ else {
885+ log . d ( "Successfully dropped journey task data collection:" , collectionName ) ;
886+ }
887+ } ) ;
888+
889+ // Also try to clean up the default collection if it exists and is empty
890+ // This is a safety measure for cases where the default collection might have been used
891+ options . db . collection ( "journey_task_data" ) . countDocuments ( { } , function ( countErr , count ) {
892+ if ( ! countErr && count === 0 ) {
893+ options . db . collection ( "journey_task_data" ) . drop ( function ( defaultDropErr ) {
894+ if ( defaultDropErr && defaultDropErr . code !== 26 ) {
895+ log . w ( "Failed to drop default journey task data collection:" , defaultDropErr ) ;
896+ }
897+ else if ( ! defaultDropErr ) {
898+ log . d ( "Successfully dropped empty default journey task data collection" ) ;
899+ }
900+ } ) ;
901+ }
902+ callback ( ) ;
903+ } ) ;
904+ }
905+ else {
906+ callback ( ) ;
907+ }
908+ } ;
909+
866910/**
867911* Mark all running or rerunning tasks as errored
868912* @param {object } options - options for the task
0 commit comments