How to use the signale.scope function in signale

To help you get started, we’ve selected a few signale examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xTracker / 0x-tracker-worker / src / jobs / derive-fill-prices / price-fill.js View on Github external
const signale = require('signale');

const deriveTokenPriceFromFill = require('./derive-token-price-from-fill');
const markFillAsUnpriceable = require('./mark-fill-as-unpriceable');
const persistAssetPrice = require('./persist-asset-price');
const persistTokenPrice = require('./persist-token-price');
const withTransaction = require('../../util/with-transaction');

const logger = signale.scope('derive fill prices > price fill');

const priceFill = async fill => {
  const tokenPrice = deriveTokenPriceFromFill(fill);

  if (tokenPrice === null) {
    // If a token price cannot be derived from the fill then this fill
    // is unpriceable and should be marked as such to avoid future processing.
    await markFillAsUnpriceable(fill._id);
    logger.info(`marked fill ${fill._id} as unpriceable`);

    return;
  }

  await withTransaction(async session => {
    // Update the priced asset on this fill and mark the fill as priced
    await persistAssetPrice(tokenPrice, fill, session);
github 0xTracker / 0x-tracker-worker / src / util / job-runner.js View on Github external
const _ = require('lodash');

const config = require('config');
const signale = require('signale');
const withRetry = require('promise-poller').default;

const logger = signale.scope('job runner');

const runJob = async ({ fn, maxInterval, minInterval }, options) => {
  const configKey = `jobs.${fn.name}`;
  const jobConfig = config.has(configKey)
    ? config.util.toObject(config.get(configKey))
    : {};

  try {
    await withRetry({
      max: maxInterval,
      min: minInterval,
      progressCallback: options.onError,
      retries: 999999, // Setting a large number because poller does not work properly with Infinity
      shouldContinue: () => true,
      strategy: 'exponential-backoff',
      taskFn: async () => {
github 0xTracker / 0x-tracker-worker / src / jobs / create-fills / index.js View on Github external
const signale = require('signale');

const {
  MissingBlockError,
  UnsupportedAssetError,
  UnsupportedProtocolError,
} = require('../../errors');
const { JOB, QUEUE } = require('../../constants');
const { publishJob } = require('../../queues');
const createFill = require('./create-fill');
const ensureTokenExists = require('../../tokens/ensure-token-exists');
const Event = require('../../model/event');
const persistFill = require('./persist-fill');
const withTransaction = require('../../util/with-transaction');

const logger = signale.scope('create fills');

const SUPPORTED_VERSIONS = [1, 2, 3];

const createFills = async ({ batchSize }) => {
  const events = await Event.find({
    fillCreated: { $in: [false, null] },
    protocolVersion: { $in: SUPPORTED_VERSIONS },
  }).limit(batchSize);

  logger.info(`found ${events.length} events without associated fills`);

  await bluebird.mapSeries(events, async event => {
    logger.time(`create fill for event ${event.id}`);

    try {
      const fill = await createFill(event);
github 0xTracker / 0x-tracker-worker / src / jobs / update-fill-rates / index.js View on Github external
require('moment-round');

const _ = require('lodash');
const bluebird = require('bluebird');
const signale = require('signale');

const { BASE_TOKENS, ZRX_TOKEN_ADDRESS } = require('../../constants');
const Fill = require('../../model/fill');
const getLocalisedAmount = require('./get-localised-amount');
const getRatesForFill = require('./get-rates-for-fill');
const localizeTokenAmount = require('./localize-token-amount');
const tokenCache = require('../../tokens/token-cache');

const logger = signale.scope('update fill rates');

const updateFillRates = async ({ batchSize, processOldestFirst }) => {
  const tokens = tokenCache.getTokens();
  const baseTokens = _.keys(BASE_TOKENS);

  const fills = await Fill.find({
    'rates.saved': { $in: [null, false] },
    $or: [
      { makerToken: { $in: baseTokens } },
      { takerToken: { $in: baseTokens } },
    ],
  })
    .sort({ date: processOldestFirst ? 1 : -1 })
    .limit(batchSize)
    .lean();
github 0xTracker / 0x-tracker-worker / src / jobs / update-fill-statuses.js View on Github external
const { findKey } = require('lodash');
const bluebird = require('bluebird');
const signale = require('signale');

const { FILL_STATUS } = require('../constants');
const Fill = require('../model/fill');
const getTransactionReceipt = require('../util/ethereum/get-transaction-receipt');

const logger = signale.scope('update fill statuses');

const updateFillStatuses = async ({ batchSize }) => {
  logger.time('fetch pending fills');

  const fills = await Fill.find({ status: FILL_STATUS.PENDING })
    .limit(batchSize)
    .lean();

  logger.timeEnd('fetch pending fills');

  if (fills.length === 0) {
    logger.info('no pending fills were found');
    return;
  }

  logger.time(`update status of ${fills.length} fills`);
github 0xTracker / 0x-tracker-worker / src / consumers / reindex-fills.js View on Github external
const _ = require('lodash');
const bluebird = require('bluebird');
const signale = require('signale');

const { publishJob } = require('../queues');
const { JOB, QUEUE } = require('../constants');
const { getModel } = require('../model');

const logger = signale.scope('reindex fills');

const reindexFills = async job => {
  const { batchSize, lastFillId } = job.data;

  if (!_.isFinite(batchSize) || batchSize <= 0) {
    throw new Error(`Invalid batchSize: ${batchSize}`);
  }

  const fills = await getModel('Fill')
    .find(
      lastFillId === undefined
        ? undefined
        : {
            _id: { $gt: lastFillId },
          },
      '_id',
github 0xTracker / 0x-event-extractor / src / jobs / extract-events.js View on Github external
const { clamp } = require('lodash');

const config = require('config');
const signale = require('signale');

const BlockRange = require('../model/block-range');
const getCurrentBlock = require('../util/ethereum/get-current-block');
const getLastProcessedBlock = require('../events/get-last-processed-block');
const persistEvents = require('../events/persist-events');
const zeroEx = require('../util/ethereum/0x');

const logger = signale.scope('extract events');

const getEvents = async (protocolVersion, fromBlock, toBlock) => {
  const events = await zeroEx
    .getClient()
    .exchange.getLogsAsync(config.get('eventType'), { fromBlock, toBlock }, {});

  return events;
};

const saveEvents = async () => {
  const protocolVersion = config.get('protocolVersion');
  const currentBlock = await getCurrentBlock();
  const maxBlock = currentBlock - config.get('minConfirmations');
  const lastBlock = await getLastProcessedBlock(protocolVersion);
  const fromBlock = lastBlock + 1;
  const toBlock = clamp(fromBlock + config.get('maxChunkSize'), 1, maxBlock);
github 0xTracker / 0x-tracker-worker / src / jobs / update-token-stats.js View on Github external
const _ = require('lodash');
const moment = require('moment');
const signale = require('signale');

const getTokenStats = require('../tokens/get-token-stats.js');
const Token = require('../model/token');

const logger = signale.scope('update token prices');

const updateTokenStatsForPeriod = async (period, dateFrom) => {
  logger.time(`update ${period} token stats`);

  const tokenStats = await getTokenStats(dateFrom, new Date());
  const tokensWithStats = tokenStats.map(stat => stat.token);
  const totalVolume = _.sumBy(tokenStats, 'volume.USD');

  const updateOperations = tokenStats
    .map(stat => ({
      updateOne: {
        filter: { address: stat.token },
        update: {
          $set: {
            [`stats.${period}`]: {
              trades: stat.trades,
github 0xTracker / 0x-tracker-worker / src / util / db.js View on Github external
const mongoose = require('mongoose');
const signale = require('signale');

const { logError } = require('./error-logger');

const logger = signale.scope('mongodb');

mongoose.Promise = global.Promise;

module.exports = {
  connect: async (connectionString, options = {}) => {
    mongoose.connection.on('connecting', () => {
      logger.info('connecting to database');
    });

    mongoose.connection.on('connected', () => {
      logger.success('database connection established');
    });

    mongoose.connection.on('error', err => {
      logError(err);
    });
github 0xTracker / 0x-tracker-worker / src / consumers / fetch-fill-status.js View on Github external
const _ = require('lodash');
const mongoose = require('mongoose');
const signale = require('signale');

const { FILL_STATUS, JOB, QUEUE } = require('../constants');
const { getModel } = require('../model');
const { publishJob } = require('../queues');
const getTransactionReceipt = require('../util/ethereum/get-transaction-receipt');

const logger = signale.scope('fetch fill status');

const fetchFillStatus = async job => {
  const { fillId, transactionHash } = job.data;

  if (!mongoose.Types.ObjectId.isValid(fillId)) {
    throw new Error(`Invalid fillId: ${fillId}`);
  }

  if (_.isEmpty(transactionHash)) {
    throw new Error(`Invalid transactionHash: ${transactionHash}`);
  }

  const receipt = await getTransactionReceipt(transactionHash);

  if (receipt === undefined) {
    throw new Error(`No receipt found for transaction: ${transactionHash}`);