-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathjob_status.rake
More file actions
50 lines (48 loc) · 1.16 KB
/
job_status.rake
File metadata and controls
50 lines (48 loc) · 1.16 KB
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
namespace :job_status do
desc "Closing past due jobs..."
task :close => :environment do
people = Hash.new
Job.all.where.not(status: 1).each do |j|
if j.user_id == nil
j.update_column(:status, 1)
elsif j.latest_start_date < (Date.today - 365)
begin
poster = User.find(j.user_id)
if people[poster] == nil
people[poster] = Array.new
end
people[poster].push(j)
#j.update_column(:status, 1)
rescue
puts j.user_id
end
end
end
people.each do |k, v|
# Do Stuff with |User, [Jobs]|
v.each do |j|
# Do Stuff with |Jobs|
end
end
end
desc "init job status..."
task :init => :environment do
Job.all.where(status: nil).each do |j|
if j.latest_start_date < Time.now
j.update_column(:status, 1)
else
j.update_column(:status, 0)
end
end
end
desc "Checking How Many Old Jobs..."
task :count => :environment do
count = 0
Job.all.where.not(status: 1).each do |j|
if j.latest_start_date < (Date.today - 365)
count += 1
end
end
p count
end
end