Scott Seago
2009-May-13 20:32 UTC
[Ovirt-devel] [PATCH server] set state to STATE_QUEUED in the task constructor since every XXXTask.new call in the codebase set the state to the same QUEUED state.
Signed-off-by: Scott Seago <sseago at redhat.com> --- src/app/models/task.rb | 5 +++++ src/app/models/vm.rb | 3 +-- src/app/services/host_service.rb | 3 +-- src/app/services/storage_pool_service.rb | 3 +-- src/app/services/storage_volume_service.rb | 6 ++---- src/app/services/vm_service.rb | 15 +++++---------- 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/app/models/task.rb b/src/app/models/task.rb index d16f076..70ec9a6 100644 --- a/src/app/models/task.rb +++ b/src/app/models/task.rb @@ -69,6 +69,11 @@ class Task < ActiveRecord::Base ["Canceled", Task::STATE_CANCELED, "break"], ["All States", ""]] + def initialize(params) + super + self.state = STATE_QUEUED unless self.state + end + def cancel self[:state] = STATE_CANCELED save! diff --git a/src/app/models/vm.rb b/src/app/models/vm.rb index f2e53ed..e7a4e4d 100644 --- a/src/app/models/vm.rb +++ b/src/app/models/vm.rb @@ -301,8 +301,7 @@ class Vm < ActiveRecord::Base task = VmTask.new({ :user => user, :task_target => self, :action => action, - :args => data, - :state => Task::STATE_QUEUED}) + :args => data}) task.save! return true end diff --git a/src/app/services/host_service.rb b/src/app/services/host_service.rb index 074d830..4ace9fb 100644 --- a/src/app/services/host_service.rb +++ b/src/app/services/host_service.rb @@ -103,8 +103,7 @@ module HostService Host.transaction do task = HostTask.new({ :user => get_login_user, :task_target => @host, - :action => HostTask::ACTION_CLEAR_VMS, - :state => Task::STATE_QUEUED}) + :action => HostTask::ACTION_CLEAR_VMS}) task.save! @host.is_disabled = true @host.save! diff --git a/src/app/services/storage_pool_service.rb b/src/app/services/storage_pool_service.rb index dd36304..ba7f938 100644 --- a/src/app/services/storage_pool_service.rb +++ b/src/app/services/storage_pool_service.rb @@ -141,8 +141,7 @@ module StoragePoolService def insert_refresh_task @task = StorageTask.new({ :user => @user, :task_target => @storage_pool, - :action => StorageTask::ACTION_REFRESH_POOL, - :state => Task::STATE_QUEUED}) + :action => StorageTask::ACTION_REFRESH_POOL}) @task.save! end diff --git a/src/app/services/storage_volume_service.rb b/src/app/services/storage_volume_service.rb index 6d338a5..a18fe55 100644 --- a/src/app/services/storage_volume_service.rb +++ b/src/app/services/storage_volume_service.rb @@ -98,8 +98,7 @@ module StorageVolumeService @storage_volume.save! @task = StorageVolumeTask.new({ :user => @user, :task_target => @storage_volume, - :action => StorageVolumeTask::ACTION_CREATE_VOLUME, - :state => Task::STATE_QUEUED}) + :action => StorageVolumeTask::ACTION_CREATE_VOLUME}) @task.save! end return "Storage Volume was successfully created." @@ -128,8 +127,7 @@ module StorageVolumeService @storage_volume.save! @task = StorageVolumeTask.new({ :user => @user, :task_target => @storage_volume, - :action => StorageVolumeTask::ACTION_DELETE_VOLUME, - :state => Task::STATE_QUEUED}) + :action => StorageVolumeTask::ACTION_DELETE_VOLUME}) @task.save! end return "Storage Volume #{name} deletion was successfully queued." diff --git a/src/app/services/vm_service.rb b/src/app/services/vm_service.rb index ff1a919..fb58b51 100644 --- a/src/app/services/vm_service.rb +++ b/src/app/services/vm_service.rb @@ -82,15 +82,13 @@ module VmService vm_provision @task = VmTask.new({ :user => @user, :task_target => @vm, - :action => VmTask::ACTION_CREATE_VM, - :state => Task::STATE_QUEUED}) + :action => VmTask::ACTION_CREATE_VM}) @task.save! if start_now if @vm.get_action_list.include?(VmTask::ACTION_START_VM) @task = VmTask.new({ :user => @user, :task_target => @vm, - :action => VmTask::ACTION_START_VM, - :state => Task::STATE_QUEUED}) + :action => VmTask::ACTION_START_VM}) @task.save! alert += " VM Start action queued." else @@ -139,8 +137,7 @@ module VmService if @vm.get_action_list.include?(VmTask::ACTION_START_VM) @task = VmTask.new({ :user => @user, :task_target => @vm, - :action => VmTask::ACTION_START_VM, - :state => Task::STATE_QUEUED}) + :action => VmTask::ACTION_START_VM}) @task.save! alert += " VM Start action queued." else @@ -150,13 +147,11 @@ module VmService if @vm.get_action_list.include?(VmTask::ACTION_SHUTDOWN_VM) @task = VmTask.new({ :user => @user, :task_target => @vm, - :action => VmTask::ACTION_SHUTDOWN_VM, - :state => Task::STATE_QUEUED}) + :action => VmTask::ACTION_SHUTDOWN_VM}) @task.save! @task = VmTask.new({ :user => @user, :task_target => @vm, - :action => VmTask::ACTION_START_VM, - :state => Task::STATE_QUEUED}) + :action => VmTask::ACTION_START_VM}) @task.save! alert += " VM Restart action queued." else -- 1.6.0.6