simple_worker 0.3.10 → 0.3.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,14 +1,74 @@
1
1
  Using Simple Worker
2
2
 
3
- 1) Upload code
3
+ Getting Started
4
+ ===============
4
5
 
5
- simple_worker.upload
6
+ Configure SimpleWorker
7
+ ----------------------
6
8
 
7
- 2) Queue up a job for code to run
9
+ You really just need your access keys.
8
10
 
9
- simple_worker.queue
11
+ SimpleWorker.configure do |config|
12
+ config.access_key = ACCESS_KEY
13
+ config.secret_key = SECRET_KEY
14
+ end
10
15
 
11
- 3)
16
+ Write a Worker
17
+ --------------
12
18
 
19
+ Here's an example worker that sends an email:
13
20
 
21
+ require 'simple_worker'
14
22
 
23
+ class EmailWorker < SimpleWorker::Base
24
+
25
+ attr_accessor :to, :subject, :body
26
+
27
+ # This is the method that will be run
28
+ def run
29
+ send_email(:to=>to, :subject=>subject, :body=>body)
30
+ end
31
+
32
+ def send_email
33
+ # Put sending code here
34
+ end
35
+ end
36
+
37
+ Queue up your Worker
38
+ --------------------
39
+
40
+ Let's say someone does something in your app and you want to send an email about it.
41
+
42
+ worker = EmailWorker.new
43
+ worker.to = current_user.email
44
+ worker.subject = "Here is your mail!"
45
+ worker.body = "This is the body"
46
+ worker.queue
47
+
48
+ Schedule your Worker
49
+ --------------------
50
+
51
+ There are two scenarios here, one is the scenario where you want something to happen due to a user
52
+ action in your application. This is almost the same as queuing your worker.
53
+
54
+ worker = EmailWorker.new
55
+ worker.to = current_user.email
56
+ worker.subject = "Here is your mail!"
57
+ worker.body = "This is the body"
58
+ worker.schedule(:start_at=>1.hours.since)
59
+
60
+ The alternative is when you want to user it like Cron. In this case you'll probably
61
+ want to write a script that will schedule, you don't want to schedule it everytime your
62
+ app starts or anything so best to keep it external.
63
+
64
+ Create a file called 'schedule_email_worker.rb' and add this:
65
+
66
+ require 'simple_worker'
67
+
68
+ worker = EmailWorker.new
69
+ worker.to = current_user.email
70
+ worker.subject = "Here is your mail!"
71
+ worker.body = "This is the body"
72
+ worker.schedule(:start_at=>1.hours.since, :run_every=>3600)
73
+
74
+ Now your worker will be scheduled to run every hour.
@@ -58,6 +58,10 @@ module SimpleWorker
58
58
  puts str.to_s
59
59
  end
60
60
 
61
+ def user_dir
62
+ "."
63
+ end
64
+
61
65
  def set_progress(hash)
62
66
  puts 'set_progress: ' + hash.inspect
63
67
  end
@@ -113,9 +117,10 @@ module SimpleWorker
113
117
 
114
118
  end
115
119
 
116
- def before_run
120
+ def before_run
117
121
 
118
122
  end
123
+
119
124
  def after_run
120
125
 
121
126
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_worker
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 10
10
- version: 0.3.10
9
+ - 11
10
+ version: 0.3.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Travis Reeder
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-24 00:00:00 -07:00
18
+ date: 2010-08-27 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency