Class: Job
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Job
- Includes:
- Altria::Proprietary
- Defined in:
- app/models/job.rb
Defined Under Namespace
Classes: ScriptNotFound
Class Method Summary collapse
- .after_enqueue(&block) ⇒ Object
- .after_enqueues ⇒ Object
- .after_execute(&block) ⇒ Object
- .after_executes ⇒ Object
- .before_enqueue(&block) ⇒ Object
- .before_enqueues ⇒ Object
- .before_execute(&block) ⇒ Object
- .before_executes ⇒ Object
- .create_with_properties(params) ⇒ Object
- .scheduled ⇒ Object
Instance Method Summary collapse
- #current_build ⇒ Object
- #enqueue ⇒ Object
- #enqueue_with_before_enqueues ⇒ Object
- #execute ⇒ Object
- #last_finished_build ⇒ Object
- #run ⇒ Object
- #scheduler ⇒ Object
- #status_name ⇒ Object
- #update_attributes_with_properties(params) ⇒ Object
- #workspace ⇒ Object
- #workspace_path ⇒ Object
Methods included from Altria::Proprietary
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_enqueues ⇒ Object
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_executes ⇒ Object
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_enqueues ⇒ Object
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_executes ⇒ Object
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 |
.scheduled ⇒ Object
27 28 29 |
# File 'app/models/job.rb', line 27 def scheduled select(&:scheduled?) end |
Instance Method Details
#current_build ⇒ Object
84 85 86 |
# File 'app/models/job.rb', line 84 def current_build builds.running.latest end |
#enqueue ⇒ Object
72 73 74 |
# File 'app/models/job.rb', line 72 def enqueue builds.create.tap(&:enqueue).tap { execute_after_enqueues } end |
#enqueue_with_before_enqueues ⇒ Object
76 77 78 |
# File 'app/models/job.rb', line 76 def enqueue_with_before_enqueues enqueue if execute_before_enqueues end |
#execute ⇒ Object
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_build ⇒ Object
88 89 90 |
# File 'app/models/job.rb', line 88 def last_finished_build builds.finished.order(:finished_at).last end |
#run ⇒ Object
64 65 66 |
# File 'app/models/job.rb', line 64 def run script ? execute : raise_script_not_found end |
#scheduler ⇒ Object
68 69 70 |
# File 'app/models/job.rb', line 68 def scheduler Altria::Scheduler.new(schedule) if schedule.present? end |
#status_name ⇒ Object
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 |
#workspace ⇒ Object
97 98 99 |
# File 'app/models/job.rb', line 97 def workspace @workspace ||= Altria::Workspace.new(workspace_path) end |
#workspace_path ⇒ Object
101 102 103 |
# File 'app/models/job.rb', line 101 def workspace_path Altria.configuration.workspace_path + "jobs/#{id}" end |