IronCast 2: What is a worker file? – IronWorker 101 Part 2/4
In a series of four IronCasts, we will provide a high-level introduction to using IronWorker, an easy-to-use scalable task queue. In this series, we will be using an example application which is written in Rails. However, the same concept applies to every language or framework.
In this video, we will show you how to write your worker file to declare and package dependencies for your IronWorker.
Let’s breakdown our worker file and analyse it line by line
runtime "ruby"
# include postgresql and activerecord
gem "pg"
gem "activerecord"
exec "pygments_worker.rb"
# Merging models
dir '../app/models/'
remote
You can find the workers code in the sample application here and the actual code package that has been uploaded to the server here.
- gem “pg” and gem “activerecord” will package up the two gems as well as any dependencies of those two libraires into the __gem__ folder in the root directory
- exec “pygments_worker.rb” will package up pygments_worker.rb and execute this file when a worker is run
- dir ‘../../app/models’ means that we will go two directories up from our current directory which is the location of the worker file and then go into the app directory and package up the models folder into the root directory of the worker. You can see this here.
You can also pass an optional argument to this and change where the folder is saved. For example, if you would like to maintain the original folder structure, you can use dir ‘../../app/models’, ‘app’, the second optional argument ‘app’ indicates that you would like to save the models folder inside an app folder and save the app folder into the root directory of your worker. For more info, click here. - remote or (full_remote_build true) means that for gems like ‘pg’ which requires building native extensions. We will build the native extension on iron.io server.
For more information on how to construct your worker file, you can find corresponding documentation here.