Skip to content

Commit

Permalink
Remove delay between requests (bulk-invite command)
Browse files Browse the repository at this point in the history
  • Loading branch information
ba1uev committed Mar 7, 2023
1 parent 67c4e2b commit c52fee3
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/commands/bulk-invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import { adminApi } from "src/admin-api"
import { RoomInfoResponse } from "src/admin-api/types"
import config from "src/config/env"
import { commandPrefix } from "src/constants"
import { canExecuteCommand, CommandError, sendMessage, sleep, TemporaryState } from "src/utils"
import { canExecuteCommand, CommandError, sendMessage, TemporaryState } from "src/utils"

const moduleName = "BulkInviteCommand"
export const BULK_INVITE_COMMAND = "bulk-invite"
const CONFIRMATION_FLAG = "confirm"
const CONFIRMATION_DELAY_MINUTES = 2
const REQUEST_DELAY_SECONDS = 0.3

type State = {
roomId: string
Expand Down Expand Up @@ -53,15 +52,7 @@ export async function runBulkInviteCommand(
} catch (err) {
throw new CommandError(`Failed to retrieve user accounts`)
}
await sendMessage(
client,
roomId,
`Starting to invite ${users.length} users to the "${
request.roomName
}" room. The estimated time for the command to complete is ${Math.ceil(
users.length * REQUEST_DELAY_SECONDS,
)} seconds.`,
)
await sendMessage(client, roomId, `Starting to invite ${users.length} users to the "${request.roomName}" room.`)

// Iterate over users
type CommandReport = { failedInvites: string[]; succeedInvites: string[]; skippedInvitesNumber: number }
Expand All @@ -72,7 +63,6 @@ export async function runBulkInviteCommand(
await client.inviteUser(user.name, request.roomId)
report.succeedInvites.push(`✓ Successfully invited ${user.name}`)
LogService.info(moduleName, `Invited ${user.name} to room "${request.roomName}" (${request.roomId})`)
await sleep(REQUEST_DELAY_SECONDS * 1e3)
} catch (e) {
let errorMessage = ""
if (e instanceof CommandError) {
Expand Down

0 comments on commit c52fee3

Please sign in to comment.