-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show progress of current orchestration task for repos
- Loading branch information
Showing
15 changed files
with
167 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class DynflowExecutionPlan < ActiveRecord::Base | ||
|
||
self.table_name = 'dynflow_execution_plans' | ||
self.primary_key = :uuid | ||
|
||
def self.create_or_update(*args) | ||
raise "Read only model - it's managed by Dynflow persistence layer" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class DynflowLock < ActiveRecord::Base | ||
attr_accessible :resource_id, :resource_type, :uuid | ||
|
||
belongs_to :dynflow_execution_plan, | ||
class_name: 'DynflowExecutionPlan', | ||
foreign_key: :uuid | ||
belongs_to :dynflow_task, foreign_key: :uuid | ||
belongs_to :resource, polymorphic: true | ||
|
||
scope :active, -> do | ||
includes(:dynflow_execution_plan) | ||
.where('dynflow_execution_plans.state != ?', :stopped) | ||
end | ||
|
||
scope :inactive, -> do | ||
includes(:dynflow_execution_plan) | ||
.where('dynflow_execution_plans.state = ?', :stopped) | ||
end | ||
|
||
scope :for_model, -> model do | ||
where(resource_id: model.id, resource_type: model.class.name) | ||
end | ||
|
||
def self.active_lock(model) | ||
active.for_model(model).first | ||
end | ||
|
||
def self.lock!(uuid, model) | ||
if model.new_record? | ||
raise "Model #{model} has to be saved before locking it" | ||
end | ||
if lock = DynflowLock.active_lock(model) | ||
raise "Model #{model} has already been locked by task #{lock.uuid}" | ||
end | ||
|
||
DynflowLock.create!(:uuid => uuid) do |new_lock| | ||
new_lock.resource = model | ||
end | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class DynflowTask < ActiveRecord::Base | ||
|
||
self.primary_key = :uuid | ||
|
||
attr_accessible :action, :organization_id, :user_id, :uuid | ||
|
||
belongs_to :dynflow_execution_plan, | ||
class_name: 'DynflowExecutionPlan', | ||
foreign_key: :uuid | ||
has_many :dynflow_locks, foreign_key: :uuid | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateDynflowTasks < ActiveRecord::Migration | ||
def change | ||
create_table :dynflow_tasks, :id => false do |t| | ||
t.string :uuid, index: true | ||
t.string :action, index: true | ||
t.integer :user_id, index: true | ||
t.integer :organization_id, index: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateDynflowLocks < ActiveRecord::Migration | ||
def change | ||
create_table :dynflow_locks do |t| | ||
t.string :uuid, index: true | ||
t.string :resource_type, index: true | ||
t.integer :resource_id, index: true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Orchestrate | ||
module Helpers | ||
|
||
# Helpers for remote actions | ||
# wraps the plan/run/finalize methods to include the info about the user | ||
# that triggered the action. | ||
module Lock | ||
|
||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
|
||
module ClassMethods | ||
|
||
def generate_phase(phase_module) | ||
super.tap do |phase_class| | ||
if phase_module == Dynflow::Action::PlanPhase | ||
phase_class.send(:include, PlanMethods) | ||
end | ||
end | ||
end | ||
|
||
end | ||
|
||
module PlanMethods | ||
|
||
def lock(model) | ||
DynflowLock.lock!(execution_plan_id, model) | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters