Class: River::JobArgsHash

Inherits:
Object
  • Object
show all
Defined in:
lib/job.rb

Overview

Provides a way of creating a job args from a simple Ruby hash for a quick way to insert a job without having to define a class. The first argument is a “kind” string for identifying the job in the database and the second is a hash that will be encoded to JSON.

For example:

insert_res = client.insert(River::JobArgsHash.new("job_kind", {
  job_num: 1
}))

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, hash) ⇒ JobArgsHash

Returns a new instance of JobArgsHash.



22
23
24
25
26
27
28
# File 'lib/job.rb', line 22

def initialize(kind, hash)
  raise "kind should be non-nil" if !kind
  raise "hash should be non-nil" if !hash

  @kind = kind
  @hash = hash
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



30
31
32
# File 'lib/job.rb', line 30

def kind
  @kind
end

Instance Method Details

#to_jsonObject



32
33
34
# File 'lib/job.rb', line 32

def to_json
  JSON.dump(@hash)
end