class Postjob::Registry
The registry holds a list of all available workflows
Attributes
workflows[R]
workflows_with_versions[R]
Public Class Methods
[](name)
click to toggle source
# File lib/postjob/registry.rb, line 170 def self.[](name) lookup! name: name, version: "" rescue KeyError nil end
instance()
click to toggle source
# File lib/postjob/registry.rb, line 3 def self.instance @instance ||= new end
load(glob_pattern)
click to toggle source
# File lib/postjob/registry.rb, line 53 def self.load(glob_pattern) Dir.glob(glob_pattern).sort.each do |path| before = Postjob::Registry.workflow_names Kernel.load path after = Postjob::Registry.workflow_names new_workflows = after - before next if new_workflows.empty? Postjob.logger.debug "#{path}: registered workflow(s) #{new_workflows.join(', ')}" end end
lookup!(name:, version:)
click to toggle source
looks up a specific version of a specific workflow. Returns a WorkflowSpec
object.
# File lib/postjob/registry.rb, line 166 def self.lookup!(name:, version:) instance.lookup! name: name, version: version end
new()
click to toggle source
# File lib/postjob/registry.rb, line 179 def initialize @workflows = {} @workflows_with_versions = [] end
queues()
click to toggle source
returns an array with the name of all queues that are configured here.
# File lib/postjob/registry.rb, line 17 def self.queues queues = workflows .select { |_, spec| spec.runnable? } .map(&:last) .map(&:options) .map(&:queue) # For a while "ruby" was the name of the default queue. Since we might # have jobs with the queue in the database we always return "ruby" as # one of the runnable queues, even if there is no workflow explicitely # registered on a "ruby" queue. queues << "ruby" queues.uniq end
register(workflow, options = {})
click to toggle source
# File lib/postjob/registry.rb, line 49 def self.register(workflow, options = {}) instance.register(workflow, options) end
runnable_workflows_with_versions()
click to toggle source
# File lib/postjob/registry.rb, line 36 def self.runnable_workflows_with_versions workflows .select { |_, spec| spec.runnable? } .inject([]) do |ary, (name_and_version, _spec)| name, version = *name_and_version ary << name << "#{name}#{version}" end end
workflow_names()
click to toggle source
# File lib/postjob/registry.rb, line 32 def self.workflow_names instance.workflows.keys.map(&:first).uniq end
workflows()
click to toggle source
# File lib/postjob/registry.rb, line 12 def self.workflows instance.workflows end
workflows_with_versions()
click to toggle source
# File lib/postjob/registry.rb, line 45 def self.workflows_with_versions instance.workflows_with_versions end
Public Instance Methods
lookup!(name:, version:)
click to toggle source
looks up a specific version of a specific workflow. Returns the workflow module itself
# File lib/postjob/registry.rb, line 199 def lookup!(name:, version:) expect! name => String expect! version => String @workflows.fetch([name, version]) end
register(workflow, options)
click to toggle source
# File lib/postjob/registry.rb, line 184 def register(workflow, options) if options[:greedy] && options[:sticky] == false raise ArgumentError, "#{workflow}: a greedy job must also be sticky" end spec = WorkflowSpec.new(workflow, options) @workflows_with_versions << spec.name << "#{spec.name}#{spec.options.version}" @workflows[[spec.name, ""]] = spec @workflows[[spec.name, spec.options.version]] = spec end