diff --git a/config/scription_list.json b/config/scription_list.json index e7cb3db..8829219 100644 --- a/config/scription_list.json +++ b/config/scription_list.json @@ -1,7 +1,7 @@ [ { "chain": 5611, - "fromBlock": 25594195, + "fromBlock": 25776083, "filters": [{ "key": "input", "op": "eq", @@ -17,7 +17,7 @@ }, { "chain": 5611, - "fromBlock": 25594195, + "fromBlock": 25776083, "filters": [{ "key": "input", "op": "like", @@ -33,7 +33,7 @@ }, { "chain": 5611, - "fromBlock": 25594195, + "fromBlock": 25776083, "filters": [{ "key": "input", "op": "like", @@ -49,7 +49,7 @@ }, { "chain": 5611, - "fromBlock": 25594195, + "fromBlock": 25776083, "filters": [{ "key": "input", "op": "like", @@ -65,7 +65,7 @@ }, { "chain": 5611, - "fromBlock": 25594195, + "fromBlock": 25776083, "filters": [{ "key": "input", "op": "like", diff --git a/scription_release.json b/scription_release.json new file mode 100644 index 0000000..9085cf1 --- /dev/null +++ b/scription_release.json @@ -0,0 +1,22 @@ +{ + "apps": [ + { + "name": "chain-scription", + "script": "npm", + "args": "run prod:scription", + "cwd": "/home/kingsome/code/web_chain_client", + "max_memory_restart": "1024M", + "log_date_format": "YYYY-MM-DD HH:mm Z", + "watch": false, + "ignore_watch": ["node_modules", "logs", "fixtures", "tasks"], + "instances": 1, + "exec_mode": "fork", + "env": { + "NODE_ENV": "production" + }, + "env_production": { + "NODE_ENV": "production" + } + } + ] +} diff --git a/src/controllers/task.controllers.ts b/src/controllers/task.controllers.ts index d092d96..953641f 100644 --- a/src/controllers/task.controllers.ts +++ b/src/controllers/task.controllers.ts @@ -1,7 +1,7 @@ import { CheckIn } from 'models/CheckIn' import { NftHolder } from 'models/NftHolder' import { BaseController, role, router, ZError } from 'zutils' -import { getMonthBegin, getNDayAgo } from 'zutils/utils/date.util' +import { getMonthBegin, getNDayAgo } from 'utils/utcdate.util' class TaskController extends BaseController { @role('anon') diff --git a/src/models/CheckIn.ts b/src/models/CheckIn.ts index eafb777..1d049de 100644 --- a/src/models/CheckIn.ts +++ b/src/models/CheckIn.ts @@ -1,7 +1,8 @@ import { getModelForClass, index, modelOptions, prop } from '@typegoose/typegoose' import { dbconn } from 'decorators/dbconn' import { BaseModule } from './Base' -import { formatDate, yesterday } from 'zutils/utils/date.util' +// import { formatDate, yesterday } from 'zutils/utils/date.util' +import { formatDate, yesterday } from 'utils/utcdate.util' import logger from 'logger/logger' @dbconn() diff --git a/src/service/block.sync.service.ts b/src/service/block.sync.service.ts index 582d4d0..85f54bd 100644 --- a/src/service/block.sync.service.ts +++ b/src/service/block.sync.service.ts @@ -5,7 +5,7 @@ import logger from 'logger/logger' import { getPastBlocksIter } from 'utils/block.util' import { ZRedisClient } from 'zutils' -import { formatDate } from 'zutils/utils/date.util' +import { formatDate } from 'utils/utcdate.util' export class BlockSyncSvr { chainCfg: IChain diff --git a/src/utils/utcdate.util.ts b/src/utils/utcdate.util.ts new file mode 100644 index 0000000..341fab2 --- /dev/null +++ b/src/utils/utcdate.util.ts @@ -0,0 +1,55 @@ +export const ONE_DAY = 24 * 60 * 60 * 1000 + +// format the date to the format we want +export const formatDate = (date: Date): string => { + const year = date.getUTCFullYear() + const month = (date.getUTCMonth() + 1 + '').padStart(2, '0') + const day = (date.getUTCDate() + '').padStart(2, '0') + return `${year}${month}${day}` +} + +// get formated datestring of yesterday +export const yesterday = (date?: Date) => { + date = date || new Date() + date.setUTCDate(date.getUTCDate() - 1) + return date +} + +export const nextday = (date?: Date) => { + date = date || new Date() + date.setUTCDate(date.getUTCDate() + 1) + return date +} + +// calc days between two Date +export function daysBetween(date1: Date, date2: Date) { + // hours*minutes*seconds*milliseconds + const diffInMs = Math.abs(date1.getTime() - date2.getTime()) + const diffInDays = Math.round(diffInMs / ONE_DAY) + return diffInDays +} + +// get begin of one day +export const getDayBegin = (date: Date): Date => { + const year = date.getUTCFullYear() + const month = date.getUTCMonth() + const day = date.getUTCDate() + return new Date(year, month, day) +} + +// get begin of n day ago +export const getNDayAgo = (n: number, begin: boolean): Date => { + const date = new Date(Date.now() - n * ONE_DAY) + if (begin) { + return getDayBegin(date) + } else { + return date + } +} + +// get begin of this month +export const getMonthBegin = (date: Date): Date => { + const year = date.getUTCFullYear() + const month = date.getUTCMonth() + return new Date(year, month, 1) +}