README.markdown in simple_worker-0.3.19 vs README.markdown in simple_worker-0.3.20

- old
+ new

@@ -43,45 +43,49 @@ worker = EmailWorker.new worker.to = current_user.email worker.subject = "Here is your mail!" worker.body = "This is the body" - **worker.run** + worker.run_local -Queue up your Worker --------------------- +Once you've got it working locally, the next step is to run it on the SimpleWorker cloud. +Queue up your Worker on the SimpleWorker Cloud +---------------------------------------------- + Let's say someone does something in your app and you want to send an email about it. worker = EmailWorker.new worker.to = current_user.email worker.subject = "Here is your mail!" worker.body = "This is the body" - **worker.queue** + worker.queue +This will send it off to the SimpleWorker cloud. + Schedule your Worker -------------------- There are two scenarios here, one is the scenario where you want something to happen due to a user action in your application. This is almost the same as queuing your worker. worker = EmailWorker.new worker.to = current_user.email worker.subject = "Here is your mail!" worker.body = "This is the body" - **worker.schedule(:start_at=>1.hours.since)** + worker.schedule(:start_at=>1.hours.since) Check Status ------------ If you still have access to the worker object, just call: worker.status If you only have the job ID, call: - SimpleWorker.status(job_id) + SimpleWorker.service.status(job_id) This will return a hash like: {"task_id"=>"ece460ce-12d8-11e0-8e15-12313b0440c6", "status"=>"running", @@ -89,27 +93,32 @@ "start_time"=>"2010-12-28T23:19:36+00:00", "end_time"=>nil, "duration"=>nil, "progress"=>{"percent"=>25}} -TODO: How to access log. Logging ------- +In your worker, just call the log method with the string you want logged: + log "Starting to do something..." -The log will be available for viewing via the SimpleWorker UI or via log in the API. +The log will be available for viewing via the SimpleWorker UI or via log in the API: + SimpleWorker.service.log(job_id) + Setting Progress ---------------- +This is just a way to let your users know where the job is at if required. + set_progress(:percent => 25, :message => "We are a quarter of the way there!") -You can actually put anything in this hash and it will be returned with a call to status. +You can actually put anything in this hash and it will be returned with a call to status. We recommend using +the format above for consistency and to get some additional features where we look for these values. - 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 @@ -175,9 +184,12 @@ Or simpler yet, try using relative paths: merge "../app/models/user" merge "../app/models/account.rb" + +The opposite can be done as well with "unmerge" and can be useful when using Rails to exclude classes that are automatically +merged. Bringing in other Workers ---------------------