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

Commit

Permalink
Disable Postgres backend for now
Browse files Browse the repository at this point in the history
  • Loading branch information
nick committed Apr 23, 2019
1 parent c0c7eb8 commit 365d04a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 152 deletions.
7 changes: 3 additions & 4 deletions devops/dockerfiles/event-listener
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ RUN npm install --unsafe-perm
COPY ./packages/contracts/releases/0.8.6/build/ ./packages/contracts/build/

CMD eval $(envkey-source) && \
npm run migrate --prefix infra/discovery && \
npm run migrate --prefix packages/event-cache && \
npm run migrate --prefix infra/identity && \
npm run start:listener --prefix infra/discovery
npm run migrate --prefix infra/discovery && \
npm run migrate --prefix infra/identity && \
npm run start:listener --prefix infra/discovery
62 changes: 0 additions & 62 deletions infra/discovery/migrations/20190410191046-event-drop-table.js

This file was deleted.

18 changes: 18 additions & 0 deletions infra/discovery/src/listener/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const esmImport = require('esm')(module)
const graphqlClient = esmImport('@origin/graphql').default

const logger = require('./logger')
const db = require('../models')
const { withRetrys } = require('./utils')
const MarketplaceEventHandler = require('./handler_marketplace')
const IdentityEventHandler = require('./handler_identity')
Expand Down Expand Up @@ -46,12 +47,29 @@ async function handleEvent(event, context) {
await withRetrys(async () => {
block = await context.web3.eth.getBlock(event.blockNumber)
})
const blockDate = new Date(block.timestamp * 1000)

const eventDetails = `blockNumber=${event.blockNumber} \
transactionIndex=${event.transactionIndex} \
eventName=${event.event}`
logger.info(`Processing event: ${eventDetails}`)

// Record the event in the DB.
await withRetrys(async () => {
return db.Event.upsert({
blockNumber: event.blockNumber,
logIndex: event.logIndex,
contractAddress: event.address,
transactionHash: event.transactionHash,
topic0: event.raw.topics[0],
topic1: event.raw.topics[1],
topic2: event.raw.topics[2],
topic3: event.raw.topics[3],
data: event,
createdAt: blockDate
})
})

// Call the event handler.
//
// Note: we run the handler with a retry since we've seen in production cases where we fail loading
Expand Down
11 changes: 5 additions & 6 deletions infra/discovery/src/listener/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,13 @@ async function main() {
}
logger.info(`Querying events from ${processedToBlock} up to ${toBlock}`)

contractsContext.marketplace.eventCache.setLatestBlock(toBlock)
contractsContext.identityEvents.eventCache.setLatestBlock(toBlock)

// Retrieve all events for the relevant contracts
const eventArrays = await Promise.all([
withRetrys(async () => {
return contractsContext.marketplace.eventCache.allEvents()
}),
withRetrys(async () => {
return contractsContext.identityEvents.eventCache.allEvents()
})
withRetrys(() => contractsContext.marketplace.eventCache.allEvents()),
withRetrys(() => contractsContext.identityEvents.eventCache.allEvents())
])

// Flatten array of arrays filtering out anything undefined
Expand Down
39 changes: 39 additions & 0 deletions infra/discovery/src/models/event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict'

module.exports = (sequelize, DataTypes) => {
// Note: all addresses and hashes are stored in lowercase hexadecimal notation.
const Event = sequelize.define(
'Event',
{
// Block number at which the event was recorded.
blockNumber: { type: DataTypes.INTEGER, primaryKey: true },
// Index of the event within the block.
logIndex: { type: DataTypes.INTEGER, primaryKey: true },
// Address of the contract that emitted the event.
contractAddress: DataTypes.CHAR(42),
// Hash of the transaction that triggered firing the event,
transactionHash: DataTypes.CHAR(66),
// First topic is the signature of the event.
topic0: DataTypes.CHAR(66),
// Next 3 topics are the optional indexed event arguments.
topic1: DataTypes.CHAR(66),
topic2: DataTypes.CHAR(66),
topic3: DataTypes.CHAR(66),
// JSON data for the event as returned by web3 method getPastEvents.
data: DataTypes.JSONB,
// Creation date.
createdAt: DataTypes.DATE
},
{
tableName: 'event',
// Do not automatically add the timestamp attributes (updatedAt, createdAt).
timestamps: false
}
)

Event.associate = function() {
// associations can be defined here
}

return Event
}

This file was deleted.

4 changes: 2 additions & 2 deletions packages/event-cache/src/EventCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class EventCache {
if (!platform) platform = this._detectPlatform()

switch (platform) {
case 'nodejs':
return new PostgreSQLBackend()
// case 'nodejs':
// return new PostgreSQLBackend()

case 'browser':
return new IndexedDBBackend({ prefix: this.prefix })
Expand Down

0 comments on commit 365d04a

Please sign in to comment.