Skip to content

Commit

Permalink
feat: added rake tasks for QOL
Browse files Browse the repository at this point in the history
- cache_supported_queries => Readyset::Query.cache_all_supported!
- drop_all_caches => Readyset::Query.drop_all_caches!
- all_caches => Readyset::Query.all_cached
  • Loading branch information
helpotters committed Dec 20, 2023
1 parent 30dc3c8 commit 4708df2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/tasks/readyset.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# lib/tasks/readyset.rake

namespace :readyset do
desc 'Creates caches for all of the supported queries on ReadySet'
task cache_supported_queries: :environment do
Readyset::Query.cache_all_supported!
end

desc 'Drops all the caches on ReadySet'
task drop_all_caches: :environment do
Readyset::Query.drop_all_caches!
end

desc 'Prints a list of all the cached queries on ReadySet'
task all_caches: :environment do
Readyset::Query.all_cached.each do |query|
puts query.inspect
end
end
end
49 changes: 49 additions & 0 deletions spec/tasks/readyset_tasks_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# spec/tasks/readyset_tasks_spec.rb

require 'rails_helper'
require 'rake'

RSpec.describe 'ReadySet tasks', type: :task do
before :all do
Rake.application.rake_require('tasks/readyset')
Rake::Task.define_task(:environment)
end

describe 'readyset:cache_supported_queries' do
it 'creates caches for all supported queries' do
# Setup
allow(Readyset::Query).to receive(:cache_all_supported!)

# Exercise
Rake::Task['readyset:cache_supported_queries'].execute

# Verify
expect(Readyset::Query).to have_received(:cache_all_supported!)
end
end
describe 'readyset:drop_all_caches' do
it 'drops all caches' do
# Setup
allow(Readyset::Query).to receive(:drop_all_caches!)

# Exercise
Rake::Task['readyset:drop_all_caches'].execute

# Verify
expect(Readyset::Query).to have_received(:drop_all_caches!)
end
end

describe 'readyset:all_caches' do
it 'prints all cached queries' do
# Setup
allow(Readyset::Query).to receive(:all_cached).and_return([double, double])

# Exercise
Rake::Task['readyset:all_caches'].execute

# Verify
expect(Readyset::Query).to have_received(:all_cached)
end
end
end

0 comments on commit 4708df2

Please sign in to comment.