Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stylized the README.md #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions README → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Example
=======

First, create a worker in app/workers:

```
class AnalyticsWorker < Workling::Base
def potential_invited(options)
Hit.create :potential_user_id => options[:potential_user_id], :action => "invited"
Expand All @@ -34,33 +34,34 @@ class AnalyticsWorker < Workling::Base
Hit.create :potential_user_id => options[:potential_user_id], :action => "converted"
end
end
```

then, call it like this anywhere in your code:

```
Workling::Remote.run(:analytics_worker, :potential_invited, :potential_user_id => 1234)
```

Runners
=======
======

configure runners in your environment.rb:

Workling::Remote.dispatcher = Workling::Remote::Runners::NotRemoteRunner.new (this runner just executes everything normally)

`Workling::Remote.dispatcher = Workling::Remote::Runners::NotRemoteRunner.new` (this runner just executes everything normally)
SpawnRunner
===========
==========

this uses http://rubyforge.org/projects/spawn to take the process out of the request cycle.

configure it like this:

SpawnRunner.options = { :method => :spawn }
`SpawnRunner.options = { :method => :spawn }`

StarlingRunner
==============

This uses Twitter's Starling to enable your asynch code to run on different VMs. Activate it like this in your environment:

Workling::Remote.dispatcher = Workling::Remote::Runners::StarlingRunner.new
`Workling::Remote.dispatcher = Workling::Remote::Runners::StarlingRunner.new`

This takes care of several things:

Expand Down Expand Up @@ -105,26 +106,26 @@ Your worklings can write back to a return store. This allows you to write progre
Workling::Return::Store.instance = Workling::Return::Store::MemoryReturnStore.new

Here is an example workling that crawls an addressbook and puts results in a return store. Worling makes sure you have options[:uid] in your hash - pass this into the return store with your results.

```
require 'blackbook'
class NetworkWorker < Workling::Base
def search(options)
results = Blackbook.get(options[:key], options[:username], options[:password])
Workling::Return.set(options[:uid], results)
end
end

```
call your workling as above:

@uid = Workling::Remote.run(:network_worker, :search, { :key => :gmail, :username => "[email protected]", :password => "bar" })
`@uid = Workling::Remote.run(:network_worker, :search, { :key => :gmail, :username => "[email protected]", :password => "bar" })`

or simply:

@uid = NetworkWorker.asynch_search({ :key => :gmail, :username => "[email protected]", :password => "bar" })
`@uid = NetworkWorker.asynch_search({ :key => :gmail, :username => "[email protected]", :password => "bar" })`

you can now use the @uid to query the return store:

results = Workling::Return.get(@uid)
`results = Workling::Return.get(@uid)`

of course, you can use this for progress indicators. just put the progress into the return store.

Expand Down