Skip to content

Commit 40dff0e

Browse files
Merge pull request #335 from boostcampwm-2024/bug-be-#326
redis 오류 수정
2 parents 3851f86 + 5a2025d commit 40dff0e

File tree

7 files changed

+110
-97
lines changed

7 files changed

+110
-97
lines changed

apps/backend/src/app.module.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ import { TasksService } from './tasks/tasks.service';
3939
imports: [ConfigModule],
4040
inject: [ConfigService],
4141
useFactory: (configService: ConfigService) => ({
42-
type: 'postgres',
43-
host: configService.get('DB_HOST'),
44-
port: configService.get('DB_PORT'),
45-
username: configService.get('DB_USER'),
46-
password: configService.get('DB_PASSWORD'),
47-
database: configService.get('DB_NAME'),
42+
type: 'sqlite',
43+
database: 'db.sqlite',
44+
// type: 'postgres',
45+
// host: configService.get('DB_HOST'),
46+
// port: configService.get('DB_PORT'),
47+
// username: configService.get('DB_USER'),
48+
// password: configService.get('DB_PASSWORD'),
49+
// database: configService.get('DB_NAME'),
4850
entities: [Node, Page, Edge, User, Workspace, Role],
4951
logging: true,
5052
synchronize: true,

apps/backend/src/page/page.entity.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
CreateDateColumn,
99
UpdateDateColumn,
1010
VersionColumn,
11+
IsNull,
1112
} from 'typeorm';
1213
import { Node } from '../node/node.entity';
1314
import { Workspace } from '../workspace/workspace.entity';
@@ -17,10 +18,10 @@ export class Page {
1718
@PrimaryGeneratedColumn('increment')
1819
id: number;
1920

20-
@Column()
21+
@Column({ nullable: true })
2122
title: string;
2223

23-
@Column('json') //TODO: Postgres에서는 jsonb로 변경
24+
@Column('json', { nullable: true }) //TODO: Postgres에서는 jsonb로 변경
2425
content: JSON;
2526

2627
@CreateDateColumn()

apps/backend/src/redis/redis.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export class RedisService {
99
private readonly redisClient: Redis;
1010

1111
constructor() {
12+
console.log('====================');
13+
console.log(process.env.REDIS_HOST);
14+
console.log(process.env.REDIS_PORT);
1215
this.redisClient = new Redis({
1316
host: process.env.REDIS_HOST,
1417
port: parseInt(process.env.REDIS_PORT),

apps/backend/src/tasks/tasks.service.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@ export class TasksService {
1616
console.log(await this.redisService.getAllKeys());
1717
const keys = await this.redisService.getAllKeys();
1818
const pages = [];
19-
19+
this.logger.log('스케줄러 시작');
2020
for await (const key of keys) {
2121
const { title, content } = await this.redisService.get(key);
22-
console.log('title,', title);
23-
console.log('content,', content);
2422
const jsonContent = JSON.parse(content);
2523
pages.push({
2624
id: key,
2725
title,
2826
content: jsonContent,
2927
version: 1,
3028
});
31-
// this.pageService.updatePage(parseInt(key), {
32-
// title,
33-
// content: jsonContent,
34-
// });
29+
this.pageService.updatePage(parseInt(key), {
30+
title,
31+
content: jsonContent,
32+
});
33+
this.logger.log('데이터베이스 갱신');
3534
}
3635
this.pageService.updateBulkPage(pages);
3736
}

apps/backend/src/workspace/workspace.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export class WorkspaceService {
3434
private readonly roleRepository: RoleRepository,
3535
private readonly tokenService: TokenService,
3636
) {
37-
console.log('환경 : ', process.env.NODE_ENV);
3837
if (process.env.NODE_ENV !== 'test') {
3938
this.initializeMainWorkspace();
4039
}

apps/backend/src/yjs/yjs.service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export class YjsService
7070
// 노드를 클릭해 페이지를 열었을 때만 해당 페이지 값을 가져와서 초기 데이터로 세팅해줍니다.
7171
if (customDoc.name?.startsWith('document-')) {
7272
const workspaceId = doc.guid;
73-
console.log('workspaceid', workspaceId);
7473
const pageId = parseInt(customDoc.name.split('-')[1]);
7574
const findPage = await this.pageService.findPageById(pageId);
7675

@@ -101,9 +100,9 @@ export class YjsService
101100
'content',
102101
JSON.stringify(yXmlFragmentToProsemirrorJSON(editorDoc)),
103102
);
104-
this.redisService.get(pageId.toString()).then((data) => {
105-
console.log(data);
106-
});
103+
// this.redisService.get(pageId.toString()).then((data) => {
104+
// console.log(data);
105+
// });
107106
});
108107
return;
109108
}
@@ -116,7 +115,10 @@ export class YjsService
116115
if (!customDoc.name?.startsWith('flow-room-')) {
117116
return;
118117
}
119-
const workspaceId = customDoc.name.split('-')[2];
118+
119+
// const workspaceId = customDoc.name.split('-')[2];
120+
// console.log('======', workspaceId);
121+
const workspaceId = 'main';
120122
const nodes = await this.nodeService.findNodesByWorkspace(workspaceId);
121123
const edges = await this.edgeService.findEdgesByWorkspace(workspaceId);
122124
const nodesMap = doc.getMap('nodes');
@@ -155,8 +157,6 @@ export class YjsService
155157
});
156158
// node의 변경 사항을 감지한다.
157159
nodesMap.observe(async (event) => {
158-
console.log('nodesmap', nodesMap.toJSON());
159-
console.log('노드 개수', event.changes.keys);
160160
for (const [key, change] of event.changes.keys) {
161161
if (change.action === 'update') {
162162
const node: any = nodesMap.get(key);

compose.local.yml

Lines changed: 83 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,93 @@
11
version: "3.8"
22

33
services:
4-
postgres:
5-
image: postgres:16-alpine
6-
environment:
7-
POSTGRES_USER: ${DB_USER}
8-
POSTGRES_PASSWORD: ${DB_PASSWORD}
9-
POSTGRES_DB: ${DB_NAME}
10-
volumes:
11-
- postgres_data:/var/lib/postgresql/data
12-
networks:
13-
- backend
14-
healthcheck:
15-
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
16-
interval: 10s
17-
timeout: 5s
18-
retries: 5
4+
postgres:
5+
image: postgres:16-alpine
6+
environment:
7+
POSTGRES_USER: ${DB_USER}
8+
POSTGRES_PASSWORD: ${DB_PASSWORD}
9+
POSTGRES_DB: ${DB_NAME}
10+
volumes:
11+
- postgres_data:/var/lib/postgresql/data
12+
networks:
13+
- net
14+
healthcheck:
15+
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
16+
interval: 10s
17+
timeout: 5s
18+
retries: 5
19+
ports:
20+
- "5432:5432"
1921

20-
redis:
21-
image: redis:latest
22-
environment:
23-
REDIS_HOST: ${REDIS_HOST}
24-
REDIS_PORT: ${REDIS_PORT}
25-
networks:
26-
- backend
22+
redis:
23+
image: redis:latest
24+
environment:
25+
REDIS_HOST: ${REDIS_HOST}
26+
REDIS_PORT: ${REDIS_PORT}
27+
networks:
28+
- net
29+
ports:
30+
- "6379:6379"
31+
healthcheck:
32+
test: ["CMD", "redis-cli", "ping"]
33+
interval: 30s
34+
retries: 3
35+
start_period: 10s
36+
timeout: 5s
2737

28-
backend:
29-
build:
30-
context: .
31-
dockerfile: ./services/backend/Dockerfile.local
32-
image: backend:latest
33-
env_file:
34-
- .env
35-
volumes:
36-
- .env:/app/.env
37-
# 소스 코드 마운트
38-
- ./apps/backend:/app/apps/backend
39-
- ./apps/frontend:/app/apps/frontend
40-
# 의존성 캐시를 위한 볼륨
41-
- backend_node_modules:/app/node_modules
42-
- backend_app_node_modules:/app/apps/backend/node_modules
43-
- frontend_app_node_modules:/app/apps/frontend/node_modules
44-
depends_on:
45-
postgres:
46-
condition: service_healthy
47-
networks:
48-
- backend
49-
- frontend
50-
ports:
51-
- "5173:5173" # Vite dev server
52-
- "3000:3000" # 백엔드 API 포트
53-
- "1234:1234" # WebSocket 포트
38+
backend:
39+
build:
40+
context: .
41+
dockerfile: ./services/backend/Dockerfile.local
42+
image: backend:latest
43+
env_file:
44+
- .env
45+
volumes:
46+
- .env:/app/.env
47+
# 소스 코드 마운트
48+
- ./apps/backend:/app/apps/backend
49+
- ./apps/frontend:/app/apps/frontend
50+
# 의존성 캐시를 위한 볼륨
51+
- backend_node_modules:/app/node_modules
52+
- backend_app_node_modules:/app/apps/backend/node_modules
53+
- frontend_app_node_modules:/app/apps/frontend/node_modules
54+
depends_on:
55+
postgres:
56+
condition: service_healthy
57+
redis:
58+
condition: service_healthy
59+
networks:
60+
- net
61+
ports:
62+
- "5173:5173" # Vite dev server
63+
- "3000:3000" # 백엔드 API 포트
64+
- "1234:1234" # WebSocket 포트
5465

55-
nginx:
56-
build:
57-
context: .
58-
dockerfile: ./services/nginx/Dockerfile.local
59-
ports:
60-
- "80:80"
61-
- "443:443"
62-
depends_on:
63-
- backend
64-
networks:
65-
- frontend
66-
volumes:
67-
- type: bind
68-
source: ./services/nginx/ssl
69-
target: /etc/nginx/ssl
70-
bind:
71-
create_host_path: true
72-
propagation: rprivate
73-
- ./services/nginx/conf.d:/etc/nginx/conf.d
66+
nginx:
67+
build:
68+
context: .
69+
dockerfile: ./services/nginx/Dockerfile.local
70+
ports:
71+
- "80:80"
72+
- "443:443"
73+
depends_on:
74+
- backend
75+
networks:
76+
- net
77+
volumes:
78+
- type: bind
79+
source: ./services/nginx/ssl
80+
target: /etc/nginx/ssl
81+
bind:
82+
create_host_path: true
83+
propagation: rprivate
84+
- ./services/nginx/conf.d:/etc/nginx/conf.d
7485

7586
networks:
76-
backend:
77-
internal: true
78-
frontend:
87+
net:
7988

8089
volumes:
81-
postgres_data:
82-
backend_node_modules:
83-
backend_app_node_modules:
84-
frontend_app_node_modules:
90+
postgres_data:
91+
backend_node_modules:
92+
backend_app_node_modules:
93+
frontend_app_node_modules:

0 commit comments

Comments
 (0)