[ARVADOS] updated: ccff8ce154b393512dd4b563853f63a9abeefba4

git at public.curoverse.com git at public.curoverse.com
Mon Sep 22 15:13:53 EDT 2014


Summary of changes:
 .../db/migrate/20140918153705_add_state_to_job.rb   | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

       via  ccff8ce154b393512dd4b563853f63a9abeefba4 (commit)
      from  148306afed19fc9138a04bcf161d8f24d83b2ac0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit ccff8ce154b393512dd4b563853f63a9abeefba4
Author: Tom Clegg <tom at curoverse.com>
Date:   Mon Sep 22 15:13:12 2014 -0400

    3898: Populate state column using SQL transaction instead of load/save N times.

diff --git a/services/api/db/migrate/20140918153705_add_state_to_job.rb b/services/api/db/migrate/20140918153705_add_state_to_job.rb
index 7e14ea8..7b595a3 100644
--- a/services/api/db/migrate/20140918153705_add_state_to_job.rb
+++ b/services/api/db/migrate/20140918153705_add_state_to_job.rb
@@ -2,23 +2,18 @@ class AddStateToJob < ActiveRecord::Migration
   include CurrentApiClient
 
   def up
-    if !column_exists?(:jobs, :state)
+    ActiveRecord::Base.transaction do
       add_column :jobs, :state, :string
-    end
-
-    Job.reset_column_information
-
-    act_as_system_user do
-      Job.all.each do |job|
-        # before_save filter will set state based on job status
-        job.save!
-      end
+      Job.reset_column_information
+      Job.update_all({state: 'Cancelled'}, ['state is null and cancelled_at is not null'])
+      Job.update_all({state: 'Failed'}, ['state is null and success = ?', false])
+      Job.update_all({state: 'Complete'}, ['state is null and success = ?', true])
+      Job.update_all({state: 'Running'}, ['state is null and running = ?', true])
+      Job.update_all({state: 'Queued'}, ['state is null'])
     end
   end
 
   def down
-    if column_exists?(:jobs, :state)
-      remove_column :jobs, :state
-    end
+    remove_column :jobs, :state
   end
 end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list