Skip to content

Business intelligence made simple

Use ActiveJob for async

Andrew Kane0f1ab47b33cf
diff --git a/README.md b/README.md
index 2366cb7f..ca5782cd 100644
--- a/README.md
+++ b/README.md
@@ -629,6 +629,20 @@ For an easy way to group by day, week, month, and more with correct time zones,
Looking for a standalone version? Check out [Ghost Blazer](https://github.com/buren/ghost_blazer).
+## Performance
+
+By default, queries take up a request while they are running. To run queries asynchronously, add to your config:
+
+```yml
+async: true
+```
+
+**Note:** Requires Rails 5+ and caching to be enabled. If you have multiple web processes, your app must use a centralized cache store like Memcached or Redis.
+
+```ruby
+config.cache_store = :mem_cache_store
+```
+
## Anomaly Detection on Heroku
Add the [R buildpack](https://github.com/virtualstaticvoid/heroku-buildpack-r) to your app.
diff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rb
index 56aa0d4a..f47469ec 100644
--- a/app/controllers/blazer/queries_controller.rb
+++ b/app/controllers/blazer/queries_controller.rb
@@ -118,7 +118,7 @@ module Blazer
options = {user: blazer_user, query: @query, refresh_cache: params[:check], run_id: @run_id, async: Blazer.async}
if Blazer.async && request.format.symbol != :csv
result = []
- Blazer::RunStatementJob.perform_async(result, @data_source, @statement, options)
+ Blazer::RunStatementJob.perform_later(result, @data_source.id, @statement, options)
wait_start = Time.now
loop do
sleep(0.02)
diff --git a/lib/blazer/run_statement_job.rb b/lib/blazer/run_statement_job.rb
index 04ce14f0..b451d9c3 100644
--- a/lib/blazer/run_statement_job.rb
+++ b/lib/blazer/run_statement_job.rb
@@ -1,11 +1,9 @@
-require "sucker_punch"
-
module Blazer
- class RunStatementJob
- include SuckerPunch::Job
- workers 4
+ class RunStatementJob < ActiveJob::Base
+ self.queue_adapter = :async
- def perform(result, data_source, statement, options)
+ def perform(result, data_source_id, statement, options)
+ data_source = Blazer.data_sources[data_source_id]
begin
ActiveRecord::Base.connection_pool.with_connection do
result << Blazer::RunStatement.new.perform(data_source, statement, options)