Class: Postjob::Registry::WorkflowSpec::Options

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

Constant Summary collapse

DEFAULTS =
{
  version: "0.0",
  max_attempts: 5,
  timeout: 15 * 60,
  sticky: false,
  greedy: false,
  cron_interval: nil,
  queue: Postjob::DEFAULT_QUEUE
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Options

Returns a new instance of Options.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/postjob/registry.rb', line 73

def initialize(options)
  expect! options => {
    version:        [ nil, /^\d+(\.\d+)*/ ],
    max_attempts:   [ nil, Integer ],
    timeout:        [ nil, Integer ],
    sticky:         [ nil, true, false ],
    cron_interval:  [ nil, Integer ],
    queue:          [ nil, String ]
  }

  options = DEFAULTS.merge(options)

  options[:sticky] ||= options[:greedy]

  @version        = options[:version]
  @max_attempts   = options[:max_attempts]
  @timeout        = options[:timeout]
  @sticky         = options[:sticky]
  @greedy         = options[:greedy]
  @cron_interval  = options[:cron_interval]
  @queue          = options[:queue]
end

Instance Attribute Details

#cron_intervalObject (readonly)

Returns the value of attribute cron_interval.



70
71
72
# File 'lib/postjob/registry.rb', line 70

def cron_interval
  @cron_interval
end

#greedyObject (readonly)

Returns the value of attribute greedy.



69
70
71
# File 'lib/postjob/registry.rb', line 69

def greedy
  @greedy
end

#max_attemptsObject (readonly)

Returns the value of attribute max_attempts.



66
67
68
# File 'lib/postjob/registry.rb', line 66

def max_attempts
  @max_attempts
end

#queueObject (readonly)

Returns the value of attribute queue.



71
72
73
# File 'lib/postjob/registry.rb', line 71

def queue
  @queue
end

#stickyObject (readonly)

Returns the value of attribute sticky.



68
69
70
# File 'lib/postjob/registry.rb', line 68

def sticky
  @sticky
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



67
68
69
# File 'lib/postjob/registry.rb', line 67

def timeout
  @timeout
end

#versionObject (readonly)

Returns the value of attribute version.



65
66
67
# File 'lib/postjob/registry.rb', line 65

def version
  @version
end

Instance Method Details

#inspectObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/postjob/registry.rb', line 96

def inspect
  r = {}
  r[:version]         = @version
  r[:max_attempts]    = @max_attempts
  r[:timeout]         = @timeout
  r[:sticky]          = @sticky
  r[:greedy]          = @greedy
  r[:cron_interval]   = @cron_interval
  r[:queue]           = @queue

  m = []
  r.each do |k, v|
    next if DEFAULTS[k] == v
    m << "#{k}: #{v.inspect}"
  end
  m.join(", ")
end