Skip to content

Commit

Permalink
add tasks to create caches from query IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
ethowitz committed Jan 19, 2024
1 parent c0eab4f commit 0aa47b0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/tasks/readyset.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ require 'progressbar'
require 'terminal-table'

namespace :readyset do
desc 'Creates a cache from the given query ID'
task :create_cache, [:id] => :environment do |_, args|
Rails.application.eager_load!

if args.first
Readyset.create_cache!(id: args.first)
else
puts 'A query ID must be passed to this task'
end
end

desc 'Creates a cache from the given query ID whose queries will never fall back to the ' \
'primary database'
task :create_cache_always, [:id] => :environment do |_, args|
Rails.application.eager_load!

if args.first
Readyset.create_cache!(id: args.first, always: true)
else
puts 'A query ID must be passed to this task'
end
end

desc 'Prints a list of all the queries that ReadySet has proxied'
task proxied_queries: :environment do
Rails.application.eager_load!
Expand Down
42 changes: 42 additions & 0 deletions spec/rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,48 @@
end

describe 'readyset' do
describe 'create_cache' do
context 'when given a query ID as an argument' do
it 'creates a cache from the given query' do
query = build_and_execute_proxied_query(:proxied_query)
build_and_execute_proxied_query(:proxied_query_2)

Rake::Task['readyset:create_cache'].execute([query.id])

caches = Readyset::Query::CachedQuery.all
expect(caches).to eq([build(:cached_query)])
end
end

context 'when given no arguments' do
it 'prints an error message' do
expect { Rake::Task['readyset:create_cache'].execute }.
to output("A query ID must be passed to this task\n").to_stdout
end
end
end

describe 'create_cache_always' do
context 'when given a query ID as an argument' do
it 'creates a cache from the given query with `always` set to true' do
query = build_and_execute_proxied_query(:proxied_query)
build_and_execute_proxied_query(:proxied_query_2)

Rake::Task['readyset:create_cache_always'].execute([query.id])

caches = Readyset::Query::CachedQuery.all
expect(caches).to eq([build(:cached_query, always: true)])
end
end

context 'when given no arguments' do
it 'prints an error message' do
expect { Rake::Task['readyset:create_cache_always'].execute }.
to output("A query ID must be passed to this task\n").to_stdout
end
end
end

describe 'caches' do
it 'prints a table with the caches that currently exist on ReadySet' do
build_and_create_cache(:cached_query)
Expand Down

0 comments on commit 0aa47b0

Please sign in to comment.