README.markdown in simple_worker-0.3.15 vs README.markdown in simple_worker-0.3.16
- old
+ new
@@ -1,10 +1,12 @@
-Using Simple Worker
-
Getting Started
===============
+[Sign up for a SimpleWorker account][1], it's free to try!
+
+[1]: http://www.simpleworker.com/
+
Configure SimpleWorker
----------------------
You really just need your access keys.
@@ -66,22 +68,57 @@
worker.to = current_user.email
worker.subject = "Here is your mail!"
worker.body = "This is the body"
**worker.schedule(:start_at=>1.hours.since)**
+Check Status
+------------
+If you still have access to the worker object, just call:
-Schedule your Worker Recurring
+ worker.status
+
+If you only have the job ID, call:
+
+ SimpleWorker.status(job_id)
+
+This will return a hash like:
+
+ {"task_id"=>"ece460ce-12d8-11e0-8e15-12313b0440c6",
+ "status"=>"running",
+ "msg"=>nil,
+ "start_time"=>"2010-12-28T23:19:36+00:00",
+ "end_time"=>nil,
+ "duration"=>nil,
+ "progress"=>{"percent"=>25}}
+
+TODO: How to access log.
+
+Logging
+-------
+
+ log "Starting to do something..."
+
+
+Setting Progress
+----------------
+
+ set_progress(:percent => progress, :message => "Server running. Trying to connect...")
+
+
+
+Schedule a Recurring Job - CRON
------------------------------
The alternative is when you want to user it like Cron. In this case you'll probably
want to write a script that will schedule, you don't want to schedule it everytime your
app starts or anything so best to keep it external.
Create a file called 'schedule_email_worker.rb' and add this:
require 'simple_worker'
+ require_relative 'email_worker'
worker = EmailWorker.new
worker.to = current_user.email
worker.subject = "Here is your mail!"
worker.body = "This is the body"
@@ -90,22 +127,65 @@
Now run it and your worker will be scheduled to run every hour.
SimpleWorker on Rails
---------------------
-SimpleWorker only supports Rails 3+.
+Rails 2.X:
-Setup:
+ config.gem 'simple_worker'
-- Make a workers directory at RAILS_ROOT/app/workers.
-- In application.rb, uncomment config.autoload_paths and put:
+Rails 3.X:
- config.autoload_paths += %W(#{config.paths.app}/workers)
+ gem 'simple_worker'
-Now you can use your workers like their part of your app!
+Now you can use your workers like they're part of your app! We recommend putting your worker classes in
+/app/workers path.
+Configuring a Database Connection
+---------------------------------
+Although you could easily do this in your worker, this makes it a bit more convenient and more importantly
+it will create the connection for you. If you are using ActiveRecord, you would add the following to your
+SimpleWorker config:
+
+ config.database = {
+ :adapter => "mysql2",
+ :host => "localhost",
+ :database => "appdb",
+ :username => "appuser",
+ :password => "secret"
+ }
+
+Then before you job is run, SimpleWorker will establish the ActiveRecord connection.
+
+Including/Merging other Ruby Classes
+------------------------------------
+
+If you are using the Rails setup above, you can probably skip this as your models will automatically be merged.
+
+ class AvgWorker < SimpleWorker::Base
+
+ attr_accessor :aws_access_key,
+ :aws_secret_key,
+ :s3_suffix
+
+ merge File.join(File.dirname(__FILE__), "..", "app", "models", "user.rb")
+ merge File.join(File.dirname(__FILE__), "..", "app", "models", "account")
+
+Or simpler yet, try using relative paths:
+
+ merge "../app/models/user"
+ merge "../app/models/account.rb"
+
+
+Bringing in other Workers
+---------------------
+
+merge_worker
+TODO
+
+
Configuration Options
---------------------
### Global Attributes
@@ -116,9 +196,9 @@
Eg:
config.global_attributes[:db_user] = "sa"
config.global_attributes[:db_pass] = "pass"
-Then in your worker, you must have:
+Then in your worker, you would have the attributes defined:
attr_accessor :db_user, :db_pass