Module: Procrastinate

Defined in:
lib/procrastinate.rb,
lib/procrastinate/server.rb,
lib/procrastinate/implicit.rb

Defined Under Namespace

Modules: SpawnStrategy, Task, Utils Classes: ChildDeath, Lock, ProcessManager, Proxy, Runtime, Scheduler, Server

Class Method Summary collapse

Class Method Details

.joinvoid

This method returns an undefined value.

Waits for all currently scheduled tasks to complete. This is like calling #value on all result objects, except that nothing is returned.

Examples:

proxy = Procrastinate.proxy("foo")
r     = proxy += "bar"
Procrastinate.join
r.ready? # => true


57
58
59
# File 'lib/procrastinate/implicit.rb', line 57

def join
  scheduler.join
end

.proxy(obj) ⇒ Proxy

Creates a proxy that will execute methods called on obj in a child process.

Examples:

proxy = Procrastinate.proxy("foo")
r     = proxy += "bar"
r.value   # => 'foobar'

Parameters:

  • obj (Object)

    Ruby object that the calls need to be proxied to

Returns:

  • (Proxy)

    proxy object that will execute method calls in child processes



26
27
28
# File 'lib/procrastinate/implicit.rb', line 26

def proxy(obj)
  scheduler.proxy(obj)
end

.resetObject

Resets the implicit scheduler. Please use this only in tests, not in production code.



76
77
78
79
# File 'lib/procrastinate/implicit.rb', line 76

def reset
  scheduler.shutdown
  @scheduler = nil
end

.schedule(&block) ⇒ Task::Result

Schedules a block to be executed in its own thread. Returns the future that will return the blocks return value.

Examples:

r = Procrastinate.schedule { do_some_work }
r.value                                     # => the blocks return value

Parameters:

  • block (Proc)

    block that will be executed in a child process

Returns:



41
42
43
# File 'lib/procrastinate/implicit.rb', line 41

def schedule(&block)
  scheduler.schedule(&block)
end

.schedulerScheduler

Returns the scheduler instance. When using procrastinate/implicit, there is one global scheduler to your ruby process, this one.

Returns:

  • (Scheduler)

    singleton scheduler for implicit scheduling.



10
11
12
# File 'lib/procrastinate/implicit.rb', line 10

def scheduler
  @scheduler ||= Scheduler.start
end

.shutdownObject

Internal method: You should not have to shutdown the scheduler manually since it consumes almost no resources when not active. This is mainly useful in tests to achieve isolation.



68
69
70
# File 'lib/procrastinate/implicit.rb', line 68

def shutdown
  scheduler.shutdown
end