Class: Job

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Altria::Proprietary
Defined in:
app/models/job.rb

Defined Under Namespace

Classes: ScriptNotFound

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Altria::Proprietary

#update_properties

Class Method Details

.after_enqueue(&block) ⇒ Object



39
40
41
# File 'app/models/job.rb', line 39

def after_enqueue(&block)
  after_enqueues << block
end

.after_enqueuesObject



43
44
45
# File 'app/models/job.rb', line 43

def after_enqueues
  @after_enqueues ||= []
end

.after_execute(&block) ⇒ Object



55
56
57
# File 'app/models/job.rb', line 55

def after_execute(&block)
  after_executes << block
end

.after_executesObject



59
60
61
# File 'app/models/job.rb', line 59

def after_executes
  @after_executes ||= []
end

.before_enqueue(&block) ⇒ Object



31
32
33
# File 'app/models/job.rb', line 31

def before_enqueue(&block)
  before_enqueues << block
end

.before_enqueuesObject



35
36
37
# File 'app/models/job.rb', line 35

def before_enqueues
  @before_enqueues ||= []
end

.before_execute(&block) ⇒ Object



47
48
49
# File 'app/models/job.rb', line 47

def before_execute(&block)
  before_executes << block
end

.before_executesObject



51
52
53
# File 'app/models/job.rb', line 51

def before_executes
  @before_executes ||= []
end

.create_with_properties(params) ⇒ Object



23
24
25
# File 'app/models/job.rb', line 23

def create_with_properties(params)
  new.update_attributes_with_properties(params)
end

.scheduledObject



27
28
29
# File 'app/models/job.rb', line 27

def scheduled
  select(&:scheduled?)
end

Instance Method Details

#current_buildObject



84
85
86
# File 'app/models/job.rb', line 84

def current_build
  builds.running.latest
end

#enqueueObject



72
73
74
# File 'app/models/job.rb', line 72

def enqueue
  builds.create.tap(&:enqueue).tap { execute_after_enqueues }
end

#enqueue_with_before_enqueuesObject



76
77
78
# File 'app/models/job.rb', line 76

def enqueue_with_before_enqueues
  enqueue if execute_before_enqueues
end

#executeObject



105
106
107
108
# File 'app/models/job.rb', line 105

def execute
  execute_before_executes
  execute_without_before_executes.tap { execute_after_executes }
end

#last_finished_buildObject



88
89
90
# File 'app/models/job.rb', line 88

def last_finished_build
  builds.finished.order(:finished_at).last
end

#runObject



64
65
66
# File 'app/models/job.rb', line 64

def run
  script ? execute : raise_script_not_found
end

#schedulerObject



68
69
70
# File 'app/models/job.rb', line 68

def scheduler
  Altria::Scheduler.new(schedule) if schedule.present?
end

#status_nameObject



80
81
82
# File 'app/models/job.rb', line 80

def status_name
  last_finished_build.try(:status_name) || "unfinished"
end

#update_attributes_with_properties(params) ⇒ Object



92
93
94
95
# File 'app/models/job.rb', line 92

def update_attributes_with_properties(params)
  params.slice(:name, *self.class.property_names).each {|key, value| send("#{key}=", value) }
  tap(&:save)
end

#workspaceObject



97
98
99
# File 'app/models/job.rb', line 97

def workspace
  @workspace ||= Altria::Workspace.new(workspace_path)
end

#workspace_pathObject



101
102
103
# File 'app/models/job.rb', line 101

def workspace_path
  Altria.configuration.workspace_path + "jobs/#{id}"
end