File tree Expand file tree Collapse file tree 3 files changed +14
-1
lines changed
Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ export function createSlack(
8080 return new SlackWebhook ( tag , slackWebhookUrl ) ;
8181 } else {
8282 console . log ( "Slack not connected" ) ;
83+ console . log ( "You can set SLACK_WEBHOOK env variable to connect Slack" ) ;
8384 return new NullSlack ( ) ;
8485 }
8586}
Original file line number Diff line number Diff line change 11import { SDK } from "codechain-sdk" ;
2+ import { createSlack , Slack } from "./checker/slack" ;
23import { IndexerConfig } from "./config" ;
34import models from "./models" ;
45import Worker from "./worker" ;
@@ -9,13 +10,21 @@ export class IndexerContext {
910 }
1011 public sdk : SDK ;
1112 public worker : Worker ;
13+ public slack : Slack ;
1214
1315 private constructor ( public readonly options : IndexerConfig ) {
1416 this . sdk = new SDK ( {
1517 server : options . codechain . host ,
1618 networkId : options . codechain . networkId
1719 } ) ;
18- this . worker = new Worker ( { sdk : this . sdk } , options . worker ) ;
20+ this . slack = createSlack (
21+ `[${ options . codechain . networkId } ][indexer]` ,
22+ process . env . SLACK_WEBHOOK
23+ ) ;
24+ this . worker = new Worker (
25+ { sdk : this . sdk , slack : this . slack } ,
26+ options . worker
27+ ) ;
1928 }
2029
2130 public destroy = async ( ) => {
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { SDK } from "codechain-sdk";
33import { Block } from "codechain-sdk/lib/core/classes" ;
44import * as _ from "lodash" ;
55import { Job , scheduleJob } from "node-schedule" ;
6+ import { Slack } from "../checker/slack" ;
67import { InvalidBlockNumber } from "../exception" ;
78import models from "../models" ;
89import { BlockAttribute } from "../models/block" ;
@@ -16,6 +17,7 @@ const ASYNC_LOCK_KEY = "worker";
1617
1718export interface WorkerContext {
1819 sdk : SDK ;
20+ slack : Slack ;
1921}
2022
2123export interface WorkerConfig {
@@ -58,6 +60,7 @@ export default class Worker {
5860 }
5961 lastError = err ;
6062 console . error ( "sync error: " , err ) ;
63+ this . context . slack . sendError ( err && err . message ) ;
6164 }
6265 } ) ;
6366 this . watchJob . invoke ( ) ;
You can’t perform that action at this time.
0 commit comments