Module: Krikri::SoftwareAgent::ClassMethods

Defined in:
lib/krikri/software_agent.rb

Overview

Class methods for extension by ActiveSupport::Concern

Instance Method Summary collapse

Instance Method Details

#agent_nameObject

Returns a string representation of this SoftwareAgent class.

Returns:

  • a string representation of this SoftwareAgent class



60
61
62
# File 'lib/krikri/software_agent.rb', line 60

def agent_name
  to_s
end

#enqueue(*args) ⇒ Boolean

Enqueue a job.

A worker process must be started to process jobs in the “harvest” queue, either before or after they are enqueued:

shell$ QUEUE=harvest bundle exec rake environment resque:work

This depends on Redis and Marmotta being available and properly configured (if necessary) in the Rails app.

Examples:

MyAgent.enqueue(:name => my_job)
Krikri::Harvesters::OAIHarvester.enqueue(
  :harvest,
  opts = {
    uri: 'http://vcoai.lib.harvard.edu/vcoai/vc',
    oai: { set: 'dag', metadata_prefix: 'mods' }
  }
)

Parameters:

  • queue_name (#to_s)

    the Resque queue name

  • opts (Hash)

    a hash of options that will be used to initialize the agent (an instance of this class).

Returns:

  • (Boolean)

See Also:



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/krikri/software_agent.rb', line 104

def enqueue(*args)
  queue = args.shift unless args.first.is_a? Hash
  queue ||= queue_name
  opts = args.shift || {}
  fail ArgumentError, "unexpected arguments #{args}" unless args.empty?
  fail ArgumentError, 'opts is not a hash' unless opts.is_a?(Hash)

  activity = Krikri::Activity.create do |a|
    a.agent = agent_name
    a.opts = JSON.generate(opts)
  end

  Krikri::Logger.log :info, "created activity #{activity.id}"
  Resque.enqueue_to(queue, Krikri::Job, activity.id)
  Krikri::Logger.log :info, "enqueued to #{queue}"
  true
end

#queue_nameObject

Returns the name of the default queue for jobs invoking this SoftwareAgent.

Returns:

  • the name of the default queue for jobs invoking this SoftwareAgent



67
68
69
# File 'lib/krikri/software_agent.rb', line 67

def queue_name
  agent_name.downcase
end