Can ActiveStorage::PurgeJob be enqueued to other than `default`?

Viewed 2621

There wasn't any queue named default in our Rails code. But it seems Sidekiq sets queue for ActiveStorage::PurgeJob as default. That was why purge_later never worked.

[ActiveJob] Enqueued ActiveStorage::PurgeJob (Job ID: .. ) to Sidekiq(default) with arguments

Is there a way to have different queue name than "default" here? I couldn't find documentation about it yet.

3 Answers

Setting the name of the Active Job queue used by Active Storage

You can change the queue used by Active Storage for its async jobs at the configuration level like this

config.active_storage.queue = :low_priority

To make this an application-wide change, put it into your application.rb. For environment-specific changes, put it into the relevant environment file under config/environments

See the documentation here:
https://guides.rubyonrails.org/configuring.html#configuring-active-storage

This did not work for me, instead the following worked

config.active_storage.queues = Hash.new(:default)

This is due to purge_job.rb looking up the queue name like so

queue_as { ActiveStorage.queues[:purge] }

For Rails 7.1, setting config.active_storage.queue doesn't impact the queue used by the PurgeJob.

This did the trick:

config.active_storage.queues.analysis = "my-queue"
config.active_storage.queues.purge = "my-queue"
Related