Looking into using IronWorker to run some common services, however I'm wondering if there is a way to know in the worker itself what environment it is running under. For example, in our main code base we set a server var ENV to equal one of 'development', 'staging', or 'production'. Based on this variable, our app knows which config files to load (via config files in dirs config/development, config/staging, and config/production). I would like to have something similar setup for a worker.
I've noticed that when I upload a worker via the cli, I can do the following:
iron_worker upload workers/example/hello_world --env staging
Which allows me to have one iron.json config file with dev, staging, and production keys in it. e.g.,
{
"production": {
"token": "AAAAAAAAAAAAAAAAAAAAAAAAAAA",
"project_id": "000000000000000000000001"
},
"staging": {
"token": "BBBBBBBBBBBBBBBBBBBBBBBBBB",
"project_id": "000000000000000000000002"
},
"development": {
"token": "CCCCCCCCCCCCCCCCCCCCCCCCCC",
"project_id": "000000000000000000000003"
},
"test": {
"token": "DDDDDDDDDDDDDDDDDDDDDDDDDD",
"project_id": "000000000000000000000004"
}
}
However, in the worker itself I don't have access to the env var from the cli so when the worker needs to load in some config vars it doesn't know which dir to look in.
In the documentation here http://dev.iron.io/worker/reference/dotworker/ they show that you can set an environment variable in the .worker file, but this means I would need to have a separate worker file for each environment and (maybe?) swap them out depending on which environment I am deploying to.
There are some tricky way:
1) iron.json. Same format as described, no changes
2) .worker file. Pass environment through, from local system to IronWorker environment. Add this line to .worker file:
3) Upload code command. Instead of
Use different syntax:
4) Check environment on Worker side (any language-of-choice supported of course):