Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from AJRedDevil/develop
Browse files Browse the repository at this point in the history
Worker
  • Loading branch information
AjanShrestha authored Dec 22, 2019
2 parents 01b5a0c + 9a5b183 commit 7175a8e
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
Expand Down Expand Up @@ -124,3 +121,6 @@ dist
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Redis
worker/data
8 changes: 4 additions & 4 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9204,10 +9204,10 @@ serialize-javascript@^1.7.0:
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.9.1.tgz#cfc200aef77b600c47da9bb8149c943e798c2fdb"
integrity sha512-0Vb/54WJ6k5v8sSWN09S0ora+Hnr+cX40r9F170nT+mSkaxltoE/7R3OrIdBSUv1OoiobH1QoWQbCnAO+e8J1A==

serialize-javascript@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-2.1.0.tgz#9310276819efd0eb128258bb341957f6eb2fc570"
integrity sha512-a/mxFfU00QT88umAJQsNWOnUKckhNCqOl028N48e7wFmo2/EHpTo9Wso+iJJCMrQnmFvcjto5RJdAHEvVhcyUQ==
serialize-javascript@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-2.1.2.tgz#ecec53b0e0317bdc95ef76ab7074b7384785fa61"
integrity sha512-rs9OggEUF0V4jUSecXazOYsLfu7OGK2qIn3c7IPBiffz32XniEp/TX9Xmc9LQfK2nQ2QKHvZ2oygKUGU0lG4jQ==

serve-index@^1.9.1:
version "1.9.1"
Expand Down
5 changes: 5 additions & 0 deletions worker/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const CronJob = require('cron').CronJob;

const fetchGithub = require('./tasks/fetch-github');

new CronJob('* * * * *', fetchGithub, null, true, 'Asia/Kathmandu');
16 changes: 16 additions & 0 deletions worker/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
download-redis:
docker pull redis

setup-volume:
mkdir data

start-redis:
docker run --name redis-job-board \
-p 6379:6379 \
--restart unless-stopped \
-v ${PWD}/data:/data\
-d redis redis-server --appendonly yes

stop-redis:
docker stop redis-job-board
docker rm redis-job-board
13 changes: 13 additions & 0 deletions worker/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "worker",
"version": "0.1.0",
"description": "Cron worker to fetch data",
"main": "index.js",
"author": "Ajan Lal Shrestha",
"license": "MIT",
"dependencies": {
"cron": "1.7.2",
"node-fetch": "2.6.0",
"redis": "2.8.0"
}
}
32 changes: 32 additions & 0 deletions worker/tasks/fetch-github.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const fetch = require('node-fetch');
const redis = require('redis'),
client = redis.createClient();
const {promisify} = require('util');
const getAsync = promisify(client.get).bind(client);
const setAsync = promisify(client.set).bind(client);

const baseURL = 'https://jobs.github.com/positions.json';

const fetchGithub = async () => {
let resultCount = 1,
onPage = 0;
const allJobs = [];

while (resultCount > 0) {
const res = await fetch(`${baseURL}?page=${onPage}`);
const jobs = await res.json();
allJobs.push(...jobs);
resultCount = jobs.length;
console.log(`got ${resultCount} jobs`);
onPage++;
}

console.log(`got ${allJobs.length} jobs`);
const successs = await setAsync('github', JSON.stringify(allJobs));

console.log(successs);
};

fetchGithub();

module.exports = fetchGithub;
51 changes: 51 additions & 0 deletions worker/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


[email protected]:
version "1.7.2"
resolved "https://registry.yarnpkg.com/cron/-/cron-1.7.2.tgz#2ea1f35c138a07edac2ac5af5084ed6fee5723db"
integrity sha512-+SaJ2OfeRvfQqwXQ2kgr0Y5pzBR/lijf5OpnnaruwWnmI799JfWr2jN2ItOV9s3A/+TFOt6mxvKzQq5F0Jp6VQ==
dependencies:
moment-timezone "^0.5.x"

double-ended-queue@^2.1.0-0:
version "2.1.0-0"
resolved "https://registry.yarnpkg.com/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz#103d3527fd31528f40188130c841efdd78264e5c"
integrity sha1-ED01J/0xUo9AGIEwyEHv3XgmTlw=

moment-timezone@^0.5.x:
version "0.5.27"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.27.tgz#73adec8139b6fe30452e78f210f27b1f346b8877"
integrity sha512-EIKQs7h5sAsjhPCqN6ggx6cEbs94GK050254TIJySD1bzoM5JTYDwAU1IoVOeTOL6Gm27kYJ51/uuvq1kIlrbw==
dependencies:
moment ">= 2.9.0"

"moment@>= 2.9.0":
version "2.24.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==

[email protected]:
version "2.6.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==

redis-commands@^1.2.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/redis-commands/-/redis-commands-1.5.0.tgz#80d2e20698fe688f227127ff9e5164a7dd17e785"
integrity sha512-6KxamqpZ468MeQC3bkWmCB1fp56XL64D4Kf0zJSwDZbVLLm7KFkoIcHrgRvQ+sk8dnhySs7+yBg94yIkAK7aJg==

redis-parser@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/redis-parser/-/redis-parser-2.6.0.tgz#52ed09dacac108f1a631c07e9b69941e7a19504b"
integrity sha1-Uu0J2srBCPGmMcB+m2mUHnoZUEs=

[email protected]:
version "2.8.0"
resolved "https://registry.yarnpkg.com/redis/-/redis-2.8.0.tgz#202288e3f58c49f6079d97af7a10e1303ae14b02"
integrity sha512-M1OkonEQwtRmZv4tEWF2VgpG0JWJ8Fv1PhlgT5+B+uNq2cA3Rt1Yt/ryoR+vQNOQcIEgdCdfH0jr3bDpihAw1A==
dependencies:
double-ended-queue "^2.1.0-0"
redis-commands "^1.2.0"
redis-parser "^2.6.0"

0 comments on commit 7175a8e

Please sign in to comment.