Skip to content

Commit 19f450f

Browse files
author
Dan Croak
committed
Add Background Job guidelines
1 parent 36bae5d commit 19f450f

File tree

1 file changed

+45
-30
lines changed

1 file changed

+45
-30
lines changed

README.md

+45-30
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Write a [good commit message](http://goo.gl/w11us).
2828
* More information about commit (under 72 characters)
2929
* More information about commit (under 72 characters)
3030

31-
Share your branch:
31+
Share your branch.
3232

3333
git push origin [branch]
3434

@@ -130,6 +130,7 @@ Naming
130130
* Avoid abbreviations.
131131
* Avoid Hungarian notiation (`szName`).
132132
* Avoid types in names (`user_array`).
133+
* Name background jobs with a `Job` suffix.
133134
* Name the enumeration parameter the singular of the collection.
134135
* Name variables, methods, and classes with intention-revealing names..
135136
* Treat acronyms as words in names (`XmlHttpRequest` not `XMLHTTPRequest`),
@@ -149,12 +150,24 @@ Design
149150
* Don't swallow exceptions or "fail silently."
150151
* Don't write code that guesses at future functionality.
151152
* [Exceptions should be exceptional](http://rdd.me/yichhgvu).
152-
* [Keep the code simple](http://www.readability.com/articles/ko2aqda2).
153+
* [Keep the code simple](http://rdd.me/ko2aqda2).
153154
* Limit the number of collaborators of an object.
154155
* Prefer composition over inheritance.
155156
* Prefer small methods. One line is best.
156157
* Prefer small objects with a single, well-defined responsibility.
157-
* [Tell, don't ask](http://robots.thoughtbot.com/post/27572137956/tell-dont-ask).
158+
* [Tell, don't ask](http://goo.gl/Ztawt).
159+
160+
Javascript
161+
----------
162+
163+
* Define functions that operate on `window` or DOM in scope of `window`.
164+
* Initialize arrays using `[]`.
165+
* Initialize empty objects and hashes using `{}`.
166+
* Use `CamelCase` for prototypes, `mixedCase` for variables and functions,
167+
`SCREAMING_SNAKE_CASE` for constants, `_single_leading_underscore` for
168+
private variables and functions.
169+
* Use `data-` attributes to bind event handlers.
170+
* Use the [module pattern](http://goo.gl/JDtHN) to control method visibility.
158171

159172
Ruby
160173
----
@@ -200,8 +213,7 @@ Ruby
200213
* Use `Set` over `Array` for arrays with unique elements. The lookup is faster.
201214
* Use single-quotes for strings unless interpolating.
202215
* Use `unless boolean?` instead of `if !boolean?`.
203-
* Use [Factory Girl](https://github.com/thoughtbot/factory_girl) for setting up
204-
complicated test data.
216+
* Use [Factory Girl](http://goo.gl/zCsF1) to set up test data.
205217

206218
Rails
207219
-----
@@ -210,6 +222,8 @@ Rails
210222
* Avoid `member` and `collection` routes.
211223
* Avoid Single Table Inheritance.
212224
* Deploy to [Heroku](http://heroku.com).
225+
* Don't change a migration after it has been committed unless it cannot be
226+
solved with another migration.
213227
* Don't invoke a model's class directly from a view.
214228
* Don't use SQL or SQL fragments (`where('inviter_id is not null')`) outside of
215229
models.
@@ -225,21 +239,24 @@ Rails
225239
helpers.
226240
* Put all copy text in models, views, controllers, and mailers in
227241
`config/locales`.
242+
* Serve assets from S3 using [asset_sync](http://goo.gl/m58tF).
228243
* Set `config.action_mailer.delivery_method = :test` in the test environment.
244+
* Set `config.assets.initialize_on_precompile = false` in
245+
`config/application.rb`.
246+
* Set default values in the database.
229247
* Use `_path` over `_url` for named routes everywhere except mailer views.
248+
* Use `db/seeds.rb` for bootstrap data, not migrations.
230249
* Use `def self.method` over the `named_scope :method` DSL.
231-
* Use [Foreman](https://github.com/ddollar/foreman) to run the development
232-
server.
250+
* Use [Foreman](http://goo.gl/oy4uw) to run the development server.
233251
* Use `I18n.t 'dot.separated.key'` over
234252
`I18n.t :key, :scope => [:dot, :separated]`.
235253
* Use [Haml](http://haml-lang.com) for view templates.
236254
* Use `has_and_belongs_to_many` if all you need is a join table. Start simple.
237-
* Use namespaced locale lookup in the views by prefixing a period: `t '.title'`.
255+
* Use namespaced locale lookup in views by prefixing a period: `t '.title'`.
238256
* Use nested routes to express `belongs_to` relationships between resources.
239257
* Use one `ActionMailer` for the app. Name it `Mailer`.
240-
* Use [single recipient SMTP](https://gist.github.com/2042496) in the staging
241-
environment.
242-
* Use the default `render 'partial'` syntax over `render :partial => 'partial'`.
258+
* Use [single recipient SMTP](http://goo.gl/FWdhG) in staging environment.
259+
* Use the default `render 'partial'` syntax over `render partial: 'partial'`.
243260
* Use the `:only` option to explicitly state exposed routes.
244261

245262
Database
@@ -254,21 +271,21 @@ Database
254271
* Create a read-only [Heroku Follower](http://goo.gl/xWDMx) for your
255272
production database. If a Heroku database outage occurs, Heroku can use the
256273
follower to get your app back up and running faster.
274+
* Index all foreign keys.
257275
* Use the Heroku Follower database for analytics to limit reads on the primary
258276
database.
259277

260-
Javascript
261-
----------
278+
Background Jobs
279+
---------------
262280

263-
* Define functions that operate on `window` or DOM in scope of `window`.
264-
* Initialize arrays using `[]`.
265-
* Initialize empty objects and hashes using `{}`.
266-
* Use `CamelCase` for prototypes, `mixedCase` for variables and functions,
267-
`SCREAMING_SNAKE_CASE` for constants, `_single_leading_underscore` for
268-
private variables and functions.
269-
* Use `data-` attributes to bind event handlers.
270-
* Use the [module pattern](http://yuiblog.com/blog/2007/06/12/module-pattern)
271-
to control method visibility.
281+
* Define a `PRIORITY` constant at the top of the class.
282+
* Define two public methods: `self.enqueue` and `perform`.
283+
* Enqueue the job in `self.enqueue` [like this](http://goo.gl/C7e54).
284+
* Put background jobs in `app/jobs`.
285+
* Store IDs, not `ActiveRecord` objects for cleaner serialization. Re-find the
286+
`ActiveRecord` object in the `perform` method.
287+
* Subclass the job from `Struct.new(:something_id)`.
288+
* Use [`Delayed::Job`](http://goo.gl/sRYju) for background jobs.
272289

273290
Testing
274291
-------
@@ -286,14 +303,12 @@ Testing
286303
* Prefix `context` blocks names with 'given' when receiving input. Prefix with
287304
'when' in most other cases.
288305
* Run specs with `--format documentation`.
306+
* Test backgroun jobs with a [`Delayed::Job` matcher](http://goo.gl/bzBlN).
289307
* Use a `context` block for each execution path through the method.
290-
* Use a [Fake](http://robots.thoughtbot.com/post/219216005/fake-it) to stub
291-
requests to external services.
292-
* Use `before` blocks to clearly define the 'setup' phase of the
293-
[Four Phase Test](http://xunitpatterns.com/Four%20Phase%20Test.html).
308+
* Use a [Fake](http://goo.gl/YR7Hh) to stub requests to external services.
309+
* Use a `before` block to define phases of [Four Phase
310+
Test](http://goo.gl/J9FiJ).
294311
* Use integration tests to execute the entire app.
295-
* Use literal strings or non-[SUT](http://xunitpatterns.com/SUT.html) methods
296-
in test expectations when possible.
312+
* Use non-[SUT](http://goo.gl/r5Ti2) methods in expectations when possible.
297313
* Use one expection per `it` block.
298-
* Use stubs and spies (not mocks) in isolated tests to test only the object
299-
under test.
314+
* Use stubs and spies (not mocks) in isolated tests.

0 commit comments

Comments
 (0)