[PATCH] added new attribute checked_at to instance and changed dbomatic to iterate instances using this attribute
Jan Provaznik
jprovazn at redhat.com
Tue Sep 4 12:23:50 UTC 2012
On 09/04/2012 10:21 AM, Tomáš Hrčka wrote:
> ---
> src/db/migrate/20120904073451_add_checked_at_to_instance.rb | 9 +++++++++
> src/dbomatic/dbomatic | 3 ++-
> 2 files changed, 11 insertions(+), 1 deletion(-)
> create mode 100644 src/db/migrate/20120904073451_add_checked_at_to_instance.rb
>
> diff --git a/src/db/migrate/20120904073451_add_checked_at_to_instance.rb b/src/db/migrate/20120904073451_add_checked_at_to_instance.rb
> new file mode 100644
> index 0000000..b60f4e2
> --- /dev/null
> +++ b/src/db/migrate/20120904073451_add_checked_at_to_instance.rb
> @@ -0,0 +1,9 @@
> +class AddCheckedAtToInstance < ActiveRecord::Migration
> + def self.up
> + add_column :instances, :checked_at, :datetime
> + end
> +
> + def self.down
> + remove_column :instances, :checked_at
> + end
> +end
> diff --git a/src/dbomatic/dbomatic b/src/dbomatic/dbomatic
> index 76fadf6..d375f40 100755
> --- a/src/dbomatic/dbomatic
> +++ b/src/dbomatic/dbomatic
> @@ -189,7 +189,7 @@ end
> def check_one_account(account)
> connection = account.connect
>
> - account.instances.each do |instance|
> + account.instances.order("checked_at ASC").each do |instance|
^ with this ordering, instances with nil checked_at value will be after
any not nil time (at least on postgres) - we want to prioritize nil
values first
> # optimization; right now we ignore instances that are in the STOPPED, NEW, or CREATE_FAILED states.
> # when we get to stateful instances, this will need to change
> unless [Instance::STATE_NEW, Instance::STATE_STOPPED, Instance::STATE_CREATE_FAILED].include?(instance.state)
> @@ -201,6 +201,7 @@ def check_one_account(account)
> end
>
> if api_instance
> + instance.update_attribute(:checked_at,Time.now)
this check should be set no matter if api_instance is set or not (it
should be set for vanished instances too), it would be better to put it
before begin-rescue block which tries to set api_instance.
> DBomaticLogger.instance.info("updating instance state for #{instance.name}: #{instance.external_key}")
> instance.state = Taskomatic.dcloud_to_instance_state(api_instance.state)
>
>
More information about the aeolus-devel
mailing list