noc.core.scheduler.job

Module Contents

noc.core.scheduler.job.logger
class noc.core.scheduler.job.Job(scheduler, attrs)

Bases: object

name
enabled = True
model
use_get_by_id = False
group_name
context_version
context_cache_key = jobctx-%(name)s-%(pool)s-%(job_id)s
ATTR_ID = _id
ATTR_TS = ts
ATTR_CLASS = jcls
ATTR_STATUS = s
ATTR_TIMEOUT = timeout
ATTR_KEY = key
ATTR_DATA = data
ATTR_LAST = last
ATTR_LAST_STATUS = ls
ATTR_LAST_DURATION = ldur
ATTR_LAST_SUCCESS = st
ATTR_RUNS = runs
ATTR_MAX_RUNS = mruns
ATTR_FAULTS = f
ATTR_OFFSET = o
ATTR_SAMPLE = sample
S_WAIT = W
S_RUN = R
S_STOP = S
S_DISABLED = D
S_SUSPEND = s
E_SUCCESS = S
E_FAILED = F
E_EXCEPTION = X
E_DEFERRED = D
E_DEREFERENCE = d
E_RETRY = r
STATUS_MAP
default_contexts
failed_exceptions
load_context(self, data)
init_context(self)

Perform context initialization

run(self)
handler(self, **kwargs)

Job handler, must be sublclassed

get_defererence_query(self)

Get dereference query condition. Called by dereference() :return: dict or None

dereference(self)

Retrieve referenced object from database

get_display_key(self)

Return dereferenced key name

can_run(self)

Check wrether the job can be launched :return:

get_group(self)
remove_job(self)

Remove job from schedule

schedule_next(self, status)

Schedule next run depending on status. Drop job by default

classmethod submit(cls, scheduler, name=None, key=None, data=None, pool=None, ts=None, delta=None, keep_ts=False)

Submit new job or change schedule for existing one :param scheduler: scheduler name :param name: Job full name :param key: Job key :param data: Job data :param pool: Pool name :param ts: Next run timestamp :param delta: Run after delta seconds :param keep_ts: Do not touch timestamp of existing jobs,

set timestamp only for created jobs
classmethod remove(cls, scheduler, name=None, key=None, pool=None)
classmethod get_job_data(cls, scheduler, jcls, key=None, pool=None)
get_context_cache_key(self)
classmethod retry_after(cls, delay, msg='')

Must be called from job handler to deal with temporary problems. Current job handler will be terminated and job will be scheduled after delay seconds :param delay: Delay in seconds :param msg: Informational message :return:

is_retries_exceeded(self)

Check if maximal amount of retries is exceeded :return:

static get_next_timestamp(interval, offset=0.0, ts=None)

Calculate next timestamp :param interval: :param offset: :param ts: current timestamp :return: datetime object