Sha256: 83c38a4d5c8343c07bc63c11967a9f37eb29f275cef8cc51751e3967c2e68085

Contents?: true

Size: 1.17 KB

Versions: 34

Compression:

Stored size: 1.17 KB

Contents

module Maestrano::Connector::Rails
  class Synchronization < ActiveRecord::Base
    # Keeping only 100 synchronizations per organization
    after_create :clean_synchronizations

    RUNNING_STATUS = 'RUNNING'.freeze
    ERROR_STATUS = 'ERROR'.freeze
    SUCCESS_STATUS = 'SUCCESS'.freeze

    #===================================
    # Associations
    #===================================
    belongs_to :organization

    validates :status, presence: true

    def running?
      status == RUNNING_STATUS
    end

    def error?
      status == ERROR_STATUS
    end

    def success?
      status == SUCCESS_STATUS
    end

    def self.create_running(organization)
      Synchronization.create(organization_id: organization.id, status: RUNNING_STATUS)
    end

    def set_success
      update_attributes(status: SUCCESS_STATUS)
    end

    def set_error(msg)
      update_attributes(status: ERROR_STATUS, message: msg)
    end

    def set_partial
      update_attributes(partial: true)
    end

    def clean_synchronizations
      count = organization.synchronizations.count
      organization.synchronizations.order('id ASC').limit(count - 100).destroy_all if count > 100
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
maestrano-connector-rails-2.0.2.pre.RC8 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.2.pre.RC9 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.2.pre.RC7 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.2.pre.RC6 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.2.pre.RC5 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.2.pre.RC4 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.2.pre.RC3 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.2.pre.RC2 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.2.pre.RC1 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.1 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.0 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.0.pre.RC13 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.0.pre.RC12 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.0.pre.RC11 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.0.pre.RC10 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.0.pre.RC9 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.0.pre.RC8 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-1.5.0 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.0.pre.RC7 app/models/maestrano/connector/rails/synchronization.rb
maestrano-connector-rails-2.0.0.pre.RC6 app/models/maestrano/connector/rails/synchronization.rb