-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathIndexBlockTask.ts
More file actions
54 lines (46 loc) · 1.32 KB
/
IndexBlockTask.ts
File metadata and controls
54 lines (46 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import {
BlockQueue,
JSONTaskSerializer,
Task,
TaskSerializer,
TaskWorkerModule,
} from "@proto-kit/sequencer";
import { log } from "@proto-kit/common";
import { inject, injectable } from "tsyringe";
import { IndexBlockTaskParameters } from "./IndexBlockTaskParameters";
@injectable()
export class IndexBlockTask
extends TaskWorkerModule
implements Task<IndexBlockTaskParameters, string | void>
{
public name = "index-block";
public constructor(
@inject("BlockQueue")
public blockStorage: BlockQueue
) {
super();
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
public async prepare(): Promise<void> {}
public async compute(
input: IndexBlockTaskParameters
): Promise<string | void> {
try {
await this.blockStorage.pushBlock(input.block);
await this.blockStorage.pushResult(input.result);
} catch (error) {
log.error("Failed to index block", input.block.height, error);
return;
}
log.info(`Block ${input.block.height} indexed sucessfully`);
}
public inputSerializer(): TaskSerializer<IndexBlockTaskParameters> {
return JSONTaskSerializer.fromType<IndexBlockTaskParameters>();
}
public resultSerializer(): TaskSerializer<string | void> {
return {
fromJSON: async () => {},
toJSON: async () => "",
};
}
}