foreman-tasks 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,12 @@
|
|
1
1
|
module ForemanTasks
|
2
2
|
class Lock < ActiveRecord::Base
|
3
3
|
|
4
|
-
LINK_LOCK_NAME
|
4
|
+
LINK_LOCK_NAME = :link_resource
|
5
5
|
OWNER_LOCK_NAME = :task_owner
|
6
6
|
|
7
7
|
# not really intedet to be created in database, but it's used for
|
8
8
|
# explicitly stating that the all the locks for resource should be used
|
9
|
-
ALL_LOCK_NAME
|
9
|
+
ALL_LOCK_NAME = :all
|
10
10
|
|
11
11
|
RESERVED_LOCK_NAMES = [LINK_LOCK_NAME, OWNER_LOCK_NAME, ALL_LOCK_NAME]
|
12
12
|
|
@@ -31,25 +31,25 @@ module ForemanTasks
|
|
31
31
|
|
32
32
|
validate do
|
33
33
|
unless available?
|
34
|
-
raise LockConflict.new(self,
|
34
|
+
raise LockConflict.new(self, colliding_locks)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
# returns true if it's possible to aquire this kind of lock
|
39
39
|
def available?
|
40
|
-
|
40
|
+
not colliding_locks.any?
|
41
41
|
end
|
42
42
|
|
43
|
-
# returns a scope of the locks
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
# returns a scope of the locks colliding with this one
|
44
|
+
def colliding_locks
|
45
|
+
colliding_locks_scope = Lock.active.where(Lock.arel_table[:task_id].not_eq(task_id))
|
46
|
+
colliding_locks_scope = colliding_locks_scope.where(name: name,
|
47
|
+
resource_id: resource_id,
|
48
|
+
resource_type: resource_type)
|
49
49
|
unless self.exclusive?
|
50
|
-
|
50
|
+
colliding_locks_scope = colliding_locks_scope.where(:exclusive => true)
|
51
51
|
end
|
52
|
-
return
|
52
|
+
return colliding_locks_scope
|
53
53
|
end
|
54
54
|
|
55
55
|
class << self
|
@@ -63,7 +63,7 @@ module ForemanTasks
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def exclusive?(resource)
|
66
|
-
build_exclusive_locks(resource).all?(
|
66
|
+
build_exclusive_locks(resource).all?(&:available?)
|
67
67
|
end
|
68
68
|
|
69
69
|
|
@@ -82,10 +82,19 @@ module ForemanTasks
|
|
82
82
|
build_locks(resource, lock_names, uuid).each(&:save!)
|
83
83
|
end
|
84
84
|
|
85
|
-
def
|
85
|
+
def lockable?(resource, uuid, *lock_names)
|
86
86
|
build_locks(resource, lock_names, uuid).all?(&:available?)
|
87
87
|
end
|
88
88
|
|
89
|
+
def locked?(resource, uuid, *lock_names)
|
90
|
+
not lockable?(resource, uuid, *lock_names)
|
91
|
+
end
|
92
|
+
|
93
|
+
def colliding_locks(resource, uuid, *lock_names)
|
94
|
+
build_locks(resource, lock_names, uuid).
|
95
|
+
inject([]) { |collisions, lock| collisions.concat lock.colliding_locks.to_a }
|
96
|
+
end
|
97
|
+
|
89
98
|
# Assigns the resource to the task to easily track the task in context of
|
90
99
|
# the resource. This doesn't prevent other actions to lock the resource
|
91
100
|
# and should be used only for actions that tolerate other actions to be
|
@@ -111,7 +120,7 @@ module ForemanTasks
|
|
111
120
|
def all_lock_names(resource, include_links = false)
|
112
121
|
lock_names = []
|
113
122
|
if resource.class.respond_to?(:available_locks) &&
|
114
|
-
|
123
|
+
resource.class.available_locks.any?
|
115
124
|
lock_names.concat(resource.class.available_locks)
|
116
125
|
else
|
117
126
|
raise "The resource #{resource.class.name} doesn't define any available lock"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Setting::ForemanTasks < Setting
|
2
|
+
|
3
|
+
def self.load_defaults
|
4
|
+
# Check the table exists
|
5
|
+
return unless super
|
6
|
+
|
7
|
+
self.transaction do
|
8
|
+
[
|
9
|
+
self.set('dynflow_enable_console', N_("Enable the dynflow console (/foreman_tasks/dynflow) for debugging"), false),
|
10
|
+
].each { |s| self.create! s.update(:category => "Setting::ForemanTasks")}
|
11
|
+
end
|
12
|
+
|
13
|
+
true
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -1,3 +1,18 @@
|
|
1
|
+
<script>
|
2
|
+
$(document).ready(function () {
|
3
|
+
var reload = function () {
|
4
|
+
$.ajax({
|
5
|
+
url: "",
|
6
|
+
context: document.body,
|
7
|
+
success: function (s, x) {
|
8
|
+
$(this).html(s);
|
9
|
+
}
|
10
|
+
});
|
11
|
+
};
|
12
|
+
setTimeout(reload, 5000);
|
13
|
+
});
|
14
|
+
</script>
|
15
|
+
|
1
16
|
<div class="task-details">
|
2
17
|
<%= form_for @task, :url => "#" do %>
|
3
18
|
<div>
|
@@ -81,8 +81,9 @@ module ForemanTasks
|
|
81
81
|
def web_console
|
82
82
|
::Dynflow::WebConsole.setup do
|
83
83
|
before do
|
84
|
-
|
85
|
-
|
84
|
+
if !Setting[:dynflow_enable_console]
|
85
|
+
redirect('dashboard')
|
86
|
+
end
|
86
87
|
end
|
87
88
|
|
88
89
|
set(:world) { ForemanTasks.dynflow.world }
|
data/lib/foreman_tasks/engine.rb
CHANGED
@@ -2,6 +2,10 @@ module ForemanTasks
|
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
engine_name "foreman_tasks"
|
4
4
|
|
5
|
+
initializer 'foreman_tasks.load_default_settings', :before => :load_config_initializers do
|
6
|
+
require_dependency File.expand_path('../../../app/models/setting/foreman_tasks.rb', __FILE__) if (Setting.table_exists? rescue(false))
|
7
|
+
end
|
8
|
+
|
5
9
|
initializer 'foreman_tasks.register_plugin', :after => :finisher_hook do |app|
|
6
10
|
Foreman::Plugin.register :"foreman-tasks" do
|
7
11
|
requires_foreman '> 1.3'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- app/models/foreman_tasks/task/dynflow_task.rb
|
150
150
|
- app/models/foreman_tasks/lock.rb
|
151
151
|
- app/models/foreman_tasks/task.rb
|
152
|
+
- app/models/setting/foreman_tasks.rb
|
152
153
|
- bin/dynflow-executor
|
153
154
|
- bin/foreman-tasks
|
154
155
|
- config/routes.rb
|