Skip to content

Instantly share code, notes, and snippets.

View hoangsetup's full-sized avatar
🎯
Work until you no longer have to represent yourself.!

Hoang Dinh hoangsetup

🎯
Work until you no longer have to represent yourself.!
View GitHub Profile
<div class="container not-loaded">
<div class="night"></div>
<div class="flowers">
<div class="flower flower--1">
<div class="flower__leafs flower__leafs--1">
<div class="flower__leaf flower__leaf--1"></div>
<div class="flower__leaf flower__leaf--2"></div>
<div class="flower__leaf flower__leaf--3"></div>
<div class="flower__leaf flower__leaf--4"></div>
<div class="flower__white-circle"></div>
@hoangsetup
hoangsetup / index.html
Created May 31, 2023 05:54
Loading animation
<div class="wrapper">
<div class="bg">
<div class="load"></div>
</div>
</div>
<div class ="text"> Loading... </div>
@hoangsetup
hoangsetup / index.html
Created May 30, 2023 01:34
Text water animation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Code The World - IO</title>
<link rel="stylesheet" href="style.css"></style>
</head>
import { getLinksByQuery } from './utils/scraper';
import { consume } from './utils/scraper-queue';
import { updateTransactionToDone, updateTransactionToProcessing } from './utils/scraper-transaction';
(async () => {
await consume(async (item) => {
await updateTransactionToProcessing(item.transactionId.toString());
const links = await getLinksByQuery(item.query);
import { ISearchResult, ITransaction } from './interfaces';
import getRedisClient from './redis';
export async function addTransaction(transactionId: string): Promise<void> {
const redisClient = await getRedisClient();
await redisClient.set(
transactionId,
JSON.stringify({ status: 'ON_QUEUE' } as ITransaction),
{ EX: 15 * 60 },
import {
Channel,
connect,
Connection,
} from 'amqplib';
import environments from './environments';
let connection: Connection;
const channels: Record<string, Channel> = {};
export interface ILink {
title: string;
link: string;
}
export interface ISearchResult {
query: string;
took: number;
links: ILink[];
}
import environments from './environments';
import { IQueueItem } from './interfaces';
import getChannel from './rabbitmq';
export async function sendQueryToQueue(item: IQueueItem): Promise<boolean> {
const channel = await getChannel(environments.rabbitMQScraperQueue);
const message = JSON.stringify(item);
return channel.sendToQueue(environments.rabbitMQScraperQueue, Buffer.from(message));
}
/* eslint-disable no-console */
import express from 'express';
import environments from './utils/environments';
import { sendQueryToQueue } from './utils/scraper-queue';
import { addTransaction, getTransactionResult } from './utils/scraper-transaction';
const app = express();
app.get('/', (req, res) => {
res.json({ message: 'Hello World!' });
diff --git a/docker-compose.yml b/docker-compose.yml
index 94302ff..19dff7a 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,7 +1,7 @@
version: '3.9'
services:
api:
- build: .
+ build: node:latest