-
Notifications
You must be signed in to change notification settings - Fork 1
/
db_func.rb
125 lines (96 loc) · 3.22 KB
/
db_func.rb
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
module DQCCdb
# config
require 'config'
include DQCCconfig
# for database connectivity
require 'mongoid'
Mongoid.configure do |config|
name = DQCCconfig.db_dqor_name
host = DQCCconfig.db_dqor_host
config.master = Mongo::Connection.new.db(name)
end
class Job
include Mongoid::Document
store_in "drqueue_jobs"
field :name, :type => String
field :startframe, :type => Integer
field :endframe, :type => Integer
field :blocksize, :type => Integer
field :renderer, :type => String
field :scenefile, :type => String
field :retries, :type => Integer
field :owner, :type => String
field :created_with, :type => String
field :rendertype, :type => String
field :send_email, :type => Boolean
field :email_recipients, :type => String
field :file_provider, :type => String
end
class User
include Mongoid::Document
store_in "drqueue_users"
field :name, :type => String
field :admin, :type => Boolean, :default => false
field :beta_user, :type => Boolean, :default => true
end
class Rendersession
include Mongoid::Document
store_in "cloudcontrol_rendersessions"
field :user, :type => String
field :num_slaves, :type => Integer
field :run_time, :type => Integer
field :vm_type, :type => String, :default => 't1.micro'
field :costs, :type => Float
field :active, :type => Boolean
field :paypal_token, :type => String
field :paypal_payer_id, :type => String
field :paid_at, :type => DateTime
field :time_passed, :type => Integer, :default => 0
field :start_timestamp, :type => Integer, :default => 0
field :stop_timestamp, :type => Integer, :default => 0
field :overall_time_passed, :type => Integer, :default => 0
end
# # return list of all jobs known to DQOR
# def fetch_job_list
# puts "DEBUG: fetch_job_list()"
#
# return Job.find(:all)
# end
# return list of all rendersessions
def fetch_rendersession_list
puts "DEBUG: fetch_rendersession_list()"
# fetch all paid, owned and active rendersessions
sessions = Rendersession.all(:conditions => { :paid_at.ne => nil, :paypal_payer_id.ne => nil, :active => true })
puts "DEBUG: Rendersessions found: "+sessions.length.to_s
return sessions
end
# # return info about job owner
# def fetch_user_data(job_id)
# puts "DEBUG: fetch_user_data("+job_id.to_s+")"
#
# job = Job.find(job_id)
# return User.find(job.owner)
# end
# return list of jobs belonging to a rendersession
def fetch_rendersession_job_list(rendersession_id)
puts "DEBUG: fetch_rendersession_job_list("+rendersession_id.to_s+")"
rs = Rendersession.find(rendersession_id)
return Job.all(:conditions => {:owner => rs.user})
end
# # return active rendersessions of user
# def find_rendersession(user_id)
# puts "DEBUG: find_rendersession(" + user_id + ")"
#
# active_rs = nil
# Rendersession.all(:conditions => { :paid_at.ne => nil, :paypal_payer_id.ne => nil, :user => user_id }).each do |rs|
# # check if there is time left
# if rs.time_passed < (rs.run_time * 3600 + rs.start_timestamp)
# # return only one session
# active_rs = rs
# break
# end
# end
#
# return active_rs
# end
end