Module: Libis::Workflow::Status

Included in:
Base::WorkItem
Defined in:
lib/libis/workflow/status.rb

Constant Summary collapse

STATUS =
{
    NOT_STARTED: 0,
    STARTED: 1,
    DONE: 2,
    ASYNC_WAIT: 3,
    ASYNC_HALT: 4,
    FAILED: 5
}

Instance Method Summary collapse

Instance Method Details

#check_status(state, task = nil) ⇒ Boolean

Check status of the object.

Parameters:

  • state (Symbol)

    status to look for

  • task (String) (defaults to: nil)

    name of task whose status to check

Returns:

  • (Boolean)

    true if the object status matches



46
47
48
# File 'lib/libis/workflow/status.rb', line 46

def check_status(state, task = nil)
  self.status(task) == state
end

#compare_status(state, task = nil) ⇒ Integer

Compare status with current status of the object.

Parameters:

  • state (Symbol)

Returns:

  • (Integer)

    1, 0 or -1 depnding on which



54
55
56
# File 'lib/libis/workflow/status.rb', line 54

def compare_status(state, task = nil)
  STATUS[self.status(task)] <=> STATUS[state]
end

#status(task = nil) ⇒ Symbol

Get last known status symbol for a given task

Parameters:

  • task (String) (defaults to: nil)

    task name to check item status for

Returns:

  • (Symbol)

    the status code



27
28
29
30
# File 'lib/libis/workflow/status.rb', line 27

def status(task = nil)
  entry = status_entry(task)
  status_symbol(entry[:status]) rescue :NOT_STARTED
end

#status=(x) ⇒ Object

Changes the status of the object. The status changed is logged in the status_log with the current timestamp.

Parameters:

  • x (Array)

    Array with status and task



17
18
19
20
21
# File 'lib/libis/workflow/status.rb', line 17

def status=(x)
  s, task = x
  self.add_status_log(task: task, status: s)
  self.save
end

#status_label(task = nil) ⇒ String

Gets the last known status label of the object.

Parameters:

  • task (String) (defaults to: nil)

    name of task to get the status for

Returns:

  • (String)

    status label ( = task name + status )



36
37
38
39
# File 'lib/libis/workflow/status.rb', line 36

def status_label(task = nil)
  entry = self.status_entry(task)
  "#{entry[:task] rescue nil}#{entry[:status].capitalize rescue nil}"
end