navvy 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +5 -3
- data/generators/navvy/navvy_generator.rb +10 -5
- data/generators/navvy/templates/{migration.rb → active_record_migration.rb} +0 -0
- data/generators/navvy/templates/sequel_migration.rb +23 -0
- data/lib/generators/navvy_generator.rb +12 -6
- data/lib/navvy.rb +7 -3
- data/lib/navvy/configuration.rb +4 -6
- data/lib/navvy/job.rb +3 -3
- data/lib/navvy/job/active_record.rb +0 -1
- data/lib/navvy/job/data_mapper.rb +0 -1
- data/lib/navvy/job/mongo_mapper.rb +0 -1
- data/lib/navvy/job/mongoid.rb +139 -0
- data/lib/navvy/job/sequel.rb +1 -2
- data/lib/navvy/logger.rb +38 -0
- data/lib/navvy/tasks.rb +2 -2
- data/lib/navvy/worker.rb +5 -37
- data/spec/configuration_spec.rb +20 -37
- data/spec/job_spec.rb +14 -14
- data/spec/logger_spec.rb +23 -0
- data/spec/setup/active_record.rb +0 -1
- data/spec/setup/mongoid.rb +9 -0
- data/spec/setup/sequel.rb +0 -1
- data/spec/spec_helper.rb +0 -14
- metadata +20 -78
- data/.document +0 -5
- data/.gitignore +0 -8
- data/Rakefile +0 -67
- data/VERSION +0 -1
- data/generators/navvy/templates/script +0 -4
- data/lib/navvy/log.rb +0 -74
- data/navvy.gemspec +0 -96
- data/spec/log_spec.rb +0 -63
- data/spec/setup/justlogging.rb +0 -3
- data/spec/setup/rails_default_logger.rb +0 -9
data/README.textile
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
h1. Navvy
|
2
2
|
|
3
|
-
Navvy is a simple Ruby background job processor inspired by "delayed_job":http://github.com/tobi/delayed_job, but aiming for database agnosticism. Currently Navvy supports ActiveRecord, MongoMapper, Sequel and
|
3
|
+
Navvy is a simple Ruby background job processor inspired by "delayed_job":http://github.com/tobi/delayed_job, but aiming for database agnosticism. Currently Navvy supports ActiveRecord, MongoMapper, Sequel, DataMapper and Mongoid but it's extremely easy to write an adapter for your favorite ORM.
|
4
|
+
|
5
|
+
Navvy doesn't depend on Rails, it's a pure Ruby library. There are generators for Rails 2 and Rails 3, though.
|
4
6
|
|
5
7
|
??“Navvy is a shorter form of navigator (UK) or navigational engineer (USA) and is particularly applied to describe the manual labourers working on major civil engineering projects. The term was coined in the late 18th century in Britain when numerous canals were being built, which were also sometimes known as "navigations". Canal navvies typically worked with shovels, pickaxes and barrows.”?? - "Wikipedia":http://en.wikipedia.org/wiki/Navvy
|
6
8
|
|
7
9
|
h2. Using Navvy
|
8
10
|
|
9
|
-
|
11
|
+
Check out the "Installation Guide":http://wiki.github.com/jeffkreeftmeijer/navvy/installation and the "Getting Started Guide":http://wiki.github.com/jeffkreeftmeijer/navvy/getting-started to get up and running. If you have any questions or problems, don't hesitate to "ask":http://github.com/inbox/new/jeffkreeftmeijer.
|
10
12
|
|
11
13
|
h2. Contributing
|
12
14
|
|
13
|
-
Found
|
15
|
+
Found an issue? Have a great idea? Want to help? Great! Create an issue "issue":http://github.com/jeffkreeftmeijer/navvy/issues for it, "ask":http://github.com/inbox/new/jeffkreeftmeijer, or even better; fork the project and fix the problem yourself. Pull requests are always welcome. :)
|
14
16
|
|
15
17
|
h2. License
|
16
18
|
|
@@ -1,14 +1,19 @@
|
|
1
1
|
class NavvyGenerator < Rails::Generator::Base
|
2
|
+
default_options :orm => 'active_record'
|
3
|
+
|
2
4
|
def manifest
|
3
5
|
record do |m|
|
4
|
-
options
|
5
|
-
:migration_file_name => 'create_jobs'
|
6
|
-
}
|
7
|
-
m.migration_template 'migration.rb', 'db/migrate', options
|
8
|
-
m.file 'script', 'script/navvy', :chmod => 0755
|
6
|
+
m.migration_template "#{options[:orm]}_migration.rb", 'db/migrate', {:migration_file_name => 'create_jobs'}
|
9
7
|
end
|
10
8
|
end
|
11
9
|
|
10
|
+
def add_options!(opt)
|
11
|
+
opt.separator ''
|
12
|
+
opt.separator 'Options:'
|
13
|
+
opt.on('--active_record', 'Generate a migration file for ActiveRecord. (default)') { options[:orm] = 'active_record' }
|
14
|
+
opt.on('--sequel', 'Generate a migration file for Sequel.') { options[:orm] = 'sequel' }
|
15
|
+
end
|
16
|
+
|
12
17
|
def banner
|
13
18
|
"Usage: #{$0} #{spec.name}"
|
14
19
|
end
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
up do
|
3
|
+
create_table(:jobs) do
|
4
|
+
primary_key :id, :type => Integer
|
5
|
+
String :object
|
6
|
+
String :method_name
|
7
|
+
String :arguments, :text => true
|
8
|
+
Integer :priority, :default => 0
|
9
|
+
String :return
|
10
|
+
String :exception
|
11
|
+
Integer :parent_id
|
12
|
+
DateTime :created_at
|
13
|
+
DateTime :run_at
|
14
|
+
DateTime :started_at
|
15
|
+
DateTime :completed_at
|
16
|
+
DateTime :failed_at
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
down do
|
21
|
+
drop_table(:jobs)
|
22
|
+
end
|
23
|
+
end
|
@@ -2,21 +2,27 @@ require 'rails/generators/migration'
|
|
2
2
|
class NavvyGenerator < Rails::Generators::Base
|
3
3
|
include Rails::Generators::Migration
|
4
4
|
|
5
|
+
class_option :active_record,
|
6
|
+
:desc => 'Generate a migration file for ActiveRecord. (default)',
|
7
|
+
:type => 'boolean'
|
8
|
+
|
9
|
+
class_option :sequel,
|
10
|
+
:desc => 'Generate a migration file for Sequel.',
|
11
|
+
:type => 'boolean'
|
12
|
+
|
5
13
|
def self.source_root
|
6
14
|
File.join(File.dirname(__FILE__), '..', '..', 'generators', 'navvy', 'templates')
|
7
15
|
end
|
8
16
|
|
9
17
|
def install_navvy
|
10
18
|
migration_template(
|
11
|
-
|
19
|
+
"#{orm}_migration.rb",
|
12
20
|
'db/migrate/create_jobs.rb'
|
13
21
|
)
|
22
|
+
end
|
14
23
|
|
15
|
-
|
16
|
-
|
17
|
-
'script/navvy',
|
18
|
-
:chmod => 0755
|
19
|
-
)
|
24
|
+
def orm
|
25
|
+
options[:sequel] ? 'sequel' : 'active_record'
|
20
26
|
end
|
21
27
|
|
22
28
|
protected
|
data/lib/navvy.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/navvy/worker')
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/navvy/
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/navvy/logger')
|
3
3
|
require File.expand_path(File.dirname(__FILE__) + '/navvy/configuration')
|
4
4
|
|
5
5
|
module Navvy
|
6
6
|
class << self
|
7
7
|
attr_writer :configuration
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
|
+
def self.logger
|
11
|
+
@logger || Navvy.configuration.logger
|
12
|
+
end
|
13
|
+
|
10
14
|
def self.configuration
|
11
15
|
@configuration ||= Configuration.new
|
12
16
|
end
|
13
|
-
|
17
|
+
|
14
18
|
def self.configure
|
15
19
|
yield(self.configuration)
|
16
20
|
end
|
data/lib/navvy/configuration.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
module Navvy
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :job_limit, :keep_jobs, :logger, :
|
4
|
-
|
5
|
-
|
3
|
+
attr_accessor :job_limit, :keep_jobs, :logger, :sleep_time, :max_attempts
|
4
|
+
|
6
5
|
def initialize
|
7
6
|
@job_limit = 100
|
8
7
|
@keep_jobs = false
|
9
|
-
@logger =
|
10
|
-
@quiet = false
|
8
|
+
@logger = Navvy::Logger.new
|
11
9
|
@sleep_time = 5
|
12
10
|
@max_attempts = 25
|
13
11
|
end
|
14
12
|
end
|
15
|
-
end
|
13
|
+
end
|
data/lib/navvy/job.rb
CHANGED
@@ -152,14 +152,14 @@ module Navvy
|
|
152
152
|
|
153
153
|
alias_method :completed?, :completed_at?
|
154
154
|
alias_method :failed?, :failed_at?
|
155
|
-
|
155
|
+
|
156
156
|
private
|
157
|
-
|
157
|
+
|
158
158
|
##
|
159
159
|
# Turn a constant with potential namespacing into an object
|
160
160
|
#
|
161
161
|
# @return [Class] class
|
162
|
-
|
162
|
+
|
163
163
|
def constantize(str)
|
164
164
|
names = str.split('::')
|
165
165
|
names.shift if names.empty? || names.first.empty?
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'mongoid'
|
2
|
+
|
3
|
+
module Navvy
|
4
|
+
class Job
|
5
|
+
include Mongoid::Document
|
6
|
+
include Mongoid::Timestamps
|
7
|
+
|
8
|
+
field :object, :type => String
|
9
|
+
field :method_name, :type => String
|
10
|
+
field :arguments, :type => String
|
11
|
+
field :priority, :type => Integer, :default => 0
|
12
|
+
field :return, :type => String
|
13
|
+
field :exception, :type => String
|
14
|
+
field :parent_id, :type => String
|
15
|
+
field :created_at, :type => Time
|
16
|
+
field :run_at, :type => Time
|
17
|
+
field :started_at, :type => Time
|
18
|
+
field :completed_at, :type => Time
|
19
|
+
field :failed_at, :type => Time
|
20
|
+
|
21
|
+
index [[:priority, Mongo::DESCENDING]]
|
22
|
+
index [[:created_at, Mongo::ASCENDING]]
|
23
|
+
|
24
|
+
##
|
25
|
+
# Add a job to the job queue.
|
26
|
+
#
|
27
|
+
# @param [Object] object the object you want to run a method from
|
28
|
+
# @param [Symbol, String] method_name the name of the method you want to
|
29
|
+
# run
|
30
|
+
# @param [*] arguments optional arguments you want to pass to the method
|
31
|
+
#
|
32
|
+
# @return [true, false]
|
33
|
+
|
34
|
+
def self.enqueue(object, method_name, *args)
|
35
|
+
options = {}
|
36
|
+
if args.last.is_a?(Hash)
|
37
|
+
options = args.last.delete(:job_options) || {}
|
38
|
+
args.pop if args.last.empty?
|
39
|
+
end
|
40
|
+
|
41
|
+
create(
|
42
|
+
:object => object.to_s,
|
43
|
+
:method_name => method_name.to_sym,
|
44
|
+
:arguments => args.to_yaml,
|
45
|
+
:priority => options[:priority] || 0,
|
46
|
+
:parent_id => options[:parent_id],
|
47
|
+
:run_at => options[:run_at] || Time.now
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Find the next available jobs in the queue. This will not include failed
|
53
|
+
# jobs (where :failed_at is not nil) and jobs that should run in the future
|
54
|
+
# (where :run_at is greater than the current time).
|
55
|
+
#
|
56
|
+
# @param [Integer] limit the limit of jobs to be fetched. Defaults to
|
57
|
+
# Navvy::Job.limit
|
58
|
+
#
|
59
|
+
# @return [array, nil] the next available jobs in an array or nil if no
|
60
|
+
# jobs were found.
|
61
|
+
|
62
|
+
def self.next(limit = self.limit)
|
63
|
+
where(:failed_at => nil).
|
64
|
+
where(:completed_at => nil).
|
65
|
+
where(:run_at.lte => Time.now).
|
66
|
+
order_by([[:priority, :desc], [:created_at, :asc]]).
|
67
|
+
limit(limit).to_a
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Clean up jobs that we don't need to keep anymore. If Navvy::Job.keep is
|
72
|
+
# false it'll delete every completed job, if it's a timestamp it'll only
|
73
|
+
# delete completed jobs that have passed their keeptime.
|
74
|
+
#
|
75
|
+
# @return [true, false] delete_all the result of the delete_all call
|
76
|
+
|
77
|
+
def self.cleanup
|
78
|
+
if keep.is_a? Fixnum
|
79
|
+
destroy_all(:conditions => { :completed_at.lte => keep.ago })
|
80
|
+
else
|
81
|
+
destroy_all(:conditions => { :completed_at.ne => nil }) unless keep?
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# Mark the job as started. Will set started_at to the current time.
|
87
|
+
#
|
88
|
+
# @return [true, false] update_attributes the result of the
|
89
|
+
# update_attributes call
|
90
|
+
|
91
|
+
def started
|
92
|
+
update_attributes(:started_at => Time.now)
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# Mark the job as completed. Will set completed_at to the current time and
|
97
|
+
# optionally add the return value if provided.
|
98
|
+
#
|
99
|
+
# @param [String] return_value the return value you want to store.
|
100
|
+
#
|
101
|
+
# @return [true, false] update_attributes the result of the
|
102
|
+
# update_attributes call
|
103
|
+
|
104
|
+
def completed(return_value = nil)
|
105
|
+
update_attributes(:completed_at => Time.now, :return => return_value)
|
106
|
+
end
|
107
|
+
|
108
|
+
##
|
109
|
+
# Mark the job as failed. Will set failed_at to the current time and
|
110
|
+
# optionally add the exception message if provided. Also, it will retry
|
111
|
+
# the job unless max_attempts has been reached.
|
112
|
+
#
|
113
|
+
# @param [String] exception the exception message you want to store.
|
114
|
+
#
|
115
|
+
# @return [true, false] update_attributes the result of the
|
116
|
+
# update_attributes call
|
117
|
+
|
118
|
+
def failed(message = nil)
|
119
|
+
self.retry unless times_failed >= self.class.max_attempts
|
120
|
+
update_attributes(:failed_at => Time.now, :exception => message)
|
121
|
+
end
|
122
|
+
|
123
|
+
##
|
124
|
+
# Check how many times the job has failed. Will try to find jobs with a
|
125
|
+
# parent_id that's the same as self.id and count them
|
126
|
+
#
|
127
|
+
# @return [Integer] count the amount of times the job has failed
|
128
|
+
|
129
|
+
def times_failed
|
130
|
+
i = parent_id || id
|
131
|
+
self.class.
|
132
|
+
where(:failed_at.ne => nil).
|
133
|
+
where("this._id == '#{i}' || this.parent_id == '#{i}'").
|
134
|
+
count
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
require File.expand_path(File.dirname(__FILE__) + '/../job')
|
data/lib/navvy/job/sequel.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'sequel'
|
3
2
|
require 'yaml'
|
4
3
|
|
@@ -48,7 +47,7 @@ module Navvy
|
|
48
47
|
def self.next(limit = self.limit)
|
49
48
|
filter(
|
50
49
|
(:run_at <= Time.now),
|
51
|
-
{:failed_at => nil,
|
50
|
+
{:failed_at => nil,
|
52
51
|
:completed_at => nil}
|
53
52
|
).order(:priority.desc, :created_at).first(limit)
|
54
53
|
end
|
data/lib/navvy/logger.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Navvy
|
4
|
+
class Logger < Logger
|
5
|
+
##
|
6
|
+
# Create a new logger. Works like Logger from Ruby's standard library, but
|
7
|
+
# defaults to STDOUT instead of failing. You can pass a filename to log to.
|
8
|
+
#
|
9
|
+
# @param [String] logdev a filename to log to, defaults to STDOUT
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# logger = Navvy::Logger.new
|
13
|
+
# logger = Navvy::Logger.new('~/file.log')
|
14
|
+
|
15
|
+
def initialize(logdev = STDOUT)
|
16
|
+
super logdev
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Send colored logs to the logger. Will only colorize output sent to
|
21
|
+
# STDOUT and will call the regular info method when writing to file.
|
22
|
+
#
|
23
|
+
# @param [String] message the message you want to log
|
24
|
+
# @param [String] color the color code you want to use to color your
|
25
|
+
# message
|
26
|
+
#
|
27
|
+
# @example
|
28
|
+
# logger = Navvy::Logger.new
|
29
|
+
# logger.colorized_info "I'm green!", 32
|
30
|
+
|
31
|
+
def colorized_info(message, color)
|
32
|
+
unless @logdev.filename
|
33
|
+
return info("\e[#{color}m#{message}\e[0m")
|
34
|
+
end
|
35
|
+
info(message)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/navvy/tasks.rb
CHANGED
data/lib/navvy/worker.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'daemons'
|
3
|
-
|
4
1
|
module Navvy
|
5
2
|
class Worker
|
6
3
|
class << self
|
@@ -20,15 +17,15 @@ module Navvy
|
|
20
17
|
# Start the worker.
|
21
18
|
|
22
19
|
def self.start
|
23
|
-
Navvy
|
24
|
-
trap('TERM') { Navvy
|
25
|
-
trap('INT') { Navvy
|
20
|
+
Navvy.logger.info '*** Starting ***'
|
21
|
+
trap('TERM') { Navvy.logger.info '*** Exiting ***'; $exit = true }
|
22
|
+
trap('INT') { Navvy.logger.info '*** Exiting ***'; $exit = true }
|
26
23
|
|
27
24
|
loop do
|
28
25
|
fetch_and_run_jobs
|
29
26
|
|
30
27
|
if $exit
|
31
|
-
Navvy
|
28
|
+
Navvy.logger.info '*** Cleaning up ***'
|
32
29
|
Navvy::Job.cleanup
|
33
30
|
break
|
34
31
|
end
|
@@ -42,41 +39,12 @@ module Navvy
|
|
42
39
|
def self.fetch_and_run_jobs
|
43
40
|
Job.next.each do |job|
|
44
41
|
result = job.run
|
45
|
-
Navvy
|
42
|
+
Navvy.logger.colorized_info(
|
46
43
|
"* #{job.object.to_s}.#{job.method_name}" <<
|
47
44
|
"(#{job.args.join(', ')}) => #{(job.exception || result).to_s}",
|
48
45
|
job.failed? ? 31 : 32
|
49
46
|
)
|
50
47
|
end
|
51
48
|
end
|
52
|
-
|
53
|
-
##
|
54
|
-
# Daemonize the worker
|
55
|
-
|
56
|
-
def self.daemonize(*args)
|
57
|
-
if defined?(ActiveRecord)
|
58
|
-
# Sets ActiveRecord's logger to Navvy a new Logger instance
|
59
|
-
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
60
|
-
end
|
61
|
-
|
62
|
-
# If #daemonize does not receive any arguments, the options variable will
|
63
|
-
# contain an empty hash, and the ARGV of the environment will be used instead
|
64
|
-
# of the :ARGV options from Daemons#run_proc. However, if the *args param has been set
|
65
|
-
# this will be used instead of the environment's ARGV for the Daemons.
|
66
|
-
options = args.empty? ? {} : {:ARGV => args}
|
67
|
-
|
68
|
-
# Finally, the directory store mode will be set to normal and the Daemons PID file
|
69
|
-
# will be stored inside tmp/pids of the application.
|
70
|
-
options.merge!({:dir_mode => :normal, :dir => 'tmp/pids'})
|
71
|
-
|
72
|
-
# Ensures that the tmp/pids folder exists so that the process id file can properly be stored
|
73
|
-
%x(mkdir -p tmp/pids)
|
74
|
-
|
75
|
-
# Runs the Navvy Worker inside a Daemon
|
76
|
-
Daemons.run_proc('navvy', options) do
|
77
|
-
Navvy::Worker.start
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
49
|
end
|
82
50
|
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -5,81 +5,64 @@ describe Navvy::Configuration do
|
|
5
5
|
Navvy.configure do |config|
|
6
6
|
config.job_limit = 100
|
7
7
|
config.keep_jobs = false
|
8
|
-
config.logger =
|
9
|
-
config.quiet = true
|
8
|
+
config.logger = Navvy::Logger.new('/dev/null')
|
10
9
|
config.sleep_time = 5
|
11
10
|
end
|
12
11
|
end
|
13
|
-
|
12
|
+
|
14
13
|
it 'should have a job limit of 100 by default' do
|
15
14
|
Navvy::Job.limit.should == 100
|
16
15
|
end
|
17
|
-
|
16
|
+
|
18
17
|
it 'should set the job limit' do
|
19
18
|
Navvy.configure do |config|
|
20
19
|
config.job_limit = 10
|
21
20
|
end
|
22
|
-
|
21
|
+
|
23
22
|
Navvy::Job.limit.should == 10
|
24
23
|
end
|
25
|
-
|
24
|
+
|
26
25
|
it 'should have keep_jobs off by default' do
|
27
26
|
Navvy::Job.keep.should == false
|
28
27
|
end
|
29
|
-
|
28
|
+
|
30
29
|
it 'should set keep_jobs' do
|
31
30
|
Navvy.configure do |config|
|
32
31
|
config.keep_jobs = 10
|
33
32
|
end
|
34
|
-
|
33
|
+
|
35
34
|
Navvy::Job.keep.should == 10
|
36
35
|
end
|
37
|
-
|
38
|
-
it 'should
|
39
|
-
Navvy::Log.logger.should == nil
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should set the keep_jobs' do
|
43
|
-
Navvy.configure do |config|
|
44
|
-
config.logger = :rails
|
45
|
-
end
|
46
|
-
|
47
|
-
Navvy::Log.logger.should == :rails
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should be quiet in the specs' do
|
51
|
-
Navvy::Log.quiet.should == true
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'should turn quiet off' do
|
36
|
+
|
37
|
+
it 'should set the logger' do
|
55
38
|
Navvy.configure do |config|
|
56
|
-
config.
|
39
|
+
config.logger = Navvy::Logger.new
|
57
40
|
end
|
58
|
-
|
59
|
-
Navvy
|
41
|
+
|
42
|
+
Navvy.logger.instance_variable_get(:@logdev).filename.should == nil
|
60
43
|
end
|
61
|
-
|
44
|
+
|
62
45
|
it 'should have a default sleep time of 5' do
|
63
46
|
Navvy::Worker.sleep_time.should == 5
|
64
47
|
end
|
65
|
-
|
48
|
+
|
66
49
|
it 'should turn quiet off' do
|
67
50
|
Navvy.configure do |config|
|
68
51
|
config.sleep_time = 10
|
69
52
|
end
|
70
|
-
|
53
|
+
|
71
54
|
Navvy::Worker.sleep_time.should == 10
|
72
55
|
end
|
73
|
-
|
56
|
+
|
74
57
|
it 'should have a default max_attempts of 25' do
|
75
58
|
Navvy::Job.max_attempts.should == 25
|
76
59
|
end
|
77
|
-
|
60
|
+
|
78
61
|
it 'should set max_attempts to 15' do
|
79
62
|
Navvy.configure do |config|
|
80
63
|
config.max_attempts = 15
|
81
|
-
end
|
82
|
-
|
64
|
+
end
|
65
|
+
|
83
66
|
Navvy::Job.max_attempts.should == 15
|
84
67
|
end
|
85
|
-
end
|
68
|
+
end
|
data/spec/job_spec.rb
CHANGED
@@ -40,7 +40,7 @@ describe 'Navvy::Job' do
|
|
40
40
|
|
41
41
|
describe '.enqueue' do
|
42
42
|
before(:each) do
|
43
|
-
|
43
|
+
Navvy::Job.delete_all
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should enqueue a job' do
|
@@ -91,7 +91,7 @@ describe 'Navvy::Job' do
|
|
91
91
|
|
92
92
|
describe '.next' do
|
93
93
|
before(:each) do
|
94
|
-
|
94
|
+
Navvy::Job.delete_all
|
95
95
|
Navvy::Job.create(
|
96
96
|
:object => 'Cow',
|
97
97
|
:method_name => :last,
|
@@ -122,7 +122,7 @@ describe 'Navvy::Job' do
|
|
122
122
|
|
123
123
|
it 'should find the next 10 available jobs' do
|
124
124
|
jobs = Navvy::Job.next
|
125
|
-
jobs.
|
125
|
+
jobs.length.should == 100
|
126
126
|
jobs.each do |job|
|
127
127
|
job.should be_instance_of Navvy::Job
|
128
128
|
job.method_name.to_s.should == 'speak'
|
@@ -130,18 +130,18 @@ describe 'Navvy::Job' do
|
|
130
130
|
end
|
131
131
|
|
132
132
|
it 'should find the next 2 available jobs' do
|
133
|
-
Navvy::Job.next(2).
|
133
|
+
Navvy::Job.next(2).length.should == 2
|
134
134
|
end
|
135
135
|
|
136
136
|
it 'should find the next 4 available jobs' do
|
137
137
|
Navvy::Job.limit = 4
|
138
|
-
Navvy::Job.next.
|
138
|
+
Navvy::Job.next.length.should == 4
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
142
|
describe '.cleanup' do
|
143
143
|
before(:each) do
|
144
|
-
|
144
|
+
Navvy::Job.delete_all
|
145
145
|
Navvy::Job.create(
|
146
146
|
:object => 'Cow',
|
147
147
|
:method_name => :speak,
|
@@ -186,7 +186,7 @@ describe 'Navvy::Job' do
|
|
186
186
|
|
187
187
|
describe '#run' do
|
188
188
|
it 'should pass the arguments' do
|
189
|
-
|
189
|
+
Navvy::Job.delete_all
|
190
190
|
job = Navvy::Job.enqueue(Cow, :name, 'Betsy')
|
191
191
|
Cow.should_receive(:name).with('Betsy')
|
192
192
|
job.run
|
@@ -194,7 +194,7 @@ describe 'Navvy::Job' do
|
|
194
194
|
|
195
195
|
describe 'when everything goes well' do
|
196
196
|
before(:each) do
|
197
|
-
|
197
|
+
Navvy::Job.delete_all
|
198
198
|
Navvy::Job.enqueue(Cow, :speak)
|
199
199
|
Navvy::Job.keep = false
|
200
200
|
end
|
@@ -235,7 +235,7 @@ describe 'Navvy::Job' do
|
|
235
235
|
|
236
236
|
describe 'when a job fails' do
|
237
237
|
before(:each) do
|
238
|
-
|
238
|
+
Navvy::Job.delete_all
|
239
239
|
Navvy::Job.enqueue(Cow, :broken)
|
240
240
|
end
|
241
241
|
|
@@ -251,7 +251,7 @@ describe 'Navvy::Job' do
|
|
251
251
|
|
252
252
|
describe '#started' do
|
253
253
|
before(:each) do
|
254
|
-
|
254
|
+
Navvy::Job.delete_all
|
255
255
|
Navvy::Job.enqueue(Cow, :speak)
|
256
256
|
end
|
257
257
|
|
@@ -264,7 +264,7 @@ describe 'Navvy::Job' do
|
|
264
264
|
|
265
265
|
describe '#completed' do
|
266
266
|
before(:each) do
|
267
|
-
|
267
|
+
Navvy::Job.delete_all
|
268
268
|
Navvy::Job.enqueue(Cow, :speak)
|
269
269
|
end
|
270
270
|
|
@@ -283,7 +283,7 @@ describe 'Navvy::Job' do
|
|
283
283
|
|
284
284
|
describe '#failed' do
|
285
285
|
before(:each) do
|
286
|
-
|
286
|
+
Navvy::Job.delete_all
|
287
287
|
Navvy::Job.enqueue(Cow, :speak)
|
288
288
|
end
|
289
289
|
|
@@ -323,7 +323,7 @@ describe 'Navvy::Job' do
|
|
323
323
|
|
324
324
|
describe '#retry' do
|
325
325
|
before(:each) do
|
326
|
-
|
326
|
+
Navvy::Job.delete_all
|
327
327
|
end
|
328
328
|
|
329
329
|
it 'should enqueue a child for the failed job' do
|
@@ -388,7 +388,7 @@ describe 'Navvy::Job' do
|
|
388
388
|
|
389
389
|
describe '#times_failed' do
|
390
390
|
before(:each) do
|
391
|
-
|
391
|
+
Navvy::Job.delete_all
|
392
392
|
@failed_job = Navvy::Job.create(
|
393
393
|
:failed_at => Time.now
|
394
394
|
)
|
data/spec/logger_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Navvy::Logger do
|
4
|
+
describe '#colorized_info' do
|
5
|
+
describe 'when logging to STDOUT' do
|
6
|
+
it 'should use the provided colors' do
|
7
|
+
logger = Navvy::Logger.new
|
8
|
+
logger.should_not_receive(:info).with('colors!')
|
9
|
+
logger.should_receive(:info).with("\e[32mcolors!\e[0m")
|
10
|
+
logger.colorized_info 'colors!', 32
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'when logging to a file' do
|
15
|
+
it 'should not use the provided colors' do
|
16
|
+
logger = Navvy::Logger.new('/dev/null')
|
17
|
+
logger.should_receive(:info).with('colors!')
|
18
|
+
logger.should_not_receive(:info).with("\e[32mcolors!\e[0m")
|
19
|
+
logger.colorized_info 'colors!', 32
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/setup/active_record.rb
CHANGED
data/spec/setup/sequel.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -7,16 +7,6 @@ require 'spec/autorun'
|
|
7
7
|
Spec::Runner.configure do |config|
|
8
8
|
end
|
9
9
|
|
10
|
-
def delete_all_jobs
|
11
|
-
if defined? Navvy::Job.delete_all
|
12
|
-
Navvy::Job.delete_all
|
13
|
-
elsif defined? Navvy::Job.all.destroy
|
14
|
-
Navvy::Job.all.destroy
|
15
|
-
else
|
16
|
-
Navvy::Job.delete
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
10
|
def job_count
|
21
11
|
if defined? Navvy::Job.count
|
22
12
|
Navvy::Job.count
|
@@ -50,7 +40,3 @@ module Animals
|
|
50
40
|
end
|
51
41
|
end
|
52
42
|
end
|
53
|
-
|
54
|
-
Navvy.configure do |config|
|
55
|
-
config.quiet = true
|
56
|
-
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jeff Kreeftmeijer
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-06-28 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -45,97 +45,49 @@ dependencies:
|
|
45
45
|
version: 0.5.2
|
46
46
|
type: :development
|
47
47
|
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: sequel
|
50
|
-
prerelease: false
|
51
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
segments:
|
56
|
-
- 3
|
57
|
-
- 8
|
58
|
-
- 0
|
59
|
-
version: 3.8.0
|
60
|
-
type: :development
|
61
|
-
version_requirements: *id003
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: sqlite3-ruby
|
64
|
-
prerelease: false
|
65
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - ">="
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
segments:
|
70
|
-
- 1
|
71
|
-
- 2
|
72
|
-
- 5
|
73
|
-
version: 1.2.5
|
74
|
-
type: :development
|
75
|
-
version_requirements: *id004
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
|
-
name: daemons
|
78
|
-
prerelease: false
|
79
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - ">="
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
segments:
|
84
|
-
- 1
|
85
|
-
- 0
|
86
|
-
- 10
|
87
|
-
version: 1.0.10
|
88
|
-
type: :runtime
|
89
|
-
version_requirements: *id005
|
90
48
|
description: Simple background job processor inspired by delayed_job, but aiming for database agnosticism.
|
91
49
|
email: jeff@kreeftmeijer.nl
|
92
50
|
executables: []
|
93
51
|
|
94
52
|
extensions: []
|
95
53
|
|
96
|
-
extra_rdoc_files:
|
97
|
-
|
98
|
-
- README.textile
|
54
|
+
extra_rdoc_files: []
|
55
|
+
|
99
56
|
files:
|
100
|
-
- .document
|
101
|
-
- .gitignore
|
102
|
-
- LICENSE
|
103
|
-
- README.textile
|
104
|
-
- Rakefile
|
105
|
-
- VERSION
|
106
57
|
- generators/navvy/navvy_generator.rb
|
107
|
-
- generators/navvy/templates/
|
108
|
-
- generators/navvy/templates/
|
58
|
+
- generators/navvy/templates/active_record_migration.rb
|
59
|
+
- generators/navvy/templates/sequel_migration.rb
|
109
60
|
- lib/generators/navvy_generator.rb
|
110
|
-
- lib/navvy.rb
|
111
61
|
- lib/navvy/configuration.rb
|
112
|
-
- lib/navvy/job.rb
|
113
62
|
- lib/navvy/job/active_record.rb
|
114
63
|
- lib/navvy/job/data_mapper.rb
|
115
64
|
- lib/navvy/job/mongo_mapper.rb
|
65
|
+
- lib/navvy/job/mongoid.rb
|
116
66
|
- lib/navvy/job/sequel.rb
|
117
|
-
- lib/navvy/
|
67
|
+
- lib/navvy/job.rb
|
68
|
+
- lib/navvy/logger.rb
|
118
69
|
- lib/navvy/tasks.rb
|
119
70
|
- lib/navvy/worker.rb
|
120
|
-
- navvy.
|
71
|
+
- lib/navvy.rb
|
121
72
|
- spec/configuration_spec.rb
|
122
73
|
- spec/job_spec.rb
|
123
|
-
- spec/
|
74
|
+
- spec/logger_spec.rb
|
124
75
|
- spec/setup/active_record.rb
|
125
76
|
- spec/setup/data_mapper.rb
|
126
|
-
- spec/setup/justlogging.rb
|
127
77
|
- spec/setup/mongo_mapper.rb
|
128
|
-
- spec/setup/
|
78
|
+
- spec/setup/mongoid.rb
|
129
79
|
- spec/setup/sequel.rb
|
130
80
|
- spec/spec_helper.rb
|
131
81
|
- spec/worker_spec.rb
|
82
|
+
- README.textile
|
83
|
+
- LICENSE
|
132
84
|
has_rdoc: true
|
133
85
|
homepage: http://github.com/jeffkreeftmeijer/navvy
|
134
86
|
licenses: []
|
135
87
|
|
136
88
|
post_install_message:
|
137
|
-
rdoc_options:
|
138
|
-
|
89
|
+
rdoc_options: []
|
90
|
+
|
139
91
|
require_paths:
|
140
92
|
- lib
|
141
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -159,15 +111,5 @@ rubygems_version: 1.3.6
|
|
159
111
|
signing_key:
|
160
112
|
specification_version: 3
|
161
113
|
summary: Simple background job processor inspired by delayed_job, but aiming for database agnosticism.
|
162
|
-
test_files:
|
163
|
-
|
164
|
-
- spec/job_spec.rb
|
165
|
-
- spec/log_spec.rb
|
166
|
-
- spec/setup/active_record.rb
|
167
|
-
- spec/setup/data_mapper.rb
|
168
|
-
- spec/setup/justlogging.rb
|
169
|
-
- spec/setup/mongo_mapper.rb
|
170
|
-
- spec/setup/rails_default_logger.rb
|
171
|
-
- spec/setup/sequel.rb
|
172
|
-
- spec/spec_helper.rb
|
173
|
-
- spec/worker_spec.rb
|
114
|
+
test_files: []
|
115
|
+
|
data/.document
DELETED
data/.gitignore
DELETED
data/Rakefile
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "navvy"
|
8
|
-
gem.summary = %Q{Simple background job processor inspired by delayed_job, but aiming for database agnosticism.}
|
9
|
-
gem.description = %Q{Simple background job processor inspired by delayed_job, but aiming for database agnosticism.}
|
10
|
-
gem.email = "jeff@kreeftmeijer.nl"
|
11
|
-
gem.homepage = "http://github.com/jeffkreeftmeijer/navvy"
|
12
|
-
gem.authors = ["Jeff Kreeftmeijer"]
|
13
|
-
|
14
|
-
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
-
gem.add_development_dependency "yard", ">= 0.5.2"
|
16
|
-
gem.add_development_dependency "sequel", ">= 3.8.0"
|
17
|
-
gem.add_development_dependency "sqlite3-ruby", ">= 1.2.5"
|
18
|
-
gem.add_dependency "daemons", ">= 1.0.10"
|
19
|
-
end
|
20
|
-
Jeweler::GemcutterTasks.new
|
21
|
-
rescue LoadError
|
22
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
23
|
-
end
|
24
|
-
|
25
|
-
require 'spec/rake/spectask'
|
26
|
-
|
27
|
-
task :spec do
|
28
|
-
['spec:active_record', 'spec:mongo_mapper', 'spec:sequel', 'spec:data_mapper'].each do |spec|
|
29
|
-
Rake::Task[spec].invoke
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
namespace :spec do
|
34
|
-
Spec::Rake::SpecTask.new(:active_record) do |spec|
|
35
|
-
spec.spec_files = FileList['spec/setup/active_record.rb', 'spec/*_spec.rb']
|
36
|
-
end
|
37
|
-
|
38
|
-
Spec::Rake::SpecTask.new(:mongo_mapper) do |spec|
|
39
|
-
spec.spec_files = FileList['spec/setup/mongo_mapper.rb', 'spec/*_spec.rb']
|
40
|
-
end
|
41
|
-
|
42
|
-
Spec::Rake::SpecTask.new(:sequel) do |spec|
|
43
|
-
spec.spec_files = FileList['spec/setup/sequel.rb', 'spec/*_spec.rb']
|
44
|
-
end
|
45
|
-
|
46
|
-
Spec::Rake::SpecTask.new(:data_mapper) do |spec|
|
47
|
-
spec.spec_files = FileList['spec/setup/data_mapper.rb', 'spec/*_spec.rb']
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
52
|
-
spec.libs << 'lib' << 'spec'
|
53
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
54
|
-
spec.rcov = true
|
55
|
-
end
|
56
|
-
|
57
|
-
task :spec => :check_dependencies
|
58
|
-
task :default => :spec
|
59
|
-
|
60
|
-
begin
|
61
|
-
require 'yard'
|
62
|
-
YARD::Rake::YardocTask.new
|
63
|
-
rescue LoadError
|
64
|
-
task :yardoc do
|
65
|
-
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
66
|
-
end
|
67
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.5
|
data/lib/navvy/log.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
module Navvy
|
2
|
-
class Log
|
3
|
-
class << self
|
4
|
-
attr_writer :logger
|
5
|
-
attr_accessor :quiet
|
6
|
-
end
|
7
|
-
|
8
|
-
class LoggerNotFound < StandardError; end
|
9
|
-
|
10
|
-
##
|
11
|
-
# Default logger
|
12
|
-
#
|
13
|
-
# @return [Symbol, nil] logger
|
14
|
-
|
15
|
-
def self.logger
|
16
|
-
@logger || Navvy.configuration.logger
|
17
|
-
end
|
18
|
-
|
19
|
-
##
|
20
|
-
# Be quiet?
|
21
|
-
#
|
22
|
-
# @return [true, false] quiet
|
23
|
-
|
24
|
-
def self.quiet
|
25
|
-
@quiet || Navvy.configuration.quiet
|
26
|
-
end
|
27
|
-
|
28
|
-
##
|
29
|
-
# Pass a log to the logger. It will check if self.logger is an array. If it
|
30
|
-
# is, it'll loop through it and log to every logger. If it's not, it'll
|
31
|
-
# just log once.
|
32
|
-
#
|
33
|
-
# @param [String] message the message you want to log
|
34
|
-
# @param [Integer] color an optional color code to use in the terminal
|
35
|
-
# output
|
36
|
-
|
37
|
-
def self.info(message, color = nil)
|
38
|
-
if logger.is_a? Array
|
39
|
-
logger.each do |logger|
|
40
|
-
write(logger, message, color)
|
41
|
-
end
|
42
|
-
else
|
43
|
-
write(logger, message, color)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
##
|
48
|
-
# Actually write the log to the logger. It'll check self.logger and use
|
49
|
-
# that to define a logger
|
50
|
-
#
|
51
|
-
# @param [Symbol] logger the logger you want to use
|
52
|
-
# @param [String] message the message you want to log
|
53
|
-
# @param [Integer] color an optional color code to use in the terminal
|
54
|
-
# output
|
55
|
-
|
56
|
-
def self.write(logger, message, color = nil)
|
57
|
-
puts "\e[#{color}m#{message}\e[0m" unless quiet
|
58
|
-
case logger
|
59
|
-
when :justlogging
|
60
|
-
raise(
|
61
|
-
LoggerNotFound,
|
62
|
-
'JustLogging could not be found. No logs were created.'
|
63
|
-
) unless defined? Justlogging.log
|
64
|
-
Justlogging.log(message)
|
65
|
-
when :rails
|
66
|
-
raise(
|
67
|
-
LoggerNotFound,
|
68
|
-
'Rails.logger could not be found. No logs were created.'
|
69
|
-
) unless defined? Rails.logger.info
|
70
|
-
Rails.logger.info(message)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/navvy.gemspec
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{navvy}
|
8
|
-
s.version = "0.2.5"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Jeff Kreeftmeijer"]
|
12
|
-
s.date = %q{2010-05-29}
|
13
|
-
s.description = %q{Simple background job processor inspired by delayed_job, but aiming for database agnosticism.}
|
14
|
-
s.email = %q{jeff@kreeftmeijer.nl}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.textile"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.textile",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"generators/navvy/navvy_generator.rb",
|
27
|
-
"generators/navvy/templates/migration.rb",
|
28
|
-
"generators/navvy/templates/script",
|
29
|
-
"lib/generators/navvy_generator.rb",
|
30
|
-
"lib/navvy.rb",
|
31
|
-
"lib/navvy/configuration.rb",
|
32
|
-
"lib/navvy/job.rb",
|
33
|
-
"lib/navvy/job/active_record.rb",
|
34
|
-
"lib/navvy/job/data_mapper.rb",
|
35
|
-
"lib/navvy/job/mongo_mapper.rb",
|
36
|
-
"lib/navvy/job/sequel.rb",
|
37
|
-
"lib/navvy/log.rb",
|
38
|
-
"lib/navvy/tasks.rb",
|
39
|
-
"lib/navvy/worker.rb",
|
40
|
-
"navvy.gemspec",
|
41
|
-
"spec/configuration_spec.rb",
|
42
|
-
"spec/job_spec.rb",
|
43
|
-
"spec/log_spec.rb",
|
44
|
-
"spec/setup/active_record.rb",
|
45
|
-
"spec/setup/data_mapper.rb",
|
46
|
-
"spec/setup/justlogging.rb",
|
47
|
-
"spec/setup/mongo_mapper.rb",
|
48
|
-
"spec/setup/rails_default_logger.rb",
|
49
|
-
"spec/setup/sequel.rb",
|
50
|
-
"spec/spec_helper.rb",
|
51
|
-
"spec/worker_spec.rb"
|
52
|
-
]
|
53
|
-
s.homepage = %q{http://github.com/jeffkreeftmeijer/navvy}
|
54
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
55
|
-
s.require_paths = ["lib"]
|
56
|
-
s.rubygems_version = %q{1.3.6}
|
57
|
-
s.summary = %q{Simple background job processor inspired by delayed_job, but aiming for database agnosticism.}
|
58
|
-
s.test_files = [
|
59
|
-
"spec/configuration_spec.rb",
|
60
|
-
"spec/job_spec.rb",
|
61
|
-
"spec/log_spec.rb",
|
62
|
-
"spec/setup/active_record.rb",
|
63
|
-
"spec/setup/data_mapper.rb",
|
64
|
-
"spec/setup/justlogging.rb",
|
65
|
-
"spec/setup/mongo_mapper.rb",
|
66
|
-
"spec/setup/rails_default_logger.rb",
|
67
|
-
"spec/setup/sequel.rb",
|
68
|
-
"spec/spec_helper.rb",
|
69
|
-
"spec/worker_spec.rb"
|
70
|
-
]
|
71
|
-
|
72
|
-
if s.respond_to? :specification_version then
|
73
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
74
|
-
s.specification_version = 3
|
75
|
-
|
76
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
77
|
-
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
78
|
-
s.add_development_dependency(%q<yard>, [">= 0.5.2"])
|
79
|
-
s.add_development_dependency(%q<sequel>, [">= 3.8.0"])
|
80
|
-
s.add_development_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
|
81
|
-
s.add_runtime_dependency(%q<daemons>, [">= 1.0.10"])
|
82
|
-
else
|
83
|
-
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
84
|
-
s.add_dependency(%q<yard>, [">= 0.5.2"])
|
85
|
-
s.add_dependency(%q<sequel>, [">= 3.8.0"])
|
86
|
-
s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
|
87
|
-
s.add_dependency(%q<daemons>, [">= 1.0.10"])
|
88
|
-
end
|
89
|
-
else
|
90
|
-
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
91
|
-
s.add_dependency(%q<yard>, [">= 0.5.2"])
|
92
|
-
s.add_dependency(%q<sequel>, [">= 3.8.0"])
|
93
|
-
s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
|
94
|
-
s.add_dependency(%q<daemons>, [">= 1.0.10"])
|
95
|
-
end
|
96
|
-
end
|
data/spec/log_spec.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
class LoggerNotFound < StandardError; end
|
4
|
-
|
5
|
-
describe Navvy::Log do
|
6
|
-
describe '.info' do
|
7
|
-
describe 'when using the rails default logger' do
|
8
|
-
before do
|
9
|
-
Navvy::Log.logger = :rails
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should raise an error when the logger can not be found' do
|
13
|
-
lambda { Navvy::Log.info('123') }.should raise_error
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should pass the log to Rails.logger' do
|
17
|
-
require File.expand_path(File.dirname(__FILE__) + '/setup/rails_default_logger')
|
18
|
-
Rails.logger.should_receive(:info).with('123')
|
19
|
-
Navvy::Log.info('123')
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'when using justlogging' do
|
24
|
-
before do
|
25
|
-
Navvy::Log.logger = :justlogging
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should raise an error when the logger can not be found' do
|
29
|
-
lambda { Navvy::Log.info('123') }.should raise_error
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should pass the log to justlogging' do
|
33
|
-
require File.expand_path(File.dirname(__FILE__) + '/setup/justlogging')
|
34
|
-
Justlogging.should_receive(:log).with('123')
|
35
|
-
Navvy::Log.info('123')
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'when using both the rails default logger and justlogging' do
|
40
|
-
before do
|
41
|
-
Navvy::Log.logger = [:rails, :justlogging]
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should pass the log to justlogging' do
|
45
|
-
Rails.logger.should_receive(:info).with('123')
|
46
|
-
Justlogging.should_receive(:log).with('123')
|
47
|
-
Navvy::Log.info('123')
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe 'when not using any logger' do
|
52
|
-
before do
|
53
|
-
Navvy::Log.logger = nil
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should not log' do
|
57
|
-
Rails.logger.should_not_receive(:info)
|
58
|
-
Justlogging.should_not_receive(:log)
|
59
|
-
Navvy::Log.info('123')
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/spec/setup/justlogging.rb
DELETED