Package gluon :: Module scheduler :: Class Scheduler
[hide private]
[frames] | no frames]

Class Scheduler

source code

        object --+            
                 |            
threading._Verbose --+        
                     |        
      threading.Thread --+    
                         |    
             MetaScheduler --+
                             |
                            Scheduler

Instance Methods [hide private]
 
__init__(self, db, tasks=None, migrate=True, worker_name=None, group_names=['main'], heartbeat=3, max_empty_runs=0, discard_results=False, utc_time=False)
This constructor should always be called with keyword arguments.
source code
 
__get_migrate(self, tablename, migrate=True) source code
 
now(self) source code
 
set_requirements(self, scheduler_task) source code
 
define_tables(self, db, migrate) source code
 
loop(self, worker_name=None) source code
 
wrapped_assign_tasks(self, db) source code
 
wrapped_pop_task(self) source code
 
pop_task(self, db) source code
 
report_task(self, task, task_report) source code
 
adj_hibernation(self) source code
 
send_heartbeat(self, counter) source code
 
being_a_ticker(self) source code
 
assign_tasks(self, db) source code
 
sleep(self) source code
 
set_worker_status(self, group_names=None, action='ACTIVE') source code
 
disable(self, group_names=None) source code
 
resume(self, group_names=None) source code
 
terminate(self, group_names=None) source code
 
kill(self, group_names=None) source code
 
queue_task(self, function, pargs=[], pvars={}, **kwargs)
Queue tasks.
source code
 
task_status(self, ref, output=False)
Shortcut for task status retrieval
source code
 
stop_task(self, ref)
Experimental!!! Shortcut for task termination.
source code

Inherited from MetaScheduler: async, die, give_up, run, start_heartbeats, terminate_process

Inherited from threading.Thread: __repr__, getName, isAlive, isDaemon, is_alive, join, setDaemon, setName, start

Inherited from threading.Thread (private): _reset_internal_locks, _set_daemon, _set_ident

Inherited from threading._Verbose (private): _note

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from threading.Thread: daemon, ident, name

Inherited from threading.Thread (private): _block

Inherited from object: __class__

Method Details [hide private]

__init__(self, db, tasks=None, migrate=True, worker_name=None, group_names=['main'], heartbeat=3, max_empty_runs=0, discard_results=False, utc_time=False)
(Constructor)

source code 

This constructor should always be called with keyword arguments. Arguments are:

*group* should be None; reserved for future extension when a ThreadGroup class is implemented.

*target* is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

*name* is the thread name. By default, a unique name is constructed of the form "Thread-N" where N is a small decimal number.

*args* is the argument tuple for the target invocation. Defaults to ().

*kwargs* is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

Overrides: object.__init__
(inherited documentation)

loop(self, worker_name=None)

source code 
Overrides: MetaScheduler.loop

pop_task(self, db)

source code 
Overrides: MetaScheduler.pop_task

report_task(self, task, task_report)

source code 
Overrides: MetaScheduler.report_task

send_heartbeat(self, counter)

source code 
Overrides: MetaScheduler.send_heartbeat

sleep(self)

source code 
Overrides: MetaScheduler.sleep

queue_task(self, function, pargs=[], pvars={}, **kwargs)

source code 

Queue tasks. This takes care of handling the validation of all
values.
:param function: the function (anything callable with a __name__)
:param pargs: "raw" args to be passed to the function. Automatically
    jsonified.
:param pvars: "raw" kwargs to be passed to the function. Automatically
    jsonified
:param kwargs: all the scheduler_task columns. args and vars here should be
    in json format already, they will override pargs and pvars

returns a dict just as a normal validate_and_insert, plus a uuid key holding
the uuid of the queued task. If validation is not passed, both id and uuid
will be None, and you'll get an "error" dict holding the errors found.

task_status(self, ref, output=False)

source code 

Shortcut for task status retrieval

:param ref: can be
    - integer --> lookup will be done by scheduler_task.id
    - string  --> lookup will be done by scheduler_task.uuid
    - query   --> lookup as you wish (as in db.scheduler_task.task_name == 'test1')
:param output: fetch also the scheduler_run record

Returns a single Row object, for the last queued task
If output == True, returns also the last scheduler_run record
    scheduler_run record is fetched by a left join, so it can
    have all fields == None

stop_task(self, ref)

source code 

Experimental!!!
Shortcut for task termination.
If the task is RUNNING it will terminate it --> execution will be set as FAILED
If the task is QUEUED, its stop_time will be set as to "now",
    the enabled flag will be set to False, status to STOPPED

:param ref: can be
    - integer --> lookup will be done by scheduler_task.id
    - string  --> lookup will be done by scheduler_task.uuid
Returns:
    - 1 if task was stopped (meaning an update has been done)
    - None if task was not found, or if task was not RUNNING or QUEUED