Skip to content

Commit

Permalink
codemod the rest of the svc to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Dec 2, 2023
1 parent caa42b7 commit f9ae45b
Show file tree
Hide file tree
Showing 32 changed files with 307 additions and 520 deletions.
46 changes: 23 additions & 23 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,143 +1,143 @@
{
"apps": [
{
"script": "svc/apiadmin.js",
"script": "svc/apiadmin.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/mmr.js",
"script": "svc/mmr.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/profiler.js",
"script": "svc/profiler.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/scanner.js",
"script": "svc/scanner.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/fullhistory.js",
"script": "svc/fullhistory.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 12
},
{
"script": "svc/autofullhistory.js",
"script": "svc/autofullhistory.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/monitor.js",
"script": "svc/monitor.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/backupscanner.js",
"script": "svc/backupscanner.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "disabled",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/gcdata.js",
"script": "svc/gcdata.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/buildsets.js",
"script": "svc/buildsets.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/cosmetics.js",
"script": "svc/cosmetics.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/distributions.js",
"script": "svc/distributions.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/heroes.js",
"script": "svc/heroes.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/herostats.js",
"script": "svc/herostats.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/items.js",
"script": "svc/items.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/leagues.js",
"script": "svc/leagues.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/livegames.js",
"script": "svc/livegames.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/proplayers.js",
"script": "svc/proplayers.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
Expand Down Expand Up @@ -193,31 +193,31 @@
"instances": 1
},
{
"script": "svc/scenariosCleanup.js",
"script": "svc/scenariosCleanup.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/counts.js",
"script": "svc/counts.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/benchmarks.js",
"script": "svc/benchmarks.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
"exec_mode": "cluster",
"instances": 1
},
{
"script": "svc/repatch.js",
"script": "svc/repatch.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
Expand All @@ -233,7 +233,7 @@
"instances": 1
},
{
"script": "svc/cassandraDelete.js",
"script": "svc/cassandraDelete.mjs",
"watch": true,
"ignore_watch": [".git", "node_modules"],
"group": "backend",
Expand Down
29 changes: 8 additions & 21 deletions svc/apiadmin.js → svc/apiadmin.mjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
const async = require('async');
const moment = require('moment');
const stripeLib = require('stripe');
const redis = require('../store/redis');
const db = require('../store/db');
const utility = require('../util/utility');
const queries = require('../store/queries');
const config = require('../config');

import async from 'async';
import moment from 'moment';
import stripeLib from 'stripe';
import redis from '../store/redis.js';
import db from '../store/db.js';
import utility from '../util/utility.js';
import queries from '../store/queries.js';
import config from '../config.js';
const stripe = stripeLib(config.STRIPE_SECRET);
const { invokeInterval } = utility;

function storeUsageCounts(cursor, cb) {
redis.hscan('usage_count', cursor, (err, results) => {
if (err) {
cb(err);
} else {
const cursor = results[0];
const values = results[1];

const apiTimestamp = moment().startOf('day');

async.eachOfLimit(
values,
5,
Expand Down Expand Up @@ -75,18 +71,15 @@ function storeUsageCounts(cursor, cb) {
if (err) {
return cb(err);
}

if (cursor !== '0') {
return storeUsageCounts(cursor, cb);
}

return cb();
}
);
}
});
}

async function updateStripeUsage(cb) {
const options = {
plan: config.STRIPE_API_PLAN,
Expand All @@ -111,15 +104,12 @@ async function updateStripeUsage(cb) {
`,
[sub.id]
);

continue;
}

const startTime = moment
.unix(sub.current_period_end - 1)
.startOf('month');
const endTime = moment.unix(sub.current_period_end - 1).endOf('month');

const res = await db.raw(
`
SELECT
Expand All @@ -140,7 +130,6 @@ async function updateStripeUsage(cb) {
`,
[startTime.format('YYYY-MM-DD'), endTime.format('YYYY-MM-DD'), sub.id]
);

if (res.rows.length > 0 && res.rows[0].usage_count) {
const usageCount = res.rows[0].usage_count;
// Set usage to be the value at end of the billing period
Expand Down Expand Up @@ -169,7 +158,6 @@ async function updateStripeUsage(cb) {
cb(err);
}
}

invokeInterval(
(cb) => {
queries.getAPIKeys(db, (err, rows) => {
Expand All @@ -196,7 +184,6 @@ invokeInterval(
},
5 * 60 * 1000
); // Update every 5 min

invokeInterval(
(cb) => {
storeUsageCounts(0, cb);
Expand Down
12 changes: 3 additions & 9 deletions svc/autofullhistory.js → svc/autofullhistory.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/**
* Worker to auto-queue full history requests for random players
* */
const async = require('async');
const db = require('../store/db');
const redis = require('../store/redis');

import async from 'async';
import db from '../store/db.js';
import redis from '../store/redis.js';
function getSummaries(cb) {
db.raw(
"SELECT account_id from players TABLESAMPLE SYSTEM_ROWS(100) where last_match_time > (now() - interval '7 day')"
Expand All @@ -29,7 +25,6 @@ function getSummaries(cb) {
);
});
}

function start() {
getSummaries((err) => {
if (err) {
Expand All @@ -38,5 +33,4 @@ function start() {
return setTimeout(start, 30000);
});
}

start();
15 changes: 5 additions & 10 deletions svc/backupscanner.js → svc/backupscanner.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
const async = require('async');
const utility = require('../util/utility');
const redis = require('../store/redis');
const queries = require('../store/queries');
const config = require('../config');

import async from 'async';
import utility from '../util/utility.js';
import redis from '../store/redis.js';
import queries from '../store/queries.js';
import config from '../config.js';
const { generateJob, getData } = utility;
const { insertMatchPromise } = queries;
const apiKeys = config.STEAM_API_KEY.split(',');
const apiHosts = config.STEAM_API_HOST.split(',');
const parallelism = Math.min(apiHosts.length * 1, apiKeys.length);
const delay = 1000;

function processMatch(matchId, cb) {
// Check if exists
redis.get(`scanner_insert:${matchId}`, (err, res) => {
Expand Down Expand Up @@ -54,7 +52,6 @@ function processMatch(matchId, cb) {
);
});
}

function processPlayer(accountId, cb) {
const ajob = generateJob('api_history', {
account_id: accountId,
Expand Down Expand Up @@ -85,7 +82,6 @@ function processPlayer(accountId, cb) {
}
);
}

function start(err) {
if (err) {
throw err;
Expand All @@ -100,5 +96,4 @@ function start(err) {
});
}, 1000);
}

start();
15 changes: 6 additions & 9 deletions svc/benchmarks.js → svc/benchmarks.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
const queue = require('../store/queue');
const benchmarksUtil = require('../util/benchmarksUtil');
const buildMatch = require('../store/buildMatch');
const utility = require('../util/utility');
const config = require('../config');
const redis = require('../store/redis');

import queue from '../store/queue.js';
import benchmarksUtil from '../util/benchmarksUtil.js';
import buildMatch from '../store/buildMatch.js';
import utility from '../util/utility.js';
import config from '../config.js';
import redis from '../store/redis.js';
const { benchmarks } = benchmarksUtil;

async function doBenchmarks(matchID, cb) {
try {
const match = await buildMatch(matchID);
Expand Down Expand Up @@ -49,5 +47,4 @@ async function doBenchmarks(matchID, cb) {
return cb(err);
}
}

queue.runQueue('parsedBenchmarksQueue', 1, doBenchmarks);
Loading

0 comments on commit f9ae45b

Please sign in to comment.