Change bilean_task to scheduler.
Module 'bilean_task' has been renamed to 'scheduler', some missing points make it fail to generate sample config and maybe some other problem, this patch fixes this issue. Change-Id: I566e7b9827fe2b7b599aba04a9c968a7ecad6b1b
This commit is contained in:
parent
aabb1c7317
commit
9f325c0be1
@ -28,7 +28,7 @@ from datetime import timedelta
|
|||||||
import random
|
import random
|
||||||
import six
|
import six
|
||||||
|
|
||||||
bilean_task_opts = [
|
scheduler_opts = [
|
||||||
cfg.StrOpt('time_zone',
|
cfg.StrOpt('time_zone',
|
||||||
default='utc',
|
default='utc',
|
||||||
help=_('The time zone of job, default is utc')),
|
help=_('The time zone of job, default is utc')),
|
||||||
@ -51,9 +51,9 @@ bilean_task_opts = [
|
|||||||
'database')
|
'database')
|
||||||
]
|
]
|
||||||
|
|
||||||
bilean_task_group = cfg.OptGroup('bilean_task')
|
scheduler_group = cfg.OptGroup('scheduler')
|
||||||
cfg.CONF.register_group(bilean_task_group)
|
cfg.CONF.register_group(scheduler_group)
|
||||||
cfg.CONF.register_opts(bilean_task_opts, group=bilean_task_group)
|
cfg.CONF.register_opts(scheduler_opts, group=scheduler_group)
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -76,23 +76,25 @@ class BileanScheduler(object):
|
|||||||
self.context = kwargs.get('context', None)
|
self.context = kwargs.get('context', None)
|
||||||
if not self.context:
|
if not self.context:
|
||||||
self.context = bilean_context.get_admin_context()
|
self.context = bilean_context.get_admin_context()
|
||||||
if cfg.CONF.bilean_task.store_ap_job:
|
if cfg.CONF.scheduler.store_ap_job:
|
||||||
self._scheduler.add_jobstore(cfg.CONF.bilean_task.backend,
|
self._scheduler.add_jobstore(cfg.CONF.scheduler.backend,
|
||||||
url=cfg.CONF.bilean_task.connection)
|
url=cfg.CONF.scheduler.connection)
|
||||||
|
|
||||||
def init_scheduler(self):
|
def init_scheduler(self):
|
||||||
"""Init all jobs related to the engine from db."""
|
"""Init all jobs related to the engine from db."""
|
||||||
jobs = db_api.job_get_all(self.context, engine_id=self.engine_id)
|
jobs = db_api.job_get_all(self.context, engine_id=self.engine_id)
|
||||||
if not jobs:
|
if not jobs:
|
||||||
LOG.info(_LI("No job found from db"))
|
LOG.info(_LI("No job related to engine '%s'."), self.engine_id)
|
||||||
return True
|
return
|
||||||
for job in jobs:
|
for job in jobs:
|
||||||
if self.bilean_scheduler.is_exist(job.id):
|
if self.is_exist(job.id):
|
||||||
continue
|
continue
|
||||||
task_name = "_%s_task" % (job.job_type)
|
task_name = "_%s_task" % (job.job_type)
|
||||||
task = getattr(self, task_name)
|
task = getattr(self, task_name)
|
||||||
self.bilean_task.add_job(task, job.id,
|
LOG.info(_LI("Add job '%(job_id)s' to engine '%(engine_id)s'."),
|
||||||
job_type=job.job_type,
|
{'job_id': job.id, 'engine_id': self.engine_id})
|
||||||
|
tg_type = self.CRON if job.job_type == self.DAILY else self.DAILY
|
||||||
|
self.add_job(task, job.id, trigger_type=tg_type,
|
||||||
params=job.parameters)
|
params=job.parameters)
|
||||||
|
|
||||||
def add_job(self, task, job_id, trigger_type='date', **kwargs):
|
def add_job(self, task, job_id, trigger_type='date', **kwargs):
|
||||||
@ -102,8 +104,8 @@ class BileanScheduler(object):
|
|||||||
:param datetime alarm_time: when to first run the job
|
:param datetime alarm_time: when to first run the job
|
||||||
|
|
||||||
"""
|
"""
|
||||||
mg_time = cfg.CONF.bilean_task.misfire_grace_time
|
mg_time = cfg.CONF.scheduler.misfire_grace_time
|
||||||
job_time_zone = cfg.CONF.bilean_task.time_zone
|
job_time_zone = cfg.CONF.scheduler.time_zone
|
||||||
user_id = job_id.split('-')[1]
|
user_id = job_id.split('-')[1]
|
||||||
if trigger_type == 'date':
|
if trigger_type == 'date':
|
||||||
run_date = kwargs.get('run_date')
|
run_date = kwargs.get('run_date')
|
||||||
@ -116,7 +118,7 @@ class BileanScheduler(object):
|
|||||||
args=[user_id],
|
args=[user_id],
|
||||||
id=job_id,
|
id=job_id,
|
||||||
misfire_grace_time=mg_time)
|
misfire_grace_time=mg_time)
|
||||||
return True
|
return
|
||||||
|
|
||||||
# Add a cron type job
|
# Add a cron type job
|
||||||
hour = kwargs.get('hour', None)
|
hour = kwargs.get('hour', None)
|
||||||
@ -130,7 +132,6 @@ class BileanScheduler(object):
|
|||||||
args=[user_id],
|
args=[user_id],
|
||||||
id=job_id,
|
id=job_id,
|
||||||
misfire_grace_time=mg_time)
|
misfire_grace_time=mg_time)
|
||||||
return True
|
|
||||||
|
|
||||||
def modify_job(self, job_id, **changes):
|
def modify_job(self, job_id, **changes):
|
||||||
"""Modifies the properties of a single job.
|
"""Modifies the properties of a single job.
|
||||||
@ -205,7 +206,7 @@ class BileanScheduler(object):
|
|||||||
if not user.rate:
|
if not user.rate:
|
||||||
return False
|
return False
|
||||||
total_seconds = user['balance'] / user['rate']
|
total_seconds = user['balance'] / user['rate']
|
||||||
prior_notify_time = cfg.CONF.bilean_task.prior_notify_time * 3600
|
prior_notify_time = cfg.CONF.scheduler.prior_notify_time * 3600
|
||||||
notify_seconds = total_seconds - prior_notify_time
|
notify_seconds = total_seconds - prior_notify_time
|
||||||
notify_seconds = notify_seconds if notify_seconds > 0 else 0
|
notify_seconds = notify_seconds if notify_seconds > 0 else 0
|
||||||
run_date = timeutils.utcnow() + timedelta(seconds=notify_seconds)
|
run_date = timeutils.utcnow() + timedelta(seconds=notify_seconds)
|
||||||
@ -295,4 +296,4 @@ class BileanScheduler(object):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
yield bilean_task_group.name, bilean_task_opts
|
yield scheduler_group.name, scheduler_opts
|
||||||
|
@ -205,7 +205,7 @@ class User(object):
|
|||||||
if new_rate == 0 and self.balance > 0:
|
if new_rate == 0 and self.balance > 0:
|
||||||
self.status = self.FREE
|
self.status = self.FREE
|
||||||
elif self.status == self.WARNING:
|
elif self.status == self.WARNING:
|
||||||
p_time = cfg.CONF.bilean_task.prior_notify_time * 3600
|
p_time = cfg.CONF.scheduler.prior_notify_time * 3600
|
||||||
rest_usage = p_time * new_rate
|
rest_usage = p_time * new_rate
|
||||||
if self.balance > rest_usage:
|
if self.balance > rest_usage:
|
||||||
self.status = self.ACTIVE
|
self.status = self.ACTIVE
|
||||||
@ -223,7 +223,7 @@ class User(object):
|
|||||||
"of recharge.")
|
"of recharge.")
|
||||||
self.set_status(self.ACTIVE, reason=reason)
|
self.set_status(self.ACTIVE, reason=reason)
|
||||||
elif self.status == self.WARNING:
|
elif self.status == self.WARNING:
|
||||||
prior_notify_time = cfg.CONF.bilean_task.prior_notify_time * 3600
|
prior_notify_time = cfg.CONF.scheduler.prior_notify_time * 3600
|
||||||
rest_usage = prior_notify_time * self.rate
|
rest_usage = prior_notify_time * self.rate
|
||||||
if self.balance > rest_usage:
|
if self.balance > rest_usage:
|
||||||
reason = _("Status change from warning to active because "
|
reason = _("Status change from warning to active because "
|
||||||
|
@ -32,7 +32,7 @@ oslo.config.opts =
|
|||||||
bilean.common.config = bilean.common.config:list_opts
|
bilean.common.config = bilean.common.config:list_opts
|
||||||
bilean.common.wsgi = bilean.common.wsgi:list_opts
|
bilean.common.wsgi = bilean.common.wsgi:list_opts
|
||||||
bilean.api.middleware.ssl = bilean.api.middleware.ssl:list_opts
|
bilean.api.middleware.ssl = bilean.api.middleware.ssl:list_opts
|
||||||
bilean.engine.bilean_task = bilean.engine.bilean_task:list_opts
|
bilean.engine.scheduler = bilean.engine.scheduler:list_opts
|
||||||
bilean.notification.converter = bilean.notification.converter:list_opts
|
bilean.notification.converter = bilean.notification.converter:list_opts
|
||||||
|
|
||||||
bilean.clients =
|
bilean.clients =
|
||||||
|
@ -3,7 +3,7 @@ output_file = etc/bilean/bilean.conf.sample
|
|||||||
wrap_width = 79
|
wrap_width = 79
|
||||||
namespace = bilean.common.config
|
namespace = bilean.common.config
|
||||||
namespace = bilean.common.wsgi
|
namespace = bilean.common.wsgi
|
||||||
namespace = bilean.engine.bilean_task
|
namespace = bilean.engine.scheduler
|
||||||
namespace = bilean.notification.converter
|
namespace = bilean.notification.converter
|
||||||
namespace = bilean.api.middleware.ssl
|
namespace = bilean.api.middleware.ssl
|
||||||
namespace = keystonemiddleware.auth_token
|
namespace = keystonemiddleware.auth_token
|
||||||
|
Loading…
x
Reference in New Issue
Block a user