module CanvasSync module JobBatches class Batch class Status attr_reader :bid def initialize(bid) @bid = bid end def join raise "Not supported" end def pending Batch.redis { |r| r.hget("BID-#{bid}", 'pending') }.to_i end def failures Batch.redis { |r| r.scard("BID-#{bid}-failed") }.to_i end def created_at Batch.redis { |r| r.hget("BID-#{bid}", 'created_at') } end def total Batch.redis { |r| r.hget("BID-#{bid}", 'total') }.to_i end def parent_bid Batch.redis { |r| r.hget("BID-#{bid}", "parent_bid") } end def failure_info Batch.redis { |r| r.smembers("BID-#{bid}-failed") } || [] end def complete? 'true' == Batch.redis { |r| r.hget("BID-#{bid}", 'complete') } end def success? 'true' == Batch.redis { |r| r.hget("BID-#{bid}", 'success') } end def child_count Batch.redis { |r| r.hget("BID-#{bid}", 'children') }.to_i end def completed_children_count Batch.redis { |r| r.scard("BID-#{bid}-batches-complete") }.to_i end def successful_children_count Batch.redis { |r| r.scard("BID-#{bid}-batches-success") }.to_i end def failed_children_count Batch.redis { |r| r.scard("BID-#{bid}-batches-failed") }.to_i end def data { bid: bid, total: total, failures: failures, pending: pending, created_at: created_at, complete: complete?, success: success?, failure_info: failure_info, parent_bid: parent_bid, child_count: child_count, completed_children_count: completed_children_count, successful_children_count: successful_children_count, failed_children_count: failed_children_count, } end end end end end