<commit_before>class Redis # :nodoc:
  # FIXME:  instance_eval this when required, like a true hero.
  class Namespace # :nodoc:
    attr_reader :redis
  end
end

# XXX: move this where required, afaik in the jobfile surrounding logic.
def _jobco_path *x # :nodoc:
  File::join(File::dirname(__FILE__), "jobco", *x)
end

# JobCo is a Resque distribution.
#
# It wraps Resque, alongside the +JobWithStatus+ and +Scheduler+ plugins,
# into one easy to use package.
#
# === What does this mean ?
#
# For your job running projects, this translates to :
#
# * A +Jobfile+, generally project-wide, to help you define and configure
#   your jobs in a single file.
#
# * The +jobco+ command line tool:
#   * Wraps Resque process management (see <tt>jobco resque --help</tt> subcommands)
#   * Allows trivial job control (see <tt>jobco jobs --help</tt> subcommands)
#
# * The <tt>JobCo::*</tt> Ruby library, that provide useful primitives for writing and
#   controlling jobs.
#
#
# === What do I get - compared to rolling out my own stack ?
#
# Several things !
#
# * Sensible development/production defaults
# * Unified, (somewhat) documented class to inherit from : JobCo::Job
# * Job introspection routines (JobCo::Jobs) - Useful for custom 'job control' tools
# * Coherent job manipulation routines (JobCo::API)

module JobCo
  require "jobco/api"
  require "jobco/jobs"
  require "jobco/jobfile"
  self.extend(JobCo::API)

  # You want to call this once in your application.
  # It's perfectly fine for a jobco Rails initializer.
  #
  # If you would like JobCo to load code located in your
  # <tt>job_load_path</tt> (see Jobfile), see JobCo::Jobs::require_files
  # 
  def self.boot filename = Jobfile::find
    Jobfile::evaluate filename # populate JobCo::Config

    resque_redis = Config.resque_redis
    if resque_redis
      if resque_redis.is_a?(String)
        Resque.redis = resque_redis
      elsif resque_redis.is_a?(Hash)
        Resque.redis = Redis.new(resque_redis)
      elsif resque_redis == :default
      else
        fail "invalid 'resque_redis' jobconf : `#{resque_redis}`"
      end
    else
      fail "Jobfile: `jobconf 'resque_redis'` is mandatory."
    end
  end

  def self.redis # :nodoc:
    @@redis ||= Redis::Namespace.new("jobco", :redis => ::Resque.redis.redis)
  end
end<commit_msg>simplified/documented entry points; cleaner docs<commit_after>class Redis # :nodoc:
  # FIXME:  instance_eval this when required, like a true hero.
  class Namespace # :nodoc:
    attr_reader :redis
  end
end

# XXX: move this where required, probably in the jobfile surrounding logic.
def _jobco_path *x # :nodoc:
  File::join(File::dirname(__FILE__), "jobco", *x)
end

# JobCo is a Resque distribution.
#
# It wraps Resque, alongside the +JobWithStatus+ and +Scheduler+ plugins,
# into one easy to use package.
#
# Check out the README if you haven't done so already.
#
# === What do I code with JobCo ?
#
# * Job definition : inherit from JobCo::Job and implement perform()
# * Job manipulation : JobCo::API
# * Job introspection : JobCo::Jobs (Useful if you wish to write your own logic around 'job control' - quite likely, right?)
module JobCo
  require "jobco/api"
  require "jobco/jobs"
  require "jobco/jobfile"
  # XXX: require jobco deps here and be done with it
  self.extend(JobCo::API)

  # Minimal JobCo initialization routine
  # It will not require the ruby files holding your job code (see #boot_and_load to do that).
  #
  # It's well suited as a JobCo Rails initializer provided Rails can load your job code.
  # One easy way for Rails to find your job ruby files is to put then under 'app/jobs'.
  #
  # Exemple:
  #    JobCo::boot # inside config/initializers/jobco.rb
  #
  def self.boot filename = Jobfile::find
    Jobfile::evaluate filename # populate JobCo::Config

    resque_redis = Config.resque_redis
    if resque_redis
      if resque_redis.is_a?(String)
        Resque.redis = resque_redis
      elsif resque_redis.is_a?(Hash)
        Resque.redis = Redis.new(resque_redis)
      elsif resque_redis == :default
      else
        fail "invalid 'resque_redis' jobconf : `#{resque_redis}`"
      end
    else
      fail "Jobfile: `jobconf 'resque_redis'` is mandatory."
    end
  end

  # General purpose JobCo initialization routine.
  #
  # Call this once if using JobCo 'bare ruby' style
  # Remember that job files can only be loaded once unless dark magic is used.
  #
  # See implementation for yourself.
  def self.boot_and_load filename = Jobfile::find
    JobCo::boot(filename)
    JobCo::Jobs::require_files
  end

  def self.redis # :nodoc:
    @@redis ||= Redis::Namespace.new("jobco", :redis => ::Resque.redis.redis)
  end
end
{'fraction_non_alphanumeric': 0.10098206660973527, 'fraction_numerical': 0.0, 'mean_word_length': 3.611220472440945, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '447486', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1529, 'n_words': 519}