Replica number/index as env variable
kokholm
PROOP

2 years ago

TL:DR; Add RAILWAYREPLICAINDEX as a Railway-Provided Variable.

In the list of Railway-Provided Variables (https://docs.railway.app/reference/variables#railway-provided-variables) there is RAILWAY_REPLICA_ID.

I have a use case where i want replicas, but i only want to run some code (cron job in this case) on a single instance - something that is easily solvable if i could write
if (process.env.RAILWAY_REPLICA_INDEX === '0') {} or something like that.

There is most likely other ways to handle my specifc problem, but anyway i think that it would make sense to have access to the index/number of replica on other cases also.

1 Replies

dzikoysk
HOBBY

11 hours ago

If indexing is tricky, getting a persistent ID between instances would be already good enough I guess.


Welcome!

Sign in to your Railway account to join the conversation.

Loading...