mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
removed NODE_APP_INSTANCE 0 dependency
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
module.exports = {
|
||||||
|
apps: [
|
||||||
|
// Master instance
|
||||||
|
{
|
||||||
|
name: 'master',
|
||||||
|
script: './dist/main.js',
|
||||||
|
instances: 1,
|
||||||
|
env: {
|
||||||
|
MASTER: 'true',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Worker instances
|
||||||
|
{
|
||||||
|
name: 'workers',
|
||||||
|
script: './dist/main.js',
|
||||||
|
instances: 31,
|
||||||
|
env: {
|
||||||
|
MASTER: 'false',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
@@ -6,9 +6,6 @@ export class RpcBlockEntity {
|
|||||||
@PrimaryColumn()
|
@PrimaryColumn()
|
||||||
blockHeight: number;
|
blockHeight: number;
|
||||||
|
|
||||||
@Column({ nullable: true })
|
|
||||||
lockedBy?: string;
|
|
||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
data?: string;
|
data?: string;
|
||||||
}
|
}
|
||||||
@@ -18,10 +18,6 @@ export class RpcBlockService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public lockBlock(blockHeight: number, process: string) {
|
|
||||||
return this.rpcBlockRepository.save({ blockHeight, data: null, lockedBy: process });
|
|
||||||
}
|
|
||||||
|
|
||||||
public saveBlock(blockHeight: number, data: string) {
|
public saveBlock(blockHeight: number, data: string) {
|
||||||
return this.rpcBlockRepository.update(blockHeight, { data })
|
return this.rpcBlockRepository.update(blockHeight, { data })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export class AppService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onModuleInit() {
|
async onModuleInit() {
|
||||||
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
|
if (process.env.MASTER == 'true') {
|
||||||
|
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
await this.deleteOldStatistics();
|
await this.deleteOldStatistics();
|
||||||
|
|||||||
@@ -99,22 +99,12 @@ export class BitcoinRpcService implements OnModuleInit {
|
|||||||
const completeBlock = block?.data != null;
|
const completeBlock = block?.data != null;
|
||||||
|
|
||||||
// If the block has already been loaded, and the same instance is fetching the template again, we just need to refresh it.
|
// If the block has already been loaded, and the same instance is fetching the template again, we just need to refresh it.
|
||||||
if (completeBlock && block.lockedBy == process.env.NODE_APP_INSTANCE) {
|
if (completeBlock && process.env.MASTER == 'true') {
|
||||||
result = await this.loadBlockTemplate(blockHeight);
|
result = await this.loadBlockTemplate(blockHeight);
|
||||||
}
|
}
|
||||||
else if (completeBlock) {
|
else if (completeBlock) {
|
||||||
return Promise.resolve(JSON.parse(block.data));
|
return Promise.resolve(JSON.parse(block.data));
|
||||||
} else if (!completeBlock) {
|
}else {
|
||||||
if (process.env.NODE_APP_INSTANCE != null) {
|
|
||||||
// There is a unique constraint on the block height so if another process tries to lock, it'll throw
|
|
||||||
try {
|
|
||||||
await this.rpcBlockService.lockBlock(blockHeight, process.env.NODE_APP_INSTANCE);
|
|
||||||
} catch (e) {
|
|
||||||
result = await this.waitForBlock(blockHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result = await this.loadBlockTemplate(blockHeight);
|
|
||||||
} else {
|
|
||||||
//wait for block
|
//wait for block
|
||||||
result = await this.waitForBlock(blockHeight);
|
result = await this.waitForBlock(blockHeight);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export class DiscordService implements OnModuleInit {
|
|||||||
|
|
||||||
|
|
||||||
constructor(private readonly configService: ConfigService) {
|
constructor(private readonly configService: ConfigService) {
|
||||||
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
|
if (process.env.MASTER == 'true') {
|
||||||
this.token = this.configService.get('DISCORD_BOT_TOKEN');
|
this.token = this.configService.get('DISCORD_BOT_TOKEN');
|
||||||
this.clientId = this.configService.get('DISCORD_BOT_CLIENTID');
|
this.clientId = this.configService.get('DISCORD_BOT_CLIENTID');
|
||||||
this.guildId = this.configService.get('DISCORD_BOT_GUILD_ID');
|
this.guildId = this.configService.get('DISCORD_BOT_GUILD_ID');
|
||||||
@@ -61,7 +61,7 @@ export class DiscordService implements OnModuleInit {
|
|||||||
|
|
||||||
async onModuleInit(): Promise<void> {
|
async onModuleInit(): Promise<void> {
|
||||||
|
|
||||||
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
|
if (process.env.MASTER == 'true') {
|
||||||
if (this.bot == null) {
|
if (this.bot == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ export class DiscordService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async registerCommands() {
|
private async registerCommands() {
|
||||||
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
|
if (process.env.MASTER == 'true') {
|
||||||
const rest = new REST().setToken(this.token);
|
const rest = new REST().setToken(this.token);
|
||||||
try {
|
try {
|
||||||
console.log(`Started refreshing ${commands.length} application (/) commands.`);
|
console.log(`Started refreshing ${commands.length} application (/) commands.`);
|
||||||
@@ -113,7 +113,7 @@ export class DiscordService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async notifyRestarted() {
|
public async notifyRestarted() {
|
||||||
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
|
if (process.env.MASTER == 'true') {
|
||||||
if (this.bot == null) {
|
if (this.bot == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,7 @@ export class DiscordService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async notifySubscribersBlockFound(height: number, block: Block, message: string) {
|
public async notifySubscribersBlockFound(height: number, block: Block, message: string) {
|
||||||
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
|
if (process.env.MASTER == 'true') {
|
||||||
if (this.bot == null) {
|
if (this.bot == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export class StratumV1Service implements OnModuleInit {
|
|||||||
|
|
||||||
async onModuleInit(): Promise<void> {
|
async onModuleInit(): Promise<void> {
|
||||||
|
|
||||||
if (process.env.NODE_APP_INSTANCE == '0') {
|
if (process.env.MASTER == 'true') {
|
||||||
await this.clientService.deleteAll();
|
await this.clientService.deleteAll();
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user