Skip to content

Commit 82140a7

Browse files
committed
Merge branch 'master' of github.com:codex-team/hawk.workers into new-diff
2 parents eb76467 + b9aeb41 commit 82140a7

27 files changed

Lines changed: 788 additions & 167 deletions

File tree

.github/workflows/build-and-push-docker-image.yml

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,36 @@ env:
77

88
jobs:
99
build:
10-
runs-on: ubuntu-20.04
10+
runs-on: ubuntu-22.04
1111
if: endsWith(github.ref, '/prod') || endsWith(github.ref, '/stage') || endsWith(github.ref, '/migration')
1212
steps:
1313
- name: Checkout repository
14-
uses: actions/checkout@v2
14+
uses: actions/checkout@v4
1515

1616
- name: Set up Docker Buildx
17-
uses: docker/setup-buildx-action@v1
17+
uses: docker/setup-buildx-action@v3
1818

1919
- name: Login to DockerHub
20-
uses: docker/login-action@v1
20+
uses: docker/login-action@v3
2121
with:
2222
username: ${{ secrets.DOCKER_USERNAME }}
2323
password: ${{ secrets.DOCKER_PASSWORD }}
2424

25-
- name: Build and push production image
26-
if: endsWith(github.ref, '/prod')
27-
uses: docker/build-push-action@v2
28-
with:
29-
context: .
30-
file: ./Dockerfile
31-
tags: ${{ env.DOCKER_REPO }}:prod
32-
push: ${{ endsWith(github.ref, '/prod') }}
33-
34-
- name: Build and push stage image
35-
if: endsWith(github.ref, '/stage')
36-
uses: docker/build-push-action@v2
25+
- name: Extract metadata (tags, labels) for Docker
26+
id: meta
27+
uses: docker/metadata-action@v5
3728
with:
38-
context: .
39-
file: ./stage.Dockerfile
40-
tags: ${{ env.DOCKER_REPO }}:stage
41-
push: ${{ endsWith(github.ref, '/stage') }}
29+
images: ${{ env.DOCKER_REPO }}
30+
tags: |
31+
type=ref,event=branch
32+
type=ref,event=pr
33+
type=raw,value=latest,enable={{is_default_branch}}
34+
type=raw,value={{branch}}-{{sha}}-{{date 'X'}},enable=${{ startsWith(github.ref, 'refs/heads') }}
4235
43-
- name: Build and push migration image
44-
if: endsWith(github.ref, '/migration')
45-
uses: docker/build-push-action@v2
36+
- name: Build and push production image
37+
uses: docker/build-push-action@v5
4638
with:
4739
context: .
48-
file: ./stage.Dockerfile
49-
tags: ${{ env.DOCKER_REPO }}:migration
50-
push: ${{ endsWith(github.ref, '/migration') }}
40+
file: ./Dockerfile
41+
tags: ${{ steps.meta.outputs.tags }}
42+
push: true

.github/workflows/check-build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
build:
10-
runs-on: ubuntu-20.04
10+
runs-on: ubuntu-22.04
1111
steps:
1212
- name: Checkout repository
1313
uses: actions/checkout@v2

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on: [push]
55
jobs:
66
lint:
77
name: Unit testing
8-
runs-on: ubuntu-20.04
8+
runs-on: ubuntu-22.04
99
steps:
1010
- uses: actions/checkout@v2
1111
- name: Use Node.js 16.x

.github/workflows/update-monorepository.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ env:
77
REPOSITORY_MONO_PATH: workers
88
jobs:
99
build:
10-
runs-on: ubuntu-20.04
10+
runs-on: ubuntu-22.04
1111
steps:
1212
- name: Mono repository update
1313
uses: peter-evans/repository-dispatch@v1

jest-mongodb-config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module.exports = {
33
instance: {
44
port: 55010,
55
dbName: 'hawk',
6+
replSet: 'rs0',
7+
storageEngine: 'wiredTiger',
68
},
79
binary: {
810
version: '6.0.2',

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ module.exports = {
2727

2828
setupFiles: [ './jest.setup.js' ],
2929

30-
setupFilesAfterEnv: [ './jest.setup.redis-mock.js' ],
30+
setupFilesAfterEnv: ['./jest.setup.redis-mock.js', './jest.setup.mongo-repl-set.js'],
3131
};

jest.setup.mongo-repl-set.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const { MongoClient } = require('mongodb');
2+
3+
let admin;
4+
let connection;
5+
6+
beforeAll(async () => {
7+
connection = await MongoClient.connect('mongodb://127.0.0.1:55010/hawk?', {
8+
useNewUrlParser: true,
9+
useUnifiedTopology: true,
10+
});
11+
12+
admin = connection.db().admin();
13+
14+
try {
15+
let status = await admin.command({ replSetGetStatus: 1 }).catch(() => null);
16+
17+
if (status && status.ok) {
18+
console.log('✅ Replica set already initialized');
19+
} else {
20+
await admin.command({ replSetInitiate: {} });
21+
console.log('✅ Replica set initiated');
22+
}
23+
24+
const startTime = Date.now();
25+
const timeout = 15000;
26+
27+
/**
28+
* Wait for the replica set to initialize all nodes
29+
*/
30+
do {
31+
await new Promise(resolve => setTimeout(resolve, 1000));
32+
status = await admin.command({ replSetGetStatus: 1 });
33+
34+
const primary = status.members.find(member => member.stateStr === 'PRIMARY');
35+
const secondary = status.members.find(member => member.stateStr === 'SECONDARY');
36+
37+
if (primary && secondary) {
38+
break;
39+
}
40+
} while (Date.now() - startTime < timeout);
41+
42+
console.log('✅ Replica set is stable');
43+
} catch (err) {
44+
console.error('❌ Failed to initiate replica set:', err);
45+
}
46+
}, 30000);
47+
48+
afterAll(async () => {
49+
await connection.close();
50+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* This migration creates indexes for all collections on payload.title field
3+
*/
4+
5+
/**
6+
* Index name for payload.title field
7+
*/
8+
const payloadTitleIndexName = 'payloadTitle';
9+
10+
module.exports = {
11+
async up(db) {
12+
const collections = await db.listCollections({}, {
13+
authorizedCollections: true,
14+
nameOnly: true,
15+
}).toArray();
16+
17+
const targetCollections = [];
18+
19+
collections.forEach((collection) => {
20+
if (/events/.test(collection.name)) {
21+
targetCollections.push(collection.name);
22+
}
23+
});
24+
25+
for (const collectionName of targetCollections) {
26+
const hasIndexAlready = await db.collection(collectionName).indexExists(payloadTitleIndexName);
27+
28+
if (!hasIndexAlready) {
29+
await db.collection(collectionName).createIndex({
30+
'payload.title': 1,
31+
}, {
32+
name: payloadTitleIndexName,
33+
});
34+
}
35+
}
36+
},
37+
async down(db) {
38+
const collections = await db.listCollections({}, {
39+
authorizedCollections: true,
40+
nameOnly: true,
41+
}).toArray();
42+
43+
const targetCollections = [];
44+
45+
collections.forEach((collection) => {
46+
if (/events/.test(collection.name)) {
47+
targetCollections.push(collection.name);
48+
}
49+
});
50+
51+
for (const collectionName of targetCollections) {
52+
await db.collection(collectionName).dropIndex(payloadTitleIndexName);
53+
}
54+
},
55+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
},
4949
"dependencies": {
5050
"@hawk.so/nodejs": "^3.1.1",
51-
"@hawk.so/types": "^0.1.26",
51+
"@hawk.so/types": "^0.1.29",
5252
"@types/amqplib": "^0.8.2",
5353
"@types/jest": "^29.2.3",
5454
"@types/mongodb": "^3.5.15",

workers/archiver/tests/index.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ process.env.MAX_DAYS_NUMBER = '30';
1818

1919
const mockedProject: ProjectDBScheme = {
2020
notifications: [],
21+
eventGroupingPatterns: [],
2122
token: '5342',
2223
integrationId: 'eyJpbnRlZ3JhdGlvbklkIjoiMzg3NGNkOWMtZjJiYS00ZDVkLTk5ZmQtM2UzZjYzMDcxYmJhIiwic2VjcmV0IjoiMGZhM2JkM2EtYmMyZC00YWRiLThlMWMtNjg2OGY0MzM1YjRiIn0=',
2324
uidAdded: new ObjectId('5e4ff518628a6c714515f4db'),
@@ -53,7 +54,7 @@ describe('Archiver worker', () => {
5354

5455
beforeEach(async () => {
5556
await db.collection('releases').deleteMany({});
56-
})
57+
});
5758

5859
test('Should correctly remove old events', async () => {
5960
/**
@@ -129,7 +130,7 @@ describe('Archiver worker', () => {
129130
/**
130131
* Insert one release with object id based on current time, it should not be removed
131132
*/
132-
await db.collection('releases').insert(releasesToStay)
133+
await db.collection('releases').insert(releasesToStay);
133134

134135
const worker = new ArchiverWorker();
135136

@@ -173,9 +174,9 @@ describe('Archiver worker', () => {
173174
expect(newReleasesCollection).toEqual([
174175
mockedReleases[mockedReleasesLength - 2],
175176
mockedReleases[mockedReleasesLength - 1],
176-
])
177+
]);
177178
await worker.finish();
178-
})
179+
});
179180

180181
afterAll(async () => {
181182
await db.dropCollection('releases');

0 commit comments

Comments
 (0)