Class: BackgroundQueue::ServerLib::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/background_queue/server_lib/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner_id, job_id, id, priority, worker, params, options) ⇒ Task

Returns a new instance of Task.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/background_queue/server_lib/task.rb', line 16

def initialize(owner_id, job_id, id, priority, worker, params, options)
  @owner_id = owner_id
  @job_id = job_id
  @id = id
  @priority = priority
  raise "Missing priority" if @priority.nil?
  @worker = worker
  @running = false
  @options = options
  @params = params
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/background_queue/server_lib/task.rb', line 4

def id
  @id
end

#job_idObject

Returns the value of attribute job_id.



8
9
10
# File 'lib/background_queue/server_lib/task.rb', line 8

def job_id
  @job_id
end

#optionsObject

Returns the value of attribute options.



14
15
16
# File 'lib/background_queue/server_lib/task.rb', line 14

def options
  @options
end

#owner_idObject

Returns the value of attribute owner_id.



7
8
9
# File 'lib/background_queue/server_lib/task.rb', line 7

def owner_id
  @owner_id
end

#priorityObject

Returns the value of attribute priority.



5
6
7
# File 'lib/background_queue/server_lib/task.rb', line 5

def priority
  @priority
end

#runningObject

Returns the value of attribute running.



12
13
14
# File 'lib/background_queue/server_lib/task.rb', line 12

def running
  @running
end

#workerObject

Returns the value of attribute worker.



10
11
12
# File 'lib/background_queue/server_lib/task.rb', line 10

def worker
  @worker
end

Instance Method Details

#domainObject



44
45
46
# File 'lib/background_queue/server_lib/task.rb', line 44

def domain
  @options[:domain]
end

#get_error_countObject



80
81
82
83
84
85
86
# File 'lib/background_queue/server_lib/task.rb', line 80

def get_error_count
  if @error_count.nil?
    0
  else
    @error_count
  end
end

#get_error_statusObject



92
93
94
# File 'lib/background_queue/server_lib/task.rb', line 92

def get_error_status
  @error_status
end

#get_jobObject



52
53
54
# File 'lib/background_queue/server_lib/task.rb', line 52

def get_job
  @job
end

#increment_error_countObject



104
105
106
# File 'lib/background_queue/server_lib/task.rb', line 104

def increment_error_count
  @error_count = get_error_count + 1
end

#initial_progress_captionObject



72
73
74
# File 'lib/background_queue/server_lib/task.rb', line 72

def initial_progress_caption
  @options[:initial_progress_caption]
end

#is_excluded_from_count?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/background_queue/server_lib/task.rb', line 56

def is_excluded_from_count?
  @options[:exclude] == true
end

#replaced_while_waiting_to_retry?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/background_queue/server_lib/task.rb', line 100

def replaced_while_waiting_to_retry?
  @error_status == :replaced_while_waiting_to_retry
end

#running?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/background_queue/server_lib/task.rb', line 40

def running?
  @running
end

#send_summary?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/background_queue/server_lib/task.rb', line 76

def send_summary?
  @options[:send_summary] 
end

#set_error_status(e_status) ⇒ Object



88
89
90
# File 'lib/background_queue/server_lib/task.rb', line 88

def set_error_status(e_status)
  @error_status = e_status
end

#set_job(job) ⇒ Object



48
49
50
# File 'lib/background_queue/server_lib/task.rb', line 48

def set_job(job)
  @job = job
end

#set_worker_status(status) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/background_queue/server_lib/task.rb', line 113

def set_worker_status(status)
  raise "Task without job set" if @job.nil?
  status[:task_id] = self.id
  status[:exclude] = self.is_excluded_from_count?
  status[:weight] = self.weighted_percent if self.weighted?
  @job.set_worker_status(status)
end

#stepObject



108
109
110
# File 'lib/background_queue/server_lib/task.rb', line 108

def step
  @options[:step]
end

#synchronous?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/background_queue/server_lib/task.rb', line 60

def synchronous?
  @options[:synchronous] == true
end

#to_json(dummy = true) ⇒ Object



28
29
30
# File 'lib/background_queue/server_lib/task.rb', line 28

def to_json(dummy=true)
  to_json_object(false).to_json
end

#to_json_object(full) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/background_queue/server_lib/task.rb', line 32

def to_json_object(full)
  jo = {:owner_id=>@owner_id, :job_id=>@job_id, :id=>@id, :priority=>@priority, :worker=>@worker, :params=>@params }
  if full
    jo[:options] = @options
  end
  jo
end

#waiting_to_retry?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/background_queue/server_lib/task.rb', line 96

def waiting_to_retry?
  @error_status == :waiting_to_retry
end

#weighted?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/background_queue/server_lib/task.rb', line 64

def weighted?
  @options[:weight] && @options[:weight] > 0
end

#weighted_percentObject



68
69
70
# File 'lib/background_queue/server_lib/task.rb', line 68

def weighted_percent
  @options[:weight]
end