Replica number/index as env variable

kokholmPRO

a year 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.

0 Replies

Replica number/index as env variable - Railway Help Station