Including other files in your Worker with “merge”

Previously, your worker file/class had to be self contained (ie: single file including all code for the worker).

Now you can use the new “merge” class method for instance:

class TestWorker2 < SimpleWorker::Base

merge "models/model_1.rb"

This will automatically upload the merged files to the SimpleWorker service and ‘require’ them in your Worker class.

If you want to use the special methods like “log” in your merged classes, use the SimpleWorker::UsedInWorker mix-in, for instance:

class Model1

include SimpleWorker::UsedInWorker

That’s about it, the rest will be taken care of for you.

If you want to kick off other workers from within the first worker, use merge_worker instead:

class TestWorker2 < SimpleWorker::Base
         merge “models/model_1.rb”
         merge_worker “my_other_worker.rb”, “MyOtherWorker” 
         # second parameter is the class name

The merge_worker does things a bit differently so it can be handled properly after uploading to the worker cloud.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.