Class: Textus::Store::Jobs::Queue::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/store/jobs/queue.rb

Constant Summary collapse

DIGEST_BYTES =
16

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, args:, role:, attempts: 0, max_attempts: 3, errors: []) ⇒ Job

Returns a new instance of Job.



21
22
23
24
25
26
27
28
# File 'lib/textus/store/jobs/queue.rb', line 21

def initialize(type:, args:, role:, attempts: 0, max_attempts: 3, errors: [])
  @type = type.to_s
  @args = stringify(args)
  @role = role.to_s
  @attempts = attempts.to_i
  @max_attempts = max_attempts.to_i
  @errors = Array(errors)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



19
20
21
# File 'lib/textus/store/jobs/queue.rb', line 19

def args
  @args
end

#attemptsObject (readonly)

Returns the value of attribute attempts.



19
20
21
# File 'lib/textus/store/jobs/queue.rb', line 19

def attempts
  @attempts
end

#errorsObject (readonly)

Returns the value of attribute errors.



19
20
21
# File 'lib/textus/store/jobs/queue.rb', line 19

def errors
  @errors
end

#max_attemptsObject (readonly)

Returns the value of attribute max_attempts.



19
20
21
# File 'lib/textus/store/jobs/queue.rb', line 19

def max_attempts
  @max_attempts
end

#roleObject (readonly)

Returns the value of attribute role.



19
20
21
# File 'lib/textus/store/jobs/queue.rb', line 19

def role
  @role
end

#typeObject (readonly)

Returns the value of attribute type.



19
20
21
# File 'lib/textus/store/jobs/queue.rb', line 19

def type
  @type
end

Instance Method Details

#idObject



30
31
32
# File 'lib/textus/store/jobs/queue.rb', line 30

def id
  "#{type}:#{Digest::SHA256.hexdigest(JSON.dump(args.sort.to_h))[0, DIGEST_BYTES]}"
end