---
title: "Rails 6 database seed uses inline Active Job adapter"
description:
  "Rails 6 uses inline Active Job adapter for background processing related to
  db:seed task"
canonical_url: "https://www.bigbinary.com/blog/database-seeding-task-uses-inline-active-job-adapter-in-rails-6"
markdown_url: "https://www.bigbinary.com/blog/database-seeding-task-uses-inline-active-job-adapter-in-rails-6.md"
---

# Rails 6 database seed uses inline Active Job adapter

Rails 6 uses inline Active Job adapter for background processing related to
db:seed task

- Author: Prathamesh Sonpatki
- Published: April 3, 2019
- Categories: Rails 6, Rails

We use the `db:seed` task to seed the database in Rails apps. Recently an
[issue](https://github.com/rails/rails/issues/34939) was reported on Rails issue
tracker where the `db:seed` task was not finishing.

In development environment, Rails uses
[async adapter](https://api.rubyonrails.org/v5.2/classes/ActiveJob/QueueAdapters/AsyncAdapter.html)
as the default Active Job adapter. The Async adapter runs jobs with an
in-process thread pool.

This specific issue was happening because the seed task was trying to attach a
file using Active Storage. Active Storage
[adds a job in the background](https://github.com/rails/rails/blob/9e34df00039d63b5672315419e76f06f80ef3dc4/activestorage/app/models/active_storage/attachment.rb#L37)
during the attachment process. This task was not getting executed properly using
the async adapter and it was causing the seed task to hang without exiting.

It was found out that by using the
[inline](https://api.rubyonrails.org/v5.2/classes/ActiveJob/QueueAdapters/InlineAdapter.html)
adapter in development environment, this issue goes away. But making a wholesale
change of making the default adapter in development environment as inline
adapter defeats the purpose of having the async adapter as default in the first
place.

Instead a change is made to
[execute all the code related to seeding using inline adapter](https://github.com/rails/rails/pull/34953).
The inline adapter makes sure that all the code will be executed immediately.

As the inline adapter does not allow queuing up the jobs in future, this can
result into an error if the seeding code somehow triggers such jobs. This
[issue](https://github.com/rails/rails/issues/35812#issuecomment-479385857) is
already reported on Github.

### Update

Active Job is optional framework and we can skip it completely. Now that seeding
depends on presence of Active Job, it was throwing an error when Active Job was
not part of the application. Also, executing the jobs inline automatically, when
users has set the Active Job queue adapter to something of their choice was
surprising for the users. So a
[change](https://github.com/rails/rails/pull/35896) has been made to load the
seeds inline only when Active Job is included in the application and the queue
adapter is `async`. This makes it backward compatible as well it does not change
user's choice of queue adapter automatically.

## Links

- [Human page](https://www.bigbinary.com/blog/database-seeding-task-uses-inline-active-job-adapter-in-rails-6)
