refactor: Remove nanoid dependency from native Python task runner (#19025)

This commit is contained in:
Iván Ovejero
2025-09-01 10:22:27 +02:00
committed by GitHub
parent 6aeced8aed
commit 5b5f60212a
5 changed files with 23 additions and 25 deletions

View File

@@ -0,0 +1,21 @@
import secrets
import string
NANOID_CHARSET = string.ascii_uppercase + string.ascii_lowercase + string.digits
TARGET_NANOID_LEN = 22
CHARSET_LEN = len(NANOID_CHARSET)
# Collision probability is roughly k^2/(2n) where k=IDs generated, n=possibilities
# At 10^12 IDs generated with 62^22 possibilities -> ~1.8e-16 chance of collision
def nanoid() -> str:
nanoid = ""
while len(nanoid) < TARGET_NANOID_LEN:
index = secrets.randbits(6)
if index < CHARSET_LEN:
nanoid += NANOID_CHARSET[index]
return nanoid

View File

@@ -1,9 +0,0 @@
from nanoid.generate import generate
import string
NANOID_CHARSET = string.ascii_uppercase + string.ascii_lowercase + string.digits
NANOID_LENGTH = 21
def nanoid() -> str:
return generate(NANOID_CHARSET, NANOID_LENGTH)

View File

@@ -13,7 +13,7 @@ from src.errors import (
TaskMissingError,
)
from src.message_types.broker import TaskSettings
from src.nanoid_utils import nanoid
from src.nanoid import nanoid
from src.constants import (
RUNNER_NAME,