1010 * governing permissions and limitations under the License.
1111 */
1212
13+ import { ok } from '@adobe/spacecat-shared-http-utils' ;
1314import { say } from '../../utils/slack-utils.js' ;
1415
1516const TASK_TYPE = 'opportunity-status-processor' ;
@@ -47,26 +48,25 @@ function getOpportunityTitle(opportunityType) {
4748export async function runOpportunityStatusProcessor ( message , context ) {
4849 const { log, env, dataAccess } = context ;
4950 const { Site } = dataAccess ;
50- log . info ( 'Running opportunity status processor' ) ;
5151 const { siteId, organizationId, taskContext } = message ;
5252 const {
53- auditTypes, slackContext,
53+ auditTypes = [ ] , slackContext,
5454 } = taskContext ;
5555
56- log . info ( 'Processing opportunity status for site:' , {
56+ log . info ( 'Processing opportunities for site:' , {
57+ taskType : TASK_TYPE ,
5758 siteId,
5859 organizationId,
59- taskType : TASK_TYPE ,
6060 auditTypes,
6161 } ) ;
6262
6363 try {
6464 // Get the site and its opportunities
65- const site = await Site . findById ( siteId ) ;
65+ const site = await Site . findByBaseURL ( `https:// ${ siteId } .com` ) ;
6666 if ( ! site ) {
6767 log . error ( `Site not found for siteId: ${ siteId } ` ) ;
6868 await say ( env , log , slackContext , `:x: Site not found for siteId: ${ siteId } ` ) ;
69- return ;
69+ return ok ( { message : 'Site not found' } ) ;
7070 }
7171
7272 const opportunities = await site . getOpportunities ( ) ;
@@ -76,49 +76,35 @@ export async function runOpportunityStatusProcessor(message, context) {
7676 const processedTypes = new Set ( ) ;
7777 const statusMessages = [ ] ;
7878
79- // Process each opportunity
8079 for ( const opportunity of opportunities ) {
8180 const opportunityType = opportunity . getType ( ) ;
82-
83- // Skip if we've already processed this opportunity type
8481 if ( processedTypes . has ( opportunityType ) ) {
8582 // eslint-disable-next-line no-continue
8683 continue ;
8784 }
88-
89- // Mark this type as processed
9085 processedTypes . add ( opportunityType ) ;
9186
92- // Get suggestions for this opportunity
9387 // eslint-disable-next-line no-await-in-loop
9488 const suggestions = await opportunity . getSuggestions ( ) ;
9589
9690 // Get the opportunity title
9791 const opportunityTitle = getOpportunityTitle ( opportunityType ) ;
98-
99- // Determine status based on suggestions length
10092 const hasSuggestions = suggestions && suggestions . length > 0 ;
10193 const status = hasSuggestions ? ':white_check_mark:' : ':cross-x:' ;
102-
103- // Add to status messages array
10494 statusMessages . push ( `${ opportunityTitle } ${ status } ` ) ;
10595 }
10696
107- // Send combined status message
97+ // send status messages to slack
10898 if ( statusMessages . length > 0 ) {
10999 const combinedMessage = statusMessages . join ( '\n' ) ;
110100 await say ( env , log , slackContext , combinedMessage ) ;
111101 }
112-
113- log . info ( 'Opportunity status checking completed' ) ;
114102 } catch ( error ) {
115- log . error ( 'Error in opportunity status checking:' , {
116- error : error . message ,
117- stack : error . stack ,
118- errorType : error . name ,
119- } ) ;
103+ log . error ( 'Error in opportunity status processor:' , error ) ;
120104 await say ( env , log , slackContext , `:x: Error checking site opportunities status: ${ error . message } ` ) ;
121105 }
106+
107+ return ok ( { message : 'Opportunity status processor completed' } ) ;
122108}
123109
124110export default runOpportunityStatusProcessor ;
0 commit comments