Skip to content

Commit

Permalink
Allow running tasks without requiring all/any of rails (#199)
Browse files Browse the repository at this point in the history
* Allow running tasks without requiring all/any of rails

- Remove initial action mailer require, per #60 (comment)
- Add an ENV var that allows you to not do any additional requires here, so that it's all handled by the Rails app

* Update README.md
  • Loading branch information
ghiculescu committed Aug 17, 2021
1 parent c59d4bf commit 6821c9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -595,12 +595,14 @@ Note: this plugs in the given webserver directly into rack, it doesn't use any `

### Excluding ActiveRecord

By default, derailed will load ActiveRecord if the gem is included as a dependency. It is included by default, if you just include the `rails` gem. If you are using a different ORM, you will either need to only include the `railties` gem, or set the `DERAILED_SKIP_ACTIVE_RECORD` flag.
By default, derailed will load ActiveRecord if the gem is included as a dependency. It is included by default, if you just include the `rails` gem. If you are using a different ORM, you will either need to only include the `railties` gem, or set the `DERAILED_SKIP_ACTIVE_RECORD` environment variable.

```
$ DERAILED_SKIP_ACTIVE_RECORD=true
```

Alternatively, use the `DERAILED_SKIP_RAILS_REQUIRES` environment variable to have derailed not require any Rails gems. Your app will then need to require them as part of its boot sequence.

### Running in a different environment

Tests run against the production environment by default, but it's easy to
Expand Down
5 changes: 3 additions & 2 deletions bin/derailed
Expand Up @@ -80,9 +80,10 @@ class DerailedBenchmarkCLI < Thor
require 'bundler/setup'

begin
if ENV["DERAILED_SKIP_ACTIVE_RECORD"]
if ENV["DERAILED_SKIP_RAILS_REQUIRES"]
# do nothing. your app will handle requiring Rails for booting.
elsif ENV["DERAILED_SKIP_ACTIVE_RECORD"]
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
else
Expand Down

0 comments on commit 6821c9c

Please sign in to comment.