Skip to content

Commit

Permalink
# This is a combination of 4 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

Update dockerignore for slimmer build context

# This is the commit message #2:

Remove innefective node flat

# This is the commit message #3:

Re-add relay1

# This is the commit message #4:

Formatting
  • Loading branch information
Sebastian Bolanos committed Jan 29, 2021
1 parent 33ae275 commit 3948c11
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ README.md
Makefile
nix
.makeFlags
*.log
*.rts2_cache_cjs
*.db
13 changes: 10 additions & 3 deletions ops/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
EMAIL: ${CERTBOT_EMAIL}
CONTAINER_NAME: relay
APP_PORT: 5000
APP_QTY: 1
APP_QTY: 2
CLOUDFLARE: ${CLOUDFLARE}
depends_on:
- relay
Expand All @@ -20,7 +20,14 @@ services:
REDIS_URL: redis://redis:6379/0
deploy:
resources:
#limits:
# memory: 3G
reservations:
cpus: '0.6'
relay1:
image: ${RELAY_IMAGE}
environment:
NODE_ENV: production
REDIS_URL: redis://redis:6379/0
deploy:
resources:
limits:
memory: 2G
2 changes: 1 addition & 1 deletion ops/relay.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ COPY ./servers/relay .
RUN npm run build

USER node
CMD node --nouse-idle-notification /relay/dist
CMD node /relay/dist
43 changes: 17 additions & 26 deletions servers/relay/src/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,38 @@ export class RedisService {
const key = `message:${topic}`;
const hash = sha256(message);
const val = `${hash}:${message}`;
this.client.sadd(key, val)
this.client.expire(key, ttl)
this.client.sadd(key, val);
this.client.expire(key, ttl);
}

public async getMessages(topic: string): Promise<Array<string>> {
this.logger.debug(`Getting Message`);
this.logger.trace({ type: "method", method: "getMessage", topic });
const messages: Array<string> = [];
return new Promise((resolve, reject) => {
this.client.smembers(`message:${topic}`, (err, res) => {
this.client.smembers(`message:${topic}`, (err, res) => {
res.map((m: string) => {
if (m != null) {
messages.push(m.split(":")[1]);
}
})
});
resolve(messages);
});
});
}

public async deleteMessage(topic: string, hash: string) {
this.client.sscan(
`message:${topic}`,
"0",
"MATCH",
`${hash}:*`,
(err, res) => {
if (res) this.client.srem(`message:${topic}`, res[0])
}
)
this.client.sscan(`message:${topic}`, "0", "MATCH", `${hash}:*`, (err, res) => {
if (res) this.client.srem(`message:${topic}`, res[0]);
});
}

public async setLegacyCached(message: LegacySocketMessage) {
this.logger.debug(`Setting Legacy Cached`);
this.logger.trace({ type: "method", method: "setLegacyCached", message });
this.client.lpush([`legacy:${message.topic}`, safeJsonStringify(message)], (err, res) => {
const sixHours = 21600;
this.client.expire([`legacy:${message.topic}`, sixHours])
this.client.expire([`legacy:${message.topic}`, sixHours]);
});
}

Expand All @@ -85,21 +79,18 @@ export class RedisService {
public setNotification(notification: Notification) {
this.logger.debug(`Setting Notification`);
this.logger.trace({ type: "method", method: "setNotification", notification });
this.client.lpush([
`notification:${notification.topic}`,
safeJsonStringify(notification)
])
this.client.lpush([`notification:${notification.topic}`, safeJsonStringify(notification)]);
}

public getNotification(topic: string): Promise<Array<Notification>> {
return new Promise((resolve, reject) => {
return this.client.lrange([`notification:${topic}`, 0, -1], (err, raw) => {
const data = raw.map((item: string) => safeJsonParse(item));
this.logger.debug(`Getting Notification`);
this.logger.trace({ type: "method", method: "getNotification", topic, data });
resolve(data);
this.client.lrange([`notification:${topic}`, 0, -1], (err, raw: any) => {
const data = raw.map((item: string) => safeJsonParse(item));
this.logger.debug(`Getting Notification`);
this.logger.trace({ type: "method", method: "getNotification", topic, data });
resolve(data);
});
})
});
}

public async setPendingRequest(topic: string, id: number, message: string) {
Expand All @@ -111,9 +102,9 @@ export class RedisService {
}

public async getPendingRequest(id: number): Promise<string> {
return new Promise((resolve) => {
return new Promise(resolve => {
resolve(this.client.get(`pending:${id}`));
})
});
}

public async deletePendingRequest(id: number) {
Expand Down

0 comments on commit 3948c11

Please sign in to comment.