forked from Mapotempo/optimizer-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
70 lines (52 loc) · 2.09 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'rubygems'
require 'bundler/setup'
require 'resque/tasks'
# Clean the jobs which are interrupted by restarting queues which left in working status
# TODO: eventually instead of removing these jobs, we can just re-queue them
namespace :resque do
task prune_dead_workers: :environment do
# Clear the resque workers who were killed off without unregistering
Resque.workers.each(&:prune_dead_workers)
end
task clean_working_job_ids: :prune_dead_workers do
next if ENV['APP_ENV'] == 'production'
puts "#{Time.now} Cleaning existing jobs with #{Resque::Plugins::Status::STATUS_WORKING} status..."
Resque::Plugins::Status::Hash.statuses.each{ |job|
next unless job.status == Resque::Plugins::Status::STATUS_WORKING && job.time < Time.now - 10.seconds
# Protect the jobs running on other queues
running_job_ids =
Resque.workers.map{ |w|
j = w.job(false)
j['payload'] && j['payload']['args'].first
}
next if running_job_ids.include?(job.uuid)
puts "#{Time.now} #{job.uuid} removed because it is interrupted by restarting queues"
Resque::Plugins::Status::Hash.remove(job.uuid)
}
end
# Add job cleaning as a pre-requisite
task work: :clean_working_job_ids
end
require 'rake/testtask'
Rake::TestTask.new do |t|
$stdout.sync = true
$stderr.sync = true
t.pattern = 'test/**/*_test.rb'
end
namespace :test do
Rake::TestTask.new(:api){ |t| t.pattern = 'test/api/**/*_test.rb' }
Rake::TestTask.new(:model){ |t| t.pattern = 'test/models/**/*_test.rb' }
Rake::TestTask.new(:structure){ |t| t.test_files = ['test/api/**/*_test.rb', 'test/models/**/*_test.rb'] }
Rake::TestTask.new(:lib){ |t| t.pattern = 'test/lib/**/*_test.rb' }
Rake::TestTask.new(:clustering){ |t| t.pattern = 'test/**/*clustering*_test.rb' }
Rake::TestTask.new(:periodic){ |t| t.pattern = 'test/**/*scheduling*_test.rb' }
end
task clean_tmp_dir: :environment do
OptimizerWrapper.tmp_vrp_dir.cleanup
end
task clean_dump_dir: :environment do
OptimizerWrapper.dump_vrp_dir.cleanup
end
task :environment do
require './environment'
end