aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/concerns/job_concern.rb
blob: b0c26baa9789338b636213101a3444fe35c852f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module JobConcern
  extend ActiveSupport::Concern
  extend ActiveModel::Naming
  extend ActiveModel::Translation
  include ActiveModel::Model
  
  included do    
    attr_reader :datas
  end

  module ClassMethods
  end

  def links
    {}.tap do |links|
      datas.links.each do |link|
        links[link["rel"]] = link["href"] 
      end    
    end
  end

  def started?
    status == "started"
  end

  def aborted?
    status == "aborted"
  end

  def cache_key
   "#{id}_#{status}"
  end

  def cache_expiration
    started? ? 10.seconds : 1.hours 
  end
  
  def id
    datas.id
  end

  def status
    datas.status.downcase
  end

  def referential_name
    datas.referential
  end
  
  def name
    datas.action_parameters.name
  end
  
  def user_name    
    datas.action_parameters.user_name
  end
  
  def created_at    
    Time.at(datas.created.to_i / 1000) if datas.created
  end

  def updated_at
    Time.at(datas.updated.to_i / 1000) if datas.updated
  end

  def format
    datas.type
  end
  
end