Skip to content

Commit

Permalink
Merge pull request #19 from jovijovi/dev-ci
Browse files Browse the repository at this point in the history
Release v0.11.6
  • Loading branch information
jovijovi authored Oct 28, 2022
2 parents fad475c + 6bf067f commit 66093dc
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 218 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [v0.11.6](https://github.com/jovijovi/ether-goblin/releases/tag/v0.11.6)

### Fixes

- (module/event/fetcher): push event to callback queue

### Build

- Replaced node-slim with node-alpine because the bug was fixed in hardhat@2.12.1. Ref: <https://github.com/NomicFoundation/hardhat/issues/3195>
- Bump node version from 16.17 to 16.18
- Bump packages

## [v0.11.2](https://github.com/jovijovi/ether-goblin/releases/tag/v0.11.2)

### Features
Expand Down Expand Up @@ -67,7 +79,7 @@

### Build

- Replace alpine by slim. Ref: <https://github.com/NomicFoundation/hardhat/issues/3195>
- Replace node-alpine with node-slim. Ref: <https://github.com/NomicFoundation/hardhat/issues/3195>

## [v0.9.0](https://github.com/jovijovi/ether-goblin/releases/tag/v0.9.0)

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
APP_NAME:=ether-goblin
HUB:=$(if $(HUB),$(HUB),some_docker_image_repo)
OS:=linux
NODE_VER=16.17
IMAGE_TAG:=slim
NODE_VER=16.18
IMAGE_TAG:=alpine
TS_VER=$(shell tsc -v)

prj_dir:=$(shell pwd -L)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A microservice for the Ethereum ecosystem.
## Development Environment

- typescript `4.8.4`
- node `v16.17.1`
- node `v16.18.0`
- ts-node `v10.9.1`
- yarn `v1.22.19`

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN yarn install --frozen-lockfile \

FROM node:${NODE_VER}-${IMAGE_TAG} as runtime

RUN apt-get update && apt-get install bash
RUN apk add --no-cache bash

COPY --from=builder /opt/app_src/dist /opt/app
COPY --from=builder /opt/app_src/node_modules /opt/app/node_modules
Expand Down
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ether-goblin",
"version": "0.11.2",
"version": "0.11.6",
"description": "A microservice for the Ethereum ecosystem.",
"author": "jovijovi <mageyul@hotmail.com>",
"license": "MIT",
Expand Down Expand Up @@ -32,45 +32,45 @@
"dist-run": "node ./dist/src/main/index.js"
},
"dependencies": {
"@jovijovi/ether-core": "0.5.3",
"@jovijovi/ether-core-api": "0.1.1",
"@jovijovi/ether-network": "0.3.3",
"@jovijovi/ether-core": "0.5.4",
"@jovijovi/ether-core-api": "0.1.2",
"@jovijovi/ether-network": "0.3.4",
"@jovijovi/express-2fa-token": "^1.1.0",
"@jovijovi/pedrojs-common": "1.1.22",
"@jovijovi/pedrojs-common": "1.1.26",
"@jovijovi/pedrojs-loader": "^1.1.23",
"@jovijovi/pedrojs-mysql": "1.1.23",
"@jovijovi/pedrojs-network-http": "1.1.23",
"@jovijovi/pedrojs-pg": "1.1.23",
"@jovijovi/pedrojs-sqlite": "1.1.23",
"@jovijovi/pedrojs-mysql": "1.1.26",
"@jovijovi/pedrojs-network-http": "1.1.26",
"@jovijovi/pedrojs-pg": "1.1.26",
"@jovijovi/pedrojs-sqlite": "1.1.26",
"@openzeppelin/contracts": "4.7.3",
"@types/progress": "^2.0.5",
"ethers": "5.7.1",
"ethers": "5.7.2",
"fastq": "^1.13.0",
"got": "11.8.5",
"lru-cache": "7.14.0",
"nodemailer": "^6.8.0",
"nodemailer-openpgp": "^2.1.0",
"progress": "^2.0.3",
"write-file-atomic": "^4.0.2"
"write-file-atomic": "^5.0.0"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "2.2.0",
"@nomiclabs/hardhat-etherscan": "3.1.1",
"@nomiclabs/hardhat-ethers": "2.2.1",
"@nomiclabs/hardhat-etherscan": "3.1.2",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"@tsconfig/node16": "^1.0.3",
"@typechain/ethers-v5": "10.1.0",
"@typechain/hardhat": "6.1.3",
"@types/chai": "4.3.3",
"@types/chai-as-promised": "7.1.5",
"@types/mocha": "10.0.0",
"@types/node": "18.8.4",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"@types/node": "18.11.7",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
"chai": "4.3.6",
"chai-as-promised": "^7.1.1",
"eslint": "^8.25.0",
"hardhat": "2.12.0",
"mocha": "^10.0.0",
"eslint": "^8.26.0",
"hardhat": "2.12.1",
"mocha": "^10.1.0",
"ts-generator": "^0.1.1",
"ts-node": "10.9.1",
"typechain": "8.1.0",
Expand Down
53 changes: 31 additions & 22 deletions src/module/event/fetcher/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import fastq, {queueAsPromised} from 'fastq';
import {auditor, log, util} from '@jovijovi/pedrojs-common';
import {customConfig} from '../../../config';
import {EventTransfer, Response} from '../common/types';
import {DefaultLoopInterval} from './params';
import {RandomRetryInterval} from './common';
import {DefaultLoopInterval, DefaultRetryTimes} from './params';

// Callback queue (ASC, FIFO)
const callbackQueue = new util.Queue<EventTransfer>();

// Callback job
const callbackJob: queueAsPromised<util.Queue<EventTransfer>> = fastq.promise(callback, 1);

// Schedule processing job
// Schedule callback job
export async function Run() {
let isEmpty = true;
setInterval(() => {
Expand All @@ -29,33 +30,41 @@ export async function Run() {
}, DefaultLoopInterval);
}

// Push event to callback queue
export function Push(evt: EventTransfer) {
callbackQueue.Push(evt);
}

// Event callback
async function callback(queue: util.Queue<EventTransfer>): Promise<void> {
try {
const conf = customConfig.GetEvents().fetcher;
// Check URL
if (!conf.callback) {
return;
}
const conf = customConfig.GetEvents().fetcher;

const len = queue.Length();
if (len === 0) {
return;
}
// Check URL
if (!conf.callback) {
return;
}

const len = queue.Length();
if (len === 0) {
return;
}

for (let i = 0; i < len; i++) {
const evt = queue.Shift();
for (let i = 0; i < len; i++) {
const evt = queue.Shift();

// Callback
log.RequestId().debug("Fetcher calling back(%s)... event:", conf.callback, evt);
const rsp: Response = await got.post(conf.callback, {
json: evt
}).json();
// Callback
log.RequestId().debug("Fetcher calling back(%s)... event=%o", conf.callback, evt);
try {
const rsp: Response = await util.retry.Run(async (): Promise<Response> => {
return got.post(conf.callback, {
json: evt
}).json();
}, DefaultRetryTimes, RandomRetryInterval(), false);

log.RequestId().trace("Fetcher callback response=", rsp);
log.RequestId().trace("Fetcher callback response=%o", rsp);
} catch (e) {
log.RequestId().error("Fetcher callback failed, error=%o", e.message);
}
} catch (e) {
log.RequestId().error("Fetcher callback failed, error=", e);
}

return;
Expand Down
1 change: 1 addition & 0 deletions src/module/event/fetcher/dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export async function Run() {
}, DefaultLoopInterval);
}

// Push event to dump queue
export function Push(evt: EventTransfer) {
eventQueue.Push(evt);
}
Expand Down
8 changes: 8 additions & 0 deletions src/module/event/fetcher/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ async function queryLogs(opts: Options = {
log.RequestId().trace("EXEC JOB(QueryLogs|id:%s), blocks[%d,%d], TotalJobs=%d",
opts.jobId, opts.fromBlock, opts.toBlock, queryLogsJobs.length());

// Get fetcher config
const conf = customConfig.GetEvents().fetcher;

// Get topic ID (string array)
const eventFragments = opts.eventType.map(x => EventMapper.get(x));
const topicIDs = eventFragments.map(x => EventNameMapper.get(x));
Expand Down Expand Up @@ -145,6 +148,11 @@ async function queryLogs(opts: Options = {

// Push event to queue
dump.Push(evt);

// Push event to callback queue
if (conf.callback) {
callback.Push(evt);
}
}

log.RequestId().trace("FINISHED JOB(QueryLogs|id:%s), blocks[%d,%d], TotalJobs=%d",
Expand Down
Loading

0 comments on commit 66093dc

Please sign in to comment.