sul-dlss/was_robot_suite

View on GitHub
bin/run_robot

Summary

Maintainability
Test Coverage

#!/usr/bin/env ruby
# frozen_string_literal: true

# Will run one robot as specified, either for a druid a file containing one druid per line
#
# To run With Options
# Options must be placed AFTER workflow and robot name
# robot_root$ ./bin/run_robot Accession::Publish -e test -d druid:aa12bb1234
require 'bundler/setup'
require 'slop'

slop = Slop.parse do |o|
  o.banner = 'Usage: ./bin/run_robot class_name [options]'
  o.string '-e', '--environment', 'Environment to run in (i.e. test, production). Defaults to development', default: 'development'
  o.string '-d', '--druid', 'One druid to run the robot with', required: true
  o.string '-f', '--file', 'One file containing a druid per line'
  o.on '--help' do
    puts o
    exit
  end
end

ARGV.replace slop.arguments

robot = ARGV.shift
opts = slop.to_h

ENV['ROBOT_ENVIRONMENT'] = opts[:environment] unless opts[:environment].nil?
require File.expand_path(File.dirname(__FILE__) + '/../config/boot')

# instantiate a Robot object using the name
klazz = robot.split('::').inject(Robots::DorRepo) { |o, c| o.const_get c }
bot = klazz.new
bot.check_queued_status = false # skipping the queued workflow status check

druids = if opts[:file]
           IO.readlines(opts[:file]).map(&:strip)
         else
           [opts[:druid]]
         end

druids.each do |druid|
  bot.work druid
end