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



49
50
51
# File 'lib/krikri/software_agent.rb', line 49

def agent_name
  to_s
end

#enqueue(job_class, opts = {}) ⇒ Boolean

Enqueue a job.

Example:

Krikri::Harvesters::OAIHarvester.enqueue(
  Krikri::HarvestJob,
  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.



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/krikri/software_agent.rb', line 79

def enqueue(job_class, opts = {})
  fail "#{job_class} has no #perform method" unless
    job_class.respond_to?(:perform)
  fail '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
  log :info, "created activity #{activity.id}"
  Resque.enqueue(job_class, activity.id)
  log :info, "enqueued #{job_class}"
  true
end

#log(priority, msg) ⇒ Object

Log a message, tagged in a way suitable for software agents.

See Also:

  • method_missing


39
40
41
42
43
44
45
# File 'lib/krikri/software_agent.rb', line 39

def log(priority, msg)
  Krikri::SoftwareAgent::Logger.tagged(
    Time.now.to_s, Process.pid, to_s
  ) do
    Krikri::SoftwareAgent::Logger.send(priority, msg)
  end
end