Class: BaseTask
- Inherits:
-
Object
- Object
- BaseTask
- Defined in:
- lib/tasks/baseTask.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#do_task_work ⇒ Object
This method should be overridden by the subclass and does the specific task work.
-
#initialize(webService, thing, isThingTask) ⇒ BaseTask
constructor
A new instance of BaseTask.
-
#perform ⇒ Object
Perform the task.
Constructor Details
#initialize(webService, thing, isThingTask) ⇒ BaseTask
Returns a new instance of BaseTask.
4 5 6 7 8 |
# File 'lib/tasks/baseTask.rb', line 4 def initialize( webService, thing, isThingTask ) @web = webService @thing = thing @isThingTask = isThingTask end |
Instance Method Details
#do_task_work ⇒ Object
This method should be overridden by the subclass and does the specific task work.
53 54 55 |
# File 'lib/tasks/baseTask.rb', line 53 def do_task_work return { :response => 'error', :msg => 'Task work method not implemented.' } end |
#perform ⇒ Object
Perform the task.
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 |
# File 'lib/tasks/baseTask.rb', line 13 def perform response = {} # # Make sure thing is valid (id and code exists) before doing any work. The exception of course is if we # are creating or retrieving a thing, in which case, id and code will not exist. # if( (@thing.id.to_s.length > 0 && @thing.code.length > 0) || @isThingTask ) # # Do the task work. If token has expired, then reauthorize and try again. # begin response = do_task_work() if( response[:response] == 'token_expired') @web.() response = do_task_work() end # # On any exception, return an error response with the exception description in the message. # rescue response[:response] = 'error' response[:msg] = "#{$!.class} - #{$!.message}" @thing.last_error = response[:msg] end # # Thing has not been created. Return the appropriate error and message. # else response[:response] = 'error' response[:msg] = "Thing '#{@thing.name}' has not been created." end # # Return the response. # return response end |