module Krikri::SoftwareAgent::ClassMethods
Class methods for extension by ActiveSupport::Concern
Public Instance Methods
@return a string representation of this SoftwareAgent
class
# File lib/krikri/software_agent.rb, line 56 def agent_name to_s end
Enqueue a job.
@example
MyAgent.enqueue(:name => my_job)
@example
Krikri::Harvesters::OAIHarvester.enqueue( :harvest, opts = { uri: 'http://vcoai.lib.harvard.edu/vcoai/vc', oai: { set: 'dag', metadata_prefix: 'mods' } } )
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.
@param queue_name
[#to_s] the Resque queue name @param opts [Hash] a hash of options that will be used to initialize
the agent (an instance of this class).
@return [Boolean]
@see github.com/resque/resque/tree/1-x-stable @see Krikri::Job
@see Krikri::SoftwareAgent#agent_name
@see Krikri::Harvester::expected_opts
# File lib/krikri/software_agent.rb, line 108 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
@return [Krikri::EntityBehavior] the default entity initializiation
behavior for this class of SoftwareAgents
@see entity_behavior
# File lib/krikri/software_agent.rb, line 64 def entity_behavior Krikri::AggregationEntityBehavior end
@return the name of the default queue for jobs invoking this
SoftwareAgent
# File lib/krikri/software_agent.rb, line 71 def queue_name agent_name.downcase end