Class: Snapsync::Task
- Inherits:
-
Object
- Object
- Snapsync::Task
- Defined in:
- lib/snapsync/tasks/Task.rb
Overview
Tasks extending this should implement _run, _task_name
All messages should be sent through info, warn, error All sub-tasks should be executed by task or appropriately adding parent to <Task>.new Progress (if the task implements it) should be notified by set_progress
Direct Known Subclasses
Instance Method Summary collapse
- #_run ⇒ Object
- #_task_name ⇒ Object
- #error(msg) ⇒ Object
- #info(msg) ⇒ Object
-
#initialize(parent: nil) ⇒ Task
constructor
A new instance of Task.
- #run ⇒ Object
- #set_progress(percent) ⇒ Object
- #set_status(status) ⇒ Object
- #warn(msg) ⇒ Object
Constructor Details
#initialize(parent: nil) ⇒ Task
Returns a new instance of Task.
40 41 42 |
# File 'lib/snapsync/tasks/Task.rb', line 40 def initialize(parent: nil) @parent = parent end |
Instance Method Details
#_run ⇒ Object
75 76 77 |
# File 'lib/snapsync/tasks/Task.rb', line 75 def _run raise NotImplementedError end |
#_task_name ⇒ Object
71 72 73 |
# File 'lib/snapsync/tasks/Task.rb', line 71 def _task_name raise NotImplementedError end |
#error(msg) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/snapsync/tasks/Task.rb', line 25 def error(msg) Snapsync.error msg if Snapsync.NOTIFY @notification.update({:body => msg, :urgency => :critical}) end end |
#info(msg) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/snapsync/tasks/Task.rb', line 11 def info(msg) Snapsync.info msg if Snapsync.NOTIFY @notification.update({:body => msg}) end end |
#run ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/snapsync/tasks/Task.rb', line 51 def run if Snapsync.NOTIFY @notification = Notification.new({ :app_name => "Snapsync"+(Snapsync.SYSTEMD ? ' [systemd service]' : ''), :body => "Starting...", :summary => "#{_task_name} Running", :urgency => :normal, :append => false, :transient => false, :timeout => 15.0, :icon_path => "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"}) end begin _run rescue Exception => e set_status "Failed" error e. raise e end set_status "Finished" end |
#set_progress(percent) ⇒ Object
33 34 35 36 37 |
# File 'lib/snapsync/tasks/Task.rb', line 33 def set_progress(percent) if Snapsync.NOTIFY @notification.update({:body => "[#{'#'*(percent / 10)}]"}) end end |
#set_status(status) ⇒ Object
44 45 46 47 48 |
# File 'lib/snapsync/tasks/Task.rb', line 44 def set_status(status) if Snapsync.NOTIFY @notification.update({ :summary => "#{_task_name} #{status}" }) end end |
#warn(msg) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/snapsync/tasks/Task.rb', line 18 def warn(msg) Snapsync.warn msg if Snapsync.NOTIFY @notification.update({:body => msg, :urgency => :critical}) end end |