a year ago
is it possible to set variables to auto increment based on the replicas spawned? i.e, I have a variable cluster set to 1 but if another replica is added that increases to 2
0 Replies
a year ago
there isnt a way to do that natively through the dashboard, but would you mind telling us your usecase?
it's a discord bot, and I was kinda hoping I can set this up natively without explicitly doing so myself. I'm spawning multiple instances of the bot and I use the cluster variable to identify them accordingly for logs.
but then again, does railway already do this in a way when u spawn replicas? i.e, having an identifier for them that I can use within my code instead?
a year ago
each replica would get a unique RAILWAY_REPLICA_ID
environment variable available to it, its a UUID not an Int but it sounds like it should work for your usecase
a year ago
railway also already adds on the replica id to the logs
a year ago
yep it's just a regular environment variable
another question for you, I have some logic that more or less sets shards to a specific cluster. got any idea on how using the replica id I could do such thing as the replica IDs aren't exaclty single digits or incremental.
cluster_kwargs = {}
if os.environ.get("IS_PRODUCTION"):
total_shards = 36
cluster_id = int(os.environ["CLUSTER"])
offset = cluster_id - 1 # As we start at 1
number_of_shards_per_cluster = 3
# Calculate the shard id's this cluster should handle
# For example on cluster 1 this would be equal to
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
shard_ids = [
i
for i in range(
offset * number_of_shards_per_cluster,
(offset * number_of_shards_per_cluster) + number_of_shards_per_cluster,
)
if i < total_shards
]
cluster_kwargs = {
"shard_ids": shard_ids,
"shard_count": total_shards,
}
a year ago
we'll do share your solution!