Module: Dronejob::Modules::Queue
Instance Method Summary collapse
- #notify_after_job ⇒ Object
- #notify_before_phase ⇒ Object
- #publish_error(event) ⇒ Object
- #publish_progress(progress, description = nil, details = {}) ⇒ Object
- #publish_status(data = {}, status = "working") ⇒ Object
- #pusher_client ⇒ Object
- #should_notify? ⇒ Boolean
Instance Method Details
#notify_after_job ⇒ Object
64 65 66 |
# File 'lib/dronejob/modules/queue.rb', line 64 def notify_after_job publish_status({ title: self.title, description: "Job Completed!", phase: @phase, progress: 100 }, "complete") if should_notify? end |
#notify_before_phase ⇒ Object
60 61 62 |
# File 'lib/dronejob/modules/queue.rb', line 60 def notify_before_phase publish_status({ title: self.title, description: @phase_config[:title], phase: @phase, progress: @phase_config[:progress] }, "working") if @phase_config[:notify] and should_notify? end |
#publish_error(event) ⇒ Object
56 57 58 |
# File 'lib/dronejob/modules/queue.rb', line 56 def publish_error(event) publish_status({ title: self.title, description: event., phase: @phase, progress: 100 }, "failed") if should_notify? end |
#publish_progress(progress, description = nil, details = {}) ⇒ Object
72 73 74 75 |
# File 'lib/dronejob/modules/queue.rb', line 72 def publish_progress(progress, description = nil, details = {}) = { title: self.title, description: description, phase: @phase, progress: progress, details: details } publish_status(, "working") if should_notify? end |
#publish_status(data = {}, status = "working") ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/dronejob/modules/queue.rb', line 44 def publish_status(data = {}, status = "working") data[:action] = "update_process" data[:user_id] = param(:user_id) data[:jid] = job_id data[:worker] = Loader.identifier_for(self) data[:timestamp] = Time.now.to_i data[:status] = status return false if data[:user_id].nil? pusher_client.trigger("private-#{data[:user_id]}", "process", data) end |
#pusher_client ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/dronejob/modules/queue.rb', line 34 def pusher_client @pusher_client ||= Pusher::Client.new( app_id: option(:pusher_app_id), key: option(:pusher_key), secret: option(:pusher_secret), cluster: option(:pusher_cluster), encrypted: true ) end |
#should_notify? ⇒ Boolean
68 69 70 |
# File 'lib/dronejob/modules/queue.rb', line 68 def should_notify? self.class.notify? and param(:notify) and !param(:run) end |