Class: BackgroundQueue::ClientLib::JobHandle

Inherits:
Object
  • Object
show all
Defined in:
lib/background_queue/client_lib/job_handle.rb

Overview

returned from add_task to describe what the job/server was added. this is because you can call add_task without a job_id, and not know what server was used. this is passed to get_status

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner_id, job_id, server) ⇒ JobHandle

Returns a new instance of JobHandle.



12
13
14
15
16
# File 'lib/background_queue/client_lib/job_handle.rb', line 12

def initialize(owner_id, job_id, server)
  @owner_id = owner_id
  @job_id = job_id
  @server = server
end

Instance Attribute Details

#job_idObject (readonly)

Returns the value of attribute job_id.



9
10
11
# File 'lib/background_queue/client_lib/job_handle.rb', line 9

def job_id
  @job_id
end

#owner_idObject (readonly)

Returns the value of attribute owner_id.



8
9
10
# File 'lib/background_queue/client_lib/job_handle.rb', line 8

def owner_id
  @owner_id
end

#serverObject (readonly)

Returns the value of attribute server.



10
11
12
# File 'lib/background_queue/client_lib/job_handle.rb', line 10

def server
  @server
end

Class Method Details

.get_registered_job(session_id, key) ⇒ Object

look up a job from the key returned from register



39
40
41
# File 'lib/background_queue/client_lib/job_handle.rb', line 39

def self.get_registered_job(session_id, key)
  Cache.get("#{session_id}_#{key}")
end

Instance Method Details

#get_registration_key(session_id) ⇒ Object

find the key for this job if its already registeed



44
45
46
47
# File 'lib/background_queue/client_lib/job_handle.rb', line 44

def get_registration_key(session_id)
  reverse_key = [owner_id, job_id, server].join("_")
  Cache.get("#{session_id}_#{reverse_key}")
end

#register(session_id) ⇒ Object

register this job and return the registered key



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/background_queue/client_lib/job_handle.rb', line 19

def register(session_id)
  md5 = Digest::MD5::new
  now = Time::now
  md5.update(now.to_s)
  md5.update(String(now.usec))
  md5.update(String(rand(0)))
  md5.update(String($$))
  md5.update('foobar')
  md5.update(owner_id.to_s)
  md5.update(job_id.to_s)
  md5.update(server.to_s)
  key = md5.hexdigest
      
  Cache.put("#{session_id}_#{key}", self )
  
  reverse_key = [owner_id, job_id, server].join("_")
  Cache.put("#{session_id}_#{reverse_key}", key )
end