108 lines
2.9 KiB
Ruby
108 lines
2.9 KiB
Ruby
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
|
|
require "rake/testtask"
|
|
require_relative "config/application"
|
|
|
|
Rails.application.load_tasks
|
|
Dir.glob(Rails.root.join("rake", "*.rake")).each { |rake_file| load rake_file }
|
|
|
|
task set_ar_stdout: :environment do
|
|
ActiveRecord::Base.logger = Logger.new($stdout)
|
|
end
|
|
|
|
task set_logger_stdout: :environment do
|
|
Rails.logger = Logger.new($stdout)
|
|
Rails.logger.formatter =
|
|
proc { |severity, datetime, progname, msg| "#{severity}: #{msg}\n" }
|
|
ActiveRecord::Base.logger = nil
|
|
ActiveJob::Base.logger = nil
|
|
GoodJob.logger = Rails.logger
|
|
end
|
|
|
|
task periodic_tasks: %i[environment set_logger_stdout] do
|
|
Thread.new do
|
|
loop do
|
|
Rake::Task["pghero:capture_space_stats"].execute
|
|
puts "logged space stats"
|
|
sleep 6.hours
|
|
end
|
|
end
|
|
|
|
Thread.new do
|
|
loop do
|
|
Rake::Task["pghero:capture_query_stats"].execute
|
|
puts "logged query stats"
|
|
sleep 5.minutes
|
|
end
|
|
end
|
|
|
|
loop { sleep 10 }
|
|
end
|
|
|
|
namespace :db_sampler do
|
|
task export: :environment do
|
|
url_names = ENV["url_names"] || raise("need 'url_names' (comma-separated)")
|
|
outfile = $stdout
|
|
DbSampler.new(outfile).export(url_names.split(","))
|
|
ensure
|
|
outfile.close if outfile
|
|
end
|
|
|
|
task import: [:environment] do
|
|
infile = $stdin
|
|
DbSampler.new(infile).import
|
|
ensure
|
|
infile.close if infile
|
|
end
|
|
end
|
|
|
|
task good_job: %i[environment set_ar_stdout set_logger_stdout] do
|
|
env_hash = {
|
|
"RAILS_ENV" => "worker",
|
|
"GOOD_JOB_POLL_INTERVAL" => "5",
|
|
"GOOD_JOB_MAX_CACHE" => "10000",
|
|
"GOOD_JOB_QUEUE_SELECT_LIMIT" => "4096",
|
|
"GOOD_JOB_MAX_THREADS" => "4",
|
|
"GOOD_JOB_ENABLE_CRON" => "1",
|
|
"GOOD_JOB_QUEUES" =>
|
|
ENV["GOOD_JOB_QUEUES"] ||
|
|
%w[manual:4 fa_post,e621:2 *:6].reject(&:nil?).join(";"),
|
|
}
|
|
|
|
env_hash.each do |key, value|
|
|
ENV[key] = value
|
|
puts "$> #{key.light_black.bold} = #{value.bold}"
|
|
end
|
|
|
|
cmd = "bundle exec good_job"
|
|
puts "$> #{cmd.bold}"
|
|
exec(cmd)
|
|
end
|
|
|
|
task :reverse_csv do
|
|
file = ENV["file"] || raise("need 'file' (file path)")
|
|
in_csv = CSV.parse(File.open(file, "r+"), headers: true)
|
|
out_csv =
|
|
CSV.new(
|
|
File.open("rev_" + file, "w"),
|
|
write_headers: true,
|
|
headers: in_csv.headers,
|
|
)
|
|
in_csv.reverse_each { |row| out_csv << row.map(&:second) }
|
|
out_csv.close
|
|
end
|
|
|
|
task migrate_domain: :environment do
|
|
# Domain::MigrateToDomain.new.migrate_e621_users
|
|
# Domain::MigrateToDomain.new.migrate_e621_posts
|
|
# Domain::MigrateToDomain.new.migrate_fa_users
|
|
# Domain::MigrateToDomain.new.migrate_fa_posts
|
|
# Domain::MigrateToDomain.new.migrate_e621_users_favs
|
|
# Domain::MigrateToDomain.new.migrate_fa_users_favs
|
|
# Domain::MigrateToDomain.new.migrate_fa_users_followed_users
|
|
# Domain::MigrateToDomain.new.migrate_inkbunny_users
|
|
Domain::MigrateToDomain.new.migrate_inkbunny_posts
|
|
Domain::MigrateToDomain.new.migrate_inkbunny_pools
|
|
end
|