Skip to content

Commit 8337409

Browse files
refactor
1 parent 1383c35 commit 8337409

25 files changed

Lines changed: 34 additions & 2663 deletions

README.md

Lines changed: 4 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
55
## Status
66
[![codecov](https://img.shields.io/codecov/c/github/adobe-rnd/spacecat-task-processor.svg)](https://codecov.io/gh/adobe-rnd/spacecat-task-processor)
7-
[![CircleCI](https://img.shields.io/circleci/project/github/adobe-rnd/spacecat-audit-worker.svg)](https://circleci.com/gh/adobe-rnd/spacecat-audit-worker)
8-
[![GitHub license](https://img.shields.io/github/license/adobe-rnd/spacecat-audit-worker.svg)](https://github.com/adobe-rnd/spacecat-audit-worker/blob/master/LICENSE.txt)
9-
[![GitHub issues](https://img.shields.io/github/issues/adobe-rnd/spacecat-audit-worker.svg)](https://github.com/adobe-rnd/spacecat-audit-worker/issues)
10-
[![LGTM Code Quality Grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/adobe-rnd/spacecat-audit-worker.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/adobe-rnd/spacecat-audit-worker)
7+
[![CircleCI](https://img.shields.io/circleci/project/github/adobe-rnd/spacecat-audit-worker.svg)](https://circleci.com/gh/adobe-rnd/spacecat-task-processor)
8+
[![GitHub license](https://img.shields.io/github/license/adobe-rnd/spacecat-task-processor.svg)](https://github.com/adobe-rnd/spacecat-task-processor/blob/master/LICENSE.txt)
9+
[![GitHub issues](https://img.shields.io/github/issues/adobe-rnd/spacecat-task-processor.svg)](https://github.com/adobe-rnd/spacecat-task-processor/issues)
10+
[![LGTM Code Quality Grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/adobe-rnd/spacecat-task-processor.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/adobe-rnd/spacecat-task-processor)
1111
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
1212

1313
## Installation
@@ -52,98 +52,3 @@ Expected message body format in `SPACECAT-TASK-PROCESSOR-JOBS` is:
5252
"siteId": "string"
5353
}
5454
```
55-
56-
Output message body format sent to `SPACECAT-TASK-PROCESSOR-JOBS` is:
57-
58-
```json
59-
{
60-
"type": "string",
61-
"url": "string",
62-
"auditContext": "object",
63-
"auditResult": "object"
64-
}
65-
```
66-
67-
## How to Run Locally
68-
69-
### 1. Using `nodemon` and AWS Credentials
70-
71-
Everyone working on Spacecat should have access to the development environments via [KLAM](https://klam.corp.adobe.com/).
72-
If you don’t have access, please refer to the engineering onboarding guide or contact your Spacecat team representative.
73-
74-
After logging into KLAM, you’ll receive the following credentials required to access AWS resources such as DynamoDB and S3 for local development:
75-
76-
- `AWS_ACCESS_KEY_ID`
77-
- `AWS_SECRET_ACCESS_KEY`
78-
- `AWS_SESSION_TOKEN`
79-
80-
**IMPORTANT: DO NOT USE THE AWS TOKENS FROM KLAM PRODUCTION PROFILES. USE ONLY DEV TOKENS.**
81-
82-
83-
### Steps to use `nodemon`
84-
85-
#### 1. Create an `.env` File
86-
87-
Create a `.env` file in the root directory with the following environment variables, which are required for all audits.
88-
Add any additional environment variables specific to the audit you're working on.
89-
90-
```
91-
AWS_REGION=us-east-1
92-
DYNAMO_TABLE_NAME_DATA=spacecat-services-data
93-
AWS_ACCESS_KEY_ID=<acquired from KLAM>
94-
AWS_SECRET_ACCESS_KEY=<acquired from KLAM>
95-
AWS_SESSION_TOKEN=<acquired from KLAM>
96-
# ... other required variables depending on the audit
97-
```
98-
99-
#### 2. Run/Debug with `npm start`
100-
101-
Once your `.env` file is set up, start the local development server using:
102-
103-
```bash
104-
npm start
105-
```
106-
107-
To use breakpoints, make sure to use the debugging tools provided by your IDE (e.g., VSCode, WebStorm, etc.).
108-
109-
#### 3. Trigger a Task
110-
111-
With the server running, you can trigger a task using a `curl` POST request. The request body should include the task type and `siteId`:
112-
113-
```json
114-
{
115-
"type": "<task handler name>",
116-
"siteId": "<siteId>"
117-
}
118-
```
119-
120-
- A list of task handler names can be found in the [index.js file](https://github.com/adobe/spacecat-task-processor/blob/main/src/index.js#L45).
121-
- You can retrieve a `siteId` using:
122-
- The [Spacecat API](https://opensource.adobe.com/spacecat-api-service/#tag/site/operation/getSiteByBaseUrl)
123-
- The Slack command: `@spacecat-dev get site domain.com`
124-
125-
Example `curl` request to trigger the "demo-url" task:
126-
127-
```bash
128-
curl -X POST http://localhost:3000 \
129-
-H "Content-Type: application/json" \
130-
-d '{ "type": "demo-url", "siteId": "9ab0575a-c238-4470-ae82-9d37fb2d0e78" }'
131-
```
132-
133-
### 2. Using AWS SAM and Docker.
134-
135-
1. Ensure you have [Docker](https://docs.docker.com/desktop/setup/install/mac-install/), [AWS SAM](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html) and [jq](https://jqlang.org/) installed.
136-
2. Login to AWS using [KLAM](https://klam.corp.adobe.com/) and login with your [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html).
137-
* KLAM dev project: `SpaceCat Development (AWS3338)`
138-
3. To provide secrets to the audit, please run `./scripts/populate-env.sh` once. It will fetch all secrets from the AWS Secret Manager.
139-
4. To run the audit locally, execute the following commands:
140-
```bash
141-
source env.sh
142-
npm run local-build
143-
npm run local-run
144-
```
145-
5. Starting point of the execution is `src/index-local.js`. Output of the audit can be found in `output.txt`.
146-
6. To hot reload any changes in the `/src` folder, you can use `npm run local-watch`. Note: This will require to run `npm run local-build` at least once beforehand.
147-
148-
If you need to add additional secrets, make sure to adjust the Lambda `template.yml` accordingly.
149-

docs/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
2-

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
},
1111
"scripts": {
1212
"start": "nodemon",
13-
"test": "c8 --exclude=src/support/** --exclude=src/utils/** --exclude=src/audit-status-processor/** --exclude=src/disable-import-audit-processor/** --exclude=src/demo-url/** --exclude=src/index.js --exclude=src/index-local.js --exclude=src/preflight/** mocha 'test/**/*.test.js' --ignore test/index.test.js",
14-
"test:index": "mocha test/index.test.js",
13+
"test": "NODE_ENV=test mocha 'test/**/*.test.js'",
14+
"test:index": "NODE_ENV=test mocha test/index.test.js",
1515
"test-postdeploy": "mocha -g 'Post-Deploy' --spec=test/**/*.test.js",
1616
"lint": "eslint .",
1717
"lint:fix": "eslint . --fix",

src/audit-status-processor/handler.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 Adobe. All rights reserved.
2+
* Copyright 2025 Adobe. All rights reserved.
33
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License. You may obtain a copy
55
* of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import { Audit } from '@adobe/spacecat-shared-data-access';
14-
import { sendSlackMessage } from '../support/slack-utils.js';
14+
import { say } from '../utils/slack-utils.js';
1515

1616
const AUDIT_TYPE = 'audit-status-processor';
1717

@@ -36,7 +36,7 @@ export async function runAuditStatusProcessor(auditStatusMessage, context) {
3636
auditTypes,
3737
});
3838

39-
await sendSlackMessage(env, log, slackContext, 'Checking audit status');
39+
await say(env, log, slackContext, 'Checking audit status');
4040
try {
4141
// Check latest audit status for each audit type in parallel
4242
const auditStatusPromises = auditTypes.map(async (auditType) => {
@@ -47,11 +47,11 @@ export async function runAuditStatusProcessor(auditStatusMessage, context) {
4747
if (auditResult.success) {
4848
log.info(`Latest audit for site ${siteId} was successful for audit type ${auditType}`);
4949
const slackMessage = `:check_mark: Latest audit for site ${siteId} was successful for audit type ${auditType}`;
50-
return sendSlackMessage(env, log, slackContext, slackMessage);
50+
return say(env, log, slackContext, slackMessage);
5151
} else {
5252
log.warn(`Latest audit for site ${siteId} failed for audit type ${auditType}: ${auditResult.error || 'Unknown error'}`);
5353
const slackMessage = `:x: Latest audit for site ${siteId} failed for audit type ${auditType}: ${auditResult.error || 'Unknown error'}`;
54-
return sendSlackMessage(env, log, slackContext, slackMessage);
54+
return say(env, log, slackContext, slackMessage);
5555
}
5656
} else {
5757
log.info(`No previous ${auditType} audit found for site ${siteId}`);
@@ -60,7 +60,7 @@ export async function runAuditStatusProcessor(auditStatusMessage, context) {
6060
});
6161
await Promise.all(auditStatusPromises);
6262
log.info('Audit status checking completed');
63-
await sendSlackMessage(env, log, slackContext, 'Audit status checking completed');
63+
await say(env, log, slackContext, 'Audit status checking completed');
6464
} catch (error) {
6565
log.error('Error in audit status checking:', {
6666
error: error.message,
Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 Adobe. All rights reserved.
2+
* Copyright 2025 Adobe. All rights reserved.
33
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License. You may obtain a copy
55
* of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -10,7 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import { sendSlackMessage } from '../support/slack-utils.js';
13+
import { say } from '../utils/slack-utils.js';
1414

1515
/** Prepare demo url for the site */
1616
function prepareDemoUrl(experienceUrl, organizationId, siteId) {
@@ -37,41 +37,19 @@ export async function runDemoUrlProcessor(demoUrlMessage, context) {
3737
organizationId,
3838
});
3939

40-
await sendSlackMessage(env, log, slackContext, 'Preparing demo url');
40+
await say(env, log, slackContext, 'Preparing demo url');
4141
try {
4242
// prepare demo url
4343
const demoUrl = prepareDemoUrl(siteUrl, organizationId, siteId);
4444
log.info(`Setup complete! Access your demo environment here: ${demoUrl}`);
4545
const slackMessage = `:white_check_mark: Setup complete! Access your demo environment here: ${demoUrl}`;
46-
await sendSlackMessage(env, log, slackContext, slackMessage);
47-
return {
48-
siteId,
49-
demoUrlResult: {
50-
status: 'Completed',
51-
siteId,
52-
organizationId,
53-
experienceUrl: siteUrl,
54-
success: true,
55-
},
56-
fullAuditRef: siteUrl,
57-
};
46+
await say(env, log, slackContext, slackMessage);
5847
} catch (error) {
5948
log.error('Error in preparing demo url:', {
6049
error: error.message,
6150
stack: error.stack,
6251
errorType: error.name,
6352
});
64-
65-
return {
66-
siteId,
67-
demoUrlResult: {
68-
status: 'error',
69-
siteId,
70-
error: `Preparing demo url failed for ${siteId}: ${error.message}`,
71-
success: false,
72-
},
73-
fullAuditRef: siteUrl,
74-
};
7553
}
7654
}
7755

src/disable-import-audit-processor/handler.js

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 Adobe. All rights reserved.
2+
* Copyright 2025 Adobe. All rights reserved.
33
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License. You may obtain a copy
55
* of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import { Site } from '@adobe/spacecat-shared-data-access';
14-
import { sendSlackMessage } from '../support/slack-utils.js';
14+
import { say } from '../utils/slack-utils.js';
1515

1616
const AUDIT_TYPE = 'disable-import-audit-processor';
1717

@@ -36,7 +36,7 @@ export async function runDisableImportAuditProcessor(message, context) {
3636
importTypes,
3737
auditTypes,
3838
});
39-
await sendSlackMessage(env, log, slackContext, ':broom: Disabling imports and audits...');
39+
await say(env, log, slackContext, ':broom: Disabling imports and audits...');
4040
try {
4141
// Database operations
4242
log.info('Starting database operations');
@@ -63,35 +63,13 @@ export async function runDisableImportAuditProcessor(message, context) {
6363
log.info('Database changes saved successfully');
6464

6565
const slackMessage = `:check_mark: Disabled imports ${JSON.stringify(importTypes)} and audits ${JSON.stringify(auditTypes)} for site ${siteId}`;
66-
await sendSlackMessage(env, log, slackContext, slackMessage);
67-
68-
return {
69-
siteId,
70-
result: {
71-
status: 'Completed',
72-
siteId,
73-
organizationId,
74-
disabledImports: importTypes,
75-
disabledAudits: auditTypes,
76-
success: true,
77-
},
78-
};
66+
await say(env, log, slackContext, slackMessage);
7967
} catch (error) {
8068
log.error('Error in disable import and audit processor:', {
8169
error: error.message,
8270
stack: error.stack,
8371
errorType: error.name,
8472
});
85-
86-
return {
87-
siteId,
88-
result: {
89-
status: 'error',
90-
siteId,
91-
error: `Disable import and audit processing failed for ${siteId}: ${error.message}`,
92-
success: false,
93-
},
94-
};
9573
}
9674
}
9775

src/index-local.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 Adobe. All rights reserved.
2+
* Copyright 2025 Adobe. All rights reserved.
33
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License. You may obtain a copy
55
* of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -16,8 +16,6 @@ import dataAccess from '@adobe/spacecat-shared-data-access';
1616
import { resolveSecretsName, sqsEventAdapter } from '@adobe/spacecat-shared-utils';
1717
import { internalServerError, notFound, ok } from '@adobe/spacecat-shared-http-utils';
1818

19-
import sqs from './support/sqs.js';
20-
import s3Client from './support/s3-client.js';
2119
import { runAuditStatusProcessor as auditStatusProcessor } from './audit-status-processor/handler.js';
2220
import { runDisableImportAuditProcessor as disableImportAuditProcessor } from './disable-import-audit-processor/handler.js';
2321

@@ -96,7 +94,5 @@ async function run(message, context) {
9694
export const main = wrap(run)
9795
.with(dataAccess)
9896
.with(sqsEventAdapter)
99-
.with(sqs)
100-
.with(s3Client)
10197
.with(secrets, { name: resolveSecretsName })
10298
.with(helixStatus);

0 commit comments

Comments
 (0)