Module: JobStatus::Status

Defined in:
lib/job_status/status.rb

Overview

Status Module, retrieve the status information from the store

Class Method Summary collapse

Class Method Details

.at(job_id) ⇒ Integer

Get the current progress from the store

Parameters:

  • job_id (String)

    ActiveJob ID to query the store for

Returns:

  • (Integer)

    at Value stored by the work for the progress



24
25
26
27
# File 'lib/job_status/status.rb', line 24

def self.at(job_id)
  status = JobStatus.store.fetch(job_id)
  status ? status[:at] : nil
end

.get_all(job_id) ⇒ Object

Get the All Data from the store

Parameters:

  • job_id (String)

    ActiveJob ID to query the store for

Returns:

  • returns all information held in the store for the job_id



67
68
69
70
# File 'lib/job_status/status.rb', line 67

def self.get_all(job_id)
  status = JobStatus.store.fetch(job_id)
  status ? status : nil
end

.get_status(job_id) ⇒ Symbol

Get the Status from the store

Parameters:

  • job_id (String)

    ActiveJob ID to query the store for

Returns:

  • (Symbol)

    status Returns status possible valuds :queued, :working, :completed



13
14
15
16
# File 'lib/job_status/status.rb', line 13

def self.get_status(job_id)
  status = JobStatus.store.fetch(job_id)
  status ? status[:status] : nil
end

.percentage(job_id) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/job_status/status.rb', line 51

def self.percentage(job_id)
  status = JobStatus.store.fetch(job_id)
  percent = nil
  puts status
  if status
    percent = 100.0 / (status[:total].to_f / status[:at])
  end
  return percent
end

.store(job_id) ⇒ Object

Get the stored data from the store

Parameters:

  • job_id (String)

    ActiveJob ID to query the store for

Returns:

  • returns the stored data, could be any serializable object



35
36
37
38
# File 'lib/job_status/status.rb', line 35

def self.store(job_id)
  status = JobStatus.store.fetch(job_id)
  status ? status[:store] : nil
end

.total(job_id) ⇒ Integer

Get the Total from the store

Parameters:

  • job_id (String)

    ActiveJob ID to query the store for

Returns:

  • (Integer)

    total Returns total used for the percentage



46
47
48
49
# File 'lib/job_status/status.rb', line 46

def self.total(job_id)
  status = JobStatus.store.fetch(job_id)
  status ? status[:total] : nil
end