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
139
140
141
142
|
# File 'app/models/foreman_tasks/task.rb', line 139
def self.authorized_resource_name
'ForemanTasks::Task'
end
|
.search_by_generic_resource(key, operator, value) ⇒ Object
91
92
93
94
95
96
97
|
# File 'app/models/foreman_tasks/task.rb', line 91
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
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
126
|
# File 'app/models/foreman_tasks/task.rb', line 99
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
#cli_example ⇒ Object
65
66
67
|
# File 'app/models/foreman_tasks/task.rb', line 65
def cli_example
""
end
|
#humanized ⇒ Object
59
60
61
62
63
|
# File 'app/models/foreman_tasks/task.rb', line 59
def humanized
{ action: label,
input: "",
output: "" }
end
|
43
44
45
|
# File 'app/models/foreman_tasks/task.rb', line 43
def input
{}
end
|
#output ⇒ Object
47
48
49
|
# File 'app/models/foreman_tasks/task.rb', line 47
def output
{}
end
|
#owner ⇒ Object
51
52
53
|
# File 'app/models/foreman_tasks/task.rb', line 51
def owner
self.owners.first
end
|
#paused? ⇒ Boolean
79
80
81
|
# File 'app/models/foreman_tasks/task.rb', line 79
def paused?
self.state == 'paused'
end
|
#pending? ⇒ Boolean
Also known as:
pending
returns true if the task is running or waiting to be run
70
71
72
|
# File 'app/models/foreman_tasks/task.rb', line 70
def pending?
self.state != 'stopped'
end
|
#progress ⇒ Object
128
129
130
131
132
133
134
135
136
137
|
# File 'app/models/foreman_tasks/task.rb', line 128
def progress
case self.state.to_s
when "running", "paused"
0.5
when "stopped"
1
else
0
end
end
|
#resumable? ⇒ Boolean
75
76
77
|
# File 'app/models/foreman_tasks/task.rb', line 75
def resumable?
false
end
|
#self_and_parents ⇒ Object
83
84
85
86
87
88
89
|
# File 'app/models/foreman_tasks/task.rb', line 83
def self_and_parents
[self].tap do |ret|
if parent_task
ret.concat(parent_task.self_and_parents)
end
end
end
|
#username ⇒ Object
55
56
57
|
# File 'app/models/foreman_tasks/task.rb', line 55
def username
self.owner.try(:login)
end
|