mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: iteration
This commit is contained in:
1 parent
4deee2d709
commit
bf9addf589
2 files changed
+15
-14
No files matched your search
+15
-14
@@ -1,27 +1,30 @@
|
|||||||
import { assertSecret, EventManager } from '@blitzkit/core';
|
// import { assertSecret, EventManager } from '@blitzkit/core';
|
||||||
|
// import { ActivityType, ShardingManager } from 'discord.js';
|
||||||
|
// import {
|
||||||
|
// discoveredIdsDefinitions,
|
||||||
|
// tankDefinitions,
|
||||||
|
// } from './core/blitzkit/nonBlockingPromises';
|
||||||
|
|
||||||
|
import { assertSecret } from '@blitzkit/core';
|
||||||
import { ActivityType, ShardingManager } from 'discord.js';
|
import { ActivityType, ShardingManager } from 'discord.js';
|
||||||
import {
|
import {
|
||||||
discoveredIdsDefinitions,
|
discoveredIdsDefinitions,
|
||||||
tankDefinitions,
|
tankDefinitions,
|
||||||
} from './core/blitzkit/nonBlockingPromises';
|
} from './core/blitzkit/nonBlockingPromises';
|
||||||
|
|
||||||
const somethingEvent = new EventManager();
|
let iteration = 0;
|
||||||
|
const interval = setInterval(async () => {
|
||||||
|
iteration++;
|
||||||
|
|
||||||
|
console.log(`Attempting launch on iteration ${iteration}`);
|
||||||
|
|
||||||
somethingEvent.on(async () => {
|
|
||||||
const manager = new ShardingManager('dist/bot/workers/bot.js', {
|
const manager = new ShardingManager('dist/bot/workers/bot.js', {
|
||||||
token: assertSecret(import.meta.env.DISCORD_TOKEN),
|
token: assertSecret(import.meta.env.DISCORD_TOKEN),
|
||||||
});
|
});
|
||||||
|
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
console.warn(`Shards didn't launch in 5 seconds; trying again...`);
|
|
||||||
somethingEvent.emit(undefined);
|
|
||||||
|
|
||||||
shards.forEach((shard) => shard.kill());
|
|
||||||
}, 5000);
|
|
||||||
|
|
||||||
const shards = await manager
|
const shards = await manager
|
||||||
.on('shardCreate', (shard) => {
|
.on('shardCreate', (shard) => {
|
||||||
clearTimeout(timeout);
|
clearInterval(interval);
|
||||||
console.log(`🟡 Launching shard ${shard.id}`);
|
console.log(`🟡 Launching shard ${shard.id}`);
|
||||||
shard.on('ready', () => console.log(`🟢 Launched shard ${shard.id}`));
|
shard.on('ready', () => console.log(`🟢 Launched shard ${shard.id}`));
|
||||||
})
|
})
|
||||||
@@ -76,6 +79,4 @@ somethingEvent.on(async () => {
|
|||||||
error,
|
error,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
}, 5000);
|
||||||
|
|
||||||
somethingEvent.emit(undefined);
|
|
||||||
Reference in new issue
Block a user