Sha256: 14bf6e35e4c3c2685dcb6b3797b06d32c2570d37ffdc2fc7428f3ceccb1dcc9d

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

module Coupler
  module Models
    class Job < Sequel::Model
      include CommonModel

      many_to_one :resource
      many_to_one :scenario

      def percent_completed
        total > 0 ? completed * 100 / total : 0
      end

      def execute
        Logger.instance.info("Starting job #{id} (#{name})")
        case name
        when 'transform'
          update(:status => 'running', :started_at => Time.now, :total => resource.source_dataset_count)

          new_status = 'failed'
          begin
            resource.transform! { |n| update(:completed => completed + n) }
            new_status = 'done'
          ensure
            update(:status => new_status, :completed_at => Time.now)
          end

        when 'run_scenario'
          update(:status => 'running', :started_at => Time.now)

          new_status = 'failed'
          begin
            scenario.run!
            new_status = 'done'
          ensure
            update(:status => new_status, :completed_at => Time.now)
          end
        end
        Logger.instance.info("Job #{id} (#{name}) finished")
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
coupler-0.0.6-java lib/coupler/models/job.rb
coupler-0.0.4-java lib/coupler/models/job.rb
coupler-0.0.3-java lib/coupler/models/job.rb
coupler-0.0.2-java lib/coupler/models/job.rb
coupler-0.0.1-java lib/coupler/models/job.rb