Class: ForemanTasks::Task
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ForemanTasks::Task
show all
- Includes:
- Authorizable
- Defined in:
- app/models/foreman_tasks/task.rb
Defined Under Namespace
Classes: DynflowTask, StatusExplicator, Summarizer, TaskCancelledException
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.authorized_resource_name ⇒ Object
152
153
154
155
|
# File 'app/models/foreman_tasks/task.rb', line 152
def self.authorized_resource_name
'ForemanTasks::Task'
end
|
.search_by_generic_resource(key, operator, value) ⇒ Object
104
105
106
107
108
109
110
|
# File 'app/models/foreman_tasks/task.rb', line 104
def self.search_by_generic_resource(key, operator, value)
key = "resource_type" if key.blank?
key_name = self.connection.quote_column_name(key.sub(/^.*\./,''))
condition = sanitize_sql_for_conditions(["foreman_tasks_locks.#{key_name} #{operator} ?", value])
return {:conditions => condition, :joins => :locks }
end
|
.search_by_owner(key, operator, value) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'app/models/foreman_tasks/task.rb', line 112
def self.search_by_owner(key, operator, value)
return { :conditions => '0 = 1' } if value == 'current_user' && User.current.nil?
key_name = self.connection.quote_column_name(key.sub(/^.*\./,''))
joins = <<-SQL
INNER JOIN foreman_tasks_locks AS foreman_tasks_locks_owner
ON (foreman_tasks_locks_owner.task_id = foreman_tasks_tasks.id AND
foreman_tasks_locks_owner.resource_type = 'User' AND
foreman_tasks_locks_owner.name = '#{Lock::OWNER_LOCK_NAME}')
SQL
if key !~ /\.id\Z/
joins << <<-SQL
INNER JOIN users
ON (users.id = foreman_tasks_locks_owner.resource_id)
SQL
end
condition = if key.blank?
sanitize_sql_for_conditions(["users.login #{operator} ? or users.firstname #{operator} ? ", value, value])
elsif key =~ /\.id\Z/
if value == 'current_user'
value = User.current.id
end
sanitize_sql_for_conditions(["foreman_tasks_locks_owner.resource_id #{operator} ?", value])
else
sanitize_sql_for_conditions(["users.#{key_name} #{operator} ?", value])
end
return {:conditions => condition, :joins => joins }
end
|
Instance Method Details
#add_missing_task_groups(groups) ⇒ Object
157
158
159
160
|
# File 'app/models/foreman_tasks/task.rb', line 157
def add_missing_task_groups(groups)
groups = [groups] unless groups.is_a? Array
(groups - task_groups).each { |group| task_groups << group }
end
|
#cli_example ⇒ Object
78
79
80
|
# File 'app/models/foreman_tasks/task.rb', line 78
def cli_example
""
end
|
#humanized ⇒ Object
72
73
74
75
76
|
# File 'app/models/foreman_tasks/task.rb', line 72
def humanized
{ action: label,
input: "",
output: "" }
end
|
56
57
58
|
# File 'app/models/foreman_tasks/task.rb', line 56
def input
{}
end
|
#output ⇒ Object
60
61
62
|
# File 'app/models/foreman_tasks/task.rb', line 60
def output
{}
end
|
#owner ⇒ Object
64
65
66
|
# File 'app/models/foreman_tasks/task.rb', line 64
def owner
self.owners.first
end
|
#paused? ⇒ Boolean
92
93
94
|
# File 'app/models/foreman_tasks/task.rb', line 92
def paused?
self.state == 'paused'
end
|
#pending? ⇒ Boolean
Also known as:
pending
returns true if the task is running or waiting to be run
83
84
85
|
# File 'app/models/foreman_tasks/task.rb', line 83
def pending?
self.state != 'stopped'
end
|
#progress ⇒ Object
141
142
143
144
145
146
147
148
149
150
|
# File 'app/models/foreman_tasks/task.rb', line 141
def progress
case self.state.to_s
when "running", "paused"
0.5
when "stopped"
1
else
0
end
end
|
#resumable? ⇒ Boolean
88
89
90
|
# File 'app/models/foreman_tasks/task.rb', line 88
def resumable?
false
end
|
#self_and_parents ⇒ Object
96
97
98
99
100
101
102
|
# File 'app/models/foreman_tasks/task.rb', line 96
def self_and_parents
[self].tap do |ret|
if parent_task
ret.concat(parent_task.self_and_parents)
end
end
end
|
#username ⇒ Object
68
69
70
|
# File 'app/models/foreman_tasks/task.rb', line 68
def username
self.owner.try(:login)
end
|