-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
137 lines (101 loc) · 5.91 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Sidekiq-ActiveRecord by sidekiq-orm</title>
<link rel="stylesheet" href="stylesheets/styles.css">
<link rel="stylesheet" href="stylesheets/pygment_trac.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="javascripts/respond.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--[if lt IE 8]>
<link rel="stylesheet" href="stylesheets/ie.css">
<![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
</head>
<body>
<div id="header">
<nav>
<li class="fork"><a href="https://github.com/sidekiq-orm">View On GitHub</a></li>
</nav>
</div><!-- end header -->
<div class="wrapper">
<section>
<div id="title">
<h1>Sidekiq-ActiveRecord</h1>
<p>Sidekiq-ORM Project</p>
<hr>
<span class="credits left">Project maintained by <a href="https://github.com/sidekiq-orm">sidekiq-orm</a></span>
<span class="credits right">Hosted on GitHub Pages — Theme by <a href="https://twitter.com/michigangraham">mattgraham</a></span>
</div>
<p><a href="https://github.com/sidekiq-orm/sidekiq-activerecord">Sidekiq::Activerecord</a> encapsulates common patterns and various interactions between <a href="https://github.com/mperham/sidekiq">Sidekiq</a> and <a href="http://guides.rubyonrails.org/active_record_basics.html">ActiveRecord</a>.</p>
<h2>
<a name="common-patterns" class="anchor" href="#common-patterns"><span class="octicon octicon-link"></span></a>Common Patterns</h2>
<p>If you've been using Sidekiq for a while, you've probably noticed a recurring pattern in your workers:</p>
<br>
<h2>
<a name="sidekiqactiverecordtaskworker" class="anchor" href="#sidekiqactiverecordtaskworker"><span class="octicon octicon-link"></span></a><a href="/task.html">Sidekiq::ActiveRecord::TaskWorker</a>
</h2>
<p>A very conventional pattern, is to have a worker that gets a model identifier, loads it and runs some custom logic on the model. </p>
<p><a href="/task.html"><code>TaskWorker</code></a> provides a simple and clean interface, which reduces the boilerplate and exposes only the custom logic. </p>
<p>Here's a simple example:</p>
<div class="highlight highlight-ruby"><pre><span class="k">class</span> <span class="nc">UserTaskWorker</span> <span class="o"><</span> <span class="no">Sidekiq</span><span class="o">::</span><span class="no">ActiveRecord</span><span class="o">::</span><span class="no">TaskWorker</span>
<span class="n">sidekiq_task_model</span> <span class="ss">:user</span> <span class="c1"># or User</span>
<span class="k">def</span> <span class="nf">perform_on_user</span>
<span class="no">UserService</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
<span class="k">end</span>
<span class="k">end</span>
</pre></div>
<p>For a more see the <a href="/task.html">TaskWorker documentation</a>.</p>
<br>
<hr>
<br>
<h2>
<a name="sidekiqactiverecordmanagerworker" class="anchor" href="#sidekiqactiverecordmanagerworker"><span class="octicon octicon-link"></span></a><a href="/manager.html">Sidekiq::ActiveRecord::ManagerWorker</a>
</h2>
<p>Another fairly common <code>Sidekiq::Worker</code> pattern, is a parent worker which goes over a model collection and enqueues a child worker for each model in the collection.</p>
<p>Here's a simple example:</p>
<div class="highlight highlight-ruby"><pre><span class="c1"># Parent Worker</span>
<span class="k">class</span> <span class="nc">UserSyncer</span> <span class="o"><</span> <span class="no">Sidekiq</span><span class="o">::</span><span class="no">ActiveRecord</span><span class="o">::</span><span class="no">ManagerWorker</span>
<span class="n">sidekiq_delegate_task_to</span> <span class="ss">:user_task_worker</span> <span class="c1"># or UserTaskWorker</span>
<span class="k">end</span>
</pre></div>
<p>Then, just call the worker with the model collection:</p>
<div class="highlight highlight-ruby"><pre><span class="no">UserSyncer</span><span class="o">.</span><span class="n">perform_query_async</span><span class="p">(</span><span class="no">User</span><span class="o">.</span><span class="n">active</span><span class="p">)</span>
</pre></div>
<p>For a more see the <a href="/manager.html">ManagerWorker documentation</a>.</p>
<br>
<hr>
<br>
<h1>
<a name="documention" class="anchor" href="#documention"><span class="octicon octicon-link"></span></a>Documentation</h1>
<p>Checkout the project's <a href="https://github.com/sidekiq-orm/sidekiq-activerecord/wiki">Wiki Page</a></p>
<br>
<hr>
<br>
<h1>
<a name="installation" class="anchor" href="#installation"><span class="octicon octicon-link"></span></a>Installation</h1>
<p>Add this line to your application's Gemfile:</p>
<pre><code>gem 'sidekiq-activerecord', '~> 0.0.5'
</code></pre>
<p>And then execute:</p>
<pre><code>$ bundle
</code></pre>
</section>
</div>
<!--[if !IE]><script>fixScale(document);</script><![endif]-->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-51556764-1");
pageTracker._trackPageview();
} catch(err) {}
</script>
</body>
</html>