Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ Starting out with conversion to YARD

  • Loading branch information...
commit eaedc07f7bc8b6a6dc8fbef2256f64ab29cfa089 1 parent f393d3b
@kschiess authored
View
1  .gitignore
@@ -1,3 +1,4 @@
+.yardoc
.bundle
pkg
rdoc
View
1  .yardopts
@@ -0,0 +1 @@
+--no-private
View
35 lib/procrastinate/implicit.rb
@@ -2,57 +2,58 @@
require 'procrastinate'
module Procrastinate
- # call-seq:
- # Procrastinate.scheduler => scheduler
- #
# Returns the scheduler instance. When using procrastinate/implicit, there
# is one global scheduler to your ruby process, this one.
+ #
+ # @return [Scheduler] singleton scheduler for implicit scheduling.
#
def scheduler
@scheduler ||= Scheduler.start
end
module_function :scheduler
- # call-seq:
- # Procrastinate.proxy(obj) => proxy
- #
# Creates a proxy that will execute methods called on obj in a child process.
#
- # Example:
- #
+ # @example
# proxy = Procrastinate.proxy("foo")
# r = proxy += "bar"
# r.value # => 'foobar'
#
+ # @param obj [Object] Ruby object that the calls need to be proxied to
+ # @return [Proxy] proxy object that will execute method calls in child
+ # processes
+ #
def proxy(obj)
scheduler.proxy(obj)
end
module_function :proxy
- # call-seq:
- # Procrastinate.schedule { some_work }
- #
# Schedules a block to be executed in its own thread. Returns the future that
# will return the blocks return value.
#
+ # @example
+ # r = Procrastinate.schedule { do_some_work }
+ # r.value # => the blocks return value
+ #
+ # @param block [Proc] block that will be executed in a child process
+ # @return [Task::Result] a promise for the blocks return value
+ #
def schedule(&block)
scheduler.schedule(&block)
end
module_function :schedule
- # call-seq:
- # Procrastinate.join
- #
# Waits for all currently scheduled tasks to complete. This is like calling
# #value on all result objects, except that nothing is returned.
#
- # Example:
- #
+ # @example
# proxy = Procrastinate.proxy("foo")
# r = proxy += "bar"
# Procrastinate.join
# r.ready? # => true
#
+ # @return [void]
+ #
def join
scheduler.join
end
@@ -62,6 +63,8 @@ def join
# since it consumes almost no resources when not active. This is mainly
# useful in tests to achieve isolation.
#
+ # @private
+ #
def shutdown
scheduler.shutdown
end
View
28 lib/procrastinate/scheduler.rb
@@ -9,10 +9,14 @@
# in this class.
#
class Procrastinate::Scheduler
+ # Process manager associated with this scheduler
attr_reader :manager
+ # Schedule strategy associated with this scheduler
attr_reader :strategy
+ # Task queue
attr_reader :task_queue
+ # @see Scheduler.start
def initialize(strategy)
@strategy = strategy || Procrastinate::SpawnStrategy::Default.new
@manager = Procrastinate::ProcessManager.new
@@ -24,7 +28,11 @@ def initialize(strategy)
@task_queue = Queue.new
end
- # Starts a new scheduler
+ # Starts a new scheduler.
+ #
+ # @param strategy [SpawnStrategy] strategy to use when spawning new processes.
+ # Will default to {SpawnStrategy::Default}.
+ # @return [Scheduler]
#
def self.start(strategy=nil)
new(strategy).
@@ -37,11 +45,13 @@ def start
# Returns a proxy for the +worker+ instance that will allow executing its
# methods in a new process.
#
- # Example:
- #
+ # @example
# proxy = scheduler.proxy(worker)
# status = proxy.do_some_work # will execute later and in its own process
#
+ # @param worker [Object] Ruby object that executes the work
+ # @return [Proxy]
+ #
def proxy(worker)
return Procrastinate::Proxy.new(worker, self)
end
@@ -50,6 +60,8 @@ def proxy(worker)
# used inside task execution processes; If you call it from your main
# process, the result is undefined.
#
+ # @return [Runtime]
+ #
def runtime
Procrastinate::Runtime.new
end
@@ -57,6 +69,16 @@ def runtime
# Called by the proxy to schedule work. You can implement your own Task
# classes; the relevant interface consists of only a #run method.
#
+ # @overload schedule(task=nil)
+ # Runs task in its own worker process.
+ # @param task [#run] task to be run in its own worker process
+ # @return [Task::Result]
+ #
+ # @overload schedule(&block)
+ # Executes the Ruby block in its own worker process.
+ # @param block [Proc] block to be executed in worker process
+ # @return [Task::Result]
+ #
def schedule(task=nil, &block)
fail "Shutting down..." if @state != :running
View
2  lib/procrastinate/task/callable.rb
@@ -2,7 +2,7 @@
require 'procrastinate/task/result'
module Procrastinate::Task
- # Calls the block and returns the result of execution.
+ # A task that calls the block and returns the result of execution.
#
class Callable
attr_reader :block
Please sign in to comment.
Something went wrong with that request. Please try again.