Skip to content

Commit

Permalink
Merge pull request #6 from zeeshanakram3/fix-lint-and-docker-build-is…
Browse files Browse the repository at this point in the history
…sues

Fix: lint and docker build issues
  • Loading branch information
zeeshanakram3 authored Dec 13, 2023
2 parents c48673c + ed26432 commit 08def42
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
uses: docker/build-push-action@v3
with:
# Do not use local dir context to ensure we can build from a commit directly
# context: .
context: .
file: Dockerfile
push: false
load: true
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ ADD package-lock.json .
ADD assets assets
RUN npm ci
ADD tsconfig.json .
ADD typegen.json .
ADD joystream.jsonl .
ADD src src
ADD schema schema
ADD scripts scripts
RUN npx squid-typeorm-codegen
RUN npx squid-substrate-typegen typegen.json
RUN npm run generate:schema || true
RUN npx squid-typeorm-codegen
RUN npm run build

FROM node-with-gyp AS deps
Expand Down
13 changes: 3 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ services:
- joystream
ports:
- '${DB_PORT}:${DB_PORT}'
command:
[
'postgres',
'-c',
'config_file=/etc/postgresql/postgresql.conf',
'-p',
'${DB_PORT}'
]
command: ['postgres', '-c', 'config_file=/etc/postgresql/postgresql.conf', '-p', '${DB_PORT}']
shm_size: 1g
volumes:
- squid_db_data:/var/lib/postgresql/data
Expand All @@ -46,7 +39,7 @@ services:
source: .
target: /storage-squid
working_dir: /storage-squid
command: [ 'make', 'process' ]
command: ['make', 'process']

squid_graphql-server:
container_name: squid_graphql-server
Expand All @@ -65,7 +58,7 @@ services:
source: .
target: /storage-squid
working_dir: /storage-squid
command: [ 'make', 'serve' ]
command: ['make', 'serve']
ports:
- '${GQL_PORT}:${GQL_PORT}'
networks:
Expand Down
58 changes: 29 additions & 29 deletions src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ import {
import { events } from './types'
import { EntityManagerOverlay } from './utils/overlay'

const PROCESSOR = new SubstrateBatchProcessor().setFields({
extrinsic: { hash: true },
block: { timestamp: true },
})

type Fields = SubstrateBatchProcessorFields<typeof PROCESSOR>
export type Block = BlockHeader<Fields>
export type Event = _Event<Fields>

type MapModuleEvents<Module extends keyof typeof events> = {
[Event in keyof typeof events[Module] &
string as `${Capitalize<Module>}.${Capitalize<Event>}`]: typeof events[Module][Event]
}

type EventsMap = MapModuleEvents<'content'> & MapModuleEvents<'storage'>
type EventNames = keyof EventsMap

export type EventHandlerContext<EventName extends EventNames> = {
overlay: EntityManagerOverlay
block: Block
Expand All @@ -56,14 +73,7 @@ export type EventHandler<EventName extends EventNames> =
| ((ctx: EventHandlerContext<EventName>) => void)
| ((ctx: EventHandlerContext<EventName>) => Promise<void>)

type MapModuleEvents<Module extends keyof typeof events> = {
[Event in keyof typeof events[Module] &
string as `${Capitalize<Module>}.${Capitalize<Event>}`]: typeof events[Module][Event]
}

type EventsMap = MapModuleEvents<'content'> & MapModuleEvents<'storage'>
type EventHandlers = { [Event in keyof EventsMap]: EventHandler<Event> }
type EventNames = keyof EventsMap

const eventHandlers: EventHandlers = {
'Content.VideoCreated': processVideoCreatedEvent,
Expand Down Expand Up @@ -110,27 +120,17 @@ const rpcURL = process.env.RPC_ENDPOINT || 'http://localhost:9944/'

const maxCachedEntities = parseInt(process.env.MAX_CACHED_ENTITIES || '1000')

const processor = new SubstrateBatchProcessor()
.setDataSource({
...(archiveUrl ? { archive: archiveUrl } : {}),
chain: {
url: rpcURL,
rateLimit: 10,
},
})
.addEvent({
name: eventNames,
extrinsic: true,
call: true,
})
.setFields({
extrinsic: { hash: true },
block: { timestamp: true },
})

type Fields = SubstrateBatchProcessorFields<typeof processor>
export type Block = BlockHeader<Fields>
export type Event = _Event<Fields>
PROCESSOR.setDataSource({
...(archiveUrl ? { archive: archiveUrl } : {}),
chain: {
url: rpcURL,
rateLimit: 10,
},
}).addEvent({
name: eventNames,
extrinsic: true,
call: true,
})

type ModuleNames = keyof typeof events
type EventNamesInModule<M extends ModuleNames> = keyof typeof events[M]
Expand All @@ -153,7 +153,7 @@ async function processEvent<EventName extends EventNames>(
await eventHandler({ block, overlay, event, eventDecoder, indexInBlock, extrinsicHash })
}

processor.run(new TypeormDatabase({ isolationLevel: 'READ COMMITTED' }), async (ctx) => {
PROCESSOR.run(new TypeormDatabase({ isolationLevel: 'READ COMMITTED' }), async (ctx) => {
Logger.set(ctx.log)

const overlay = await EntityManagerOverlay.create(ctx.store)
Expand Down

0 comments on commit 08def42

Please sign in to comment.