Module: CanvasSync::JobBatches::Compat::Sidekiq::Web::Helpers

Defined in:
lib/canvas_sync/job_batches/compat/sidekiq/web/helpers.rb

Constant Summary collapse

VIEW_PATH =
File.expand_path("../web/views", __dir__)

Class Method Summary collapse

Class Method Details

.drain_zset(key) {|items| ... } ⇒ Object

Yields:

  • (items)


14
15
16
17
18
19
20
21
22
# File 'lib/canvas_sync/job_batches/compat/sidekiq/web/helpers.rb', line 14

def drain_zset(key)
  items, _ = CanvasSync::JobBatches::Batch.redis do |r|
    r.multi do |r|
      r.zrange(key, 0, -1)
      r.zremrangebyrank(key, 0, -1)
    end
  end
  yield items
end

.get_template(name) ⇒ Object



10
11
12
# File 'lib/canvas_sync/job_batches/compat/sidekiq/web/helpers.rb', line 10

def get_template(name)
  File.open(File.join(VIEW_PATH, "#{name}.erb")).read
end

.parse_time(time) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/canvas_sync/job_batches/compat/sidekiq/web/helpers.rb', line 29

def parse_time(time)
  case time
  when Time
    time
  when Integer, Float
    Time.at(time)
  else
    Time.parse(time.to_s)
  end
end

.safe_relative_time(time) ⇒ Object



24
25
26
27
# File 'lib/canvas_sync/job_batches/compat/sidekiq/web/helpers.rb', line 24

def safe_relative_time(time)
  time = parse_time(time)
  relative_time(time)
end