示例#1
0
 def _delete_all_job(self, user):
     for job_type in self.job_types:
         job_id = self._generate_job_id(user.id, job_type)
         if self.is_exist(job_id):
             self.remove_job(job_id)
         try:
             db_api.job_delete(self.context, job_id)
         except exception.NotFound as e:
             LOG.warn(_("Failed in deleting job: %s") % six.text_type(e))
示例#2
0
 def _freeze_task(self, user_id):
     user = user_mod.User.load(self.context, user_id=user_id)
     if user.status != user.FREEZE and user.rate > 0:
         user.do_bill(self.context)
     try:
         db_api.job_delete(
             self.context, self._generate_job_id(user.id, 'freeze'))
     except exception.NotFound as e:
         LOG.warn(_("Failed in deleting job: %s") % six.text_type(e))
示例#3
0
 def _task(self, user_id, task_type):
     admin_context = bilean_context.get_admin_context()
     self.rpc_client.settle_account(
         admin_context, user_id, task=task_type)
     if task_type != self.DAILY:
         try:
             db_api.job_delete(
                 admin_context, self._generate_job_id(user_id, task_type))
         except exception.NotFound as e:
             LOG.warn(_LW("Failed in deleting job: %s") % six.text_type(e))
示例#4
0
 def delete_jobs(self, user):
     """Delete all jobs related the specific user."""
     admin_context = bilean_context.get_admin_context()
     for job_type in self.job_types:
         job_id = self._generate_job_id(user.id, job_type)
         try:
             if self._is_exist(job_id):
                 self._remove_job(job_id)
                 db_api.job_delete(admin_context, job_id)
         except Exception as e:
             LOG.warn(_LW("Failed in deleting job: %s") % six.text_type(e))
示例#5
0
 def _notify_task(self, user_id):
     user = user_mod.User.load(self.context, user_id=user_id)
     msg = {'user': user.id, 'notification': 'The balance is almost use up'}
     self.notifier.info('billing.notify', msg)
     if user.status != user.FREEZE and user.rate > 0:
         user.do_bill(self.context)
     try:
         db_api.job_delete(
             self.context, self._generate_job_id(user.id, 'notify'))
     except exception.NotFound as e:
         LOG.warn(_("Failed in deleting job: %s") % six.text_type(e))
     self._add_freeze_job(user)
示例#6
0
    def update_jobs(self, user):
        """Update user's billing job"""
        # Delete all jobs except daily job
        admin_context = bilean_context.get_admin_context()
        for job_type in self.NOTIFY, self.FREEZE:
            job_id = self._generate_job_id(user.id, job_type)
            try:
                if self._is_exist(job_id):
                    self._remove_job(job_id)
                    db_api.job_delete(admin_context, job_id)
            except Exception as e:
                LOG.warn(_LW("Failed in deleting job: %s") % six.text_type(e))

        if user.status == user.ACTIVE:
            self._add_notify_job(user)
        elif user.status == user.WARNING:
            self._add_freeze_job(user)
示例#7
0
    def update_user_job(self, user):
        """Update user's billing job"""
        if user.status not in [user.ACTIVE, user.WARNING]:
            self._delete_all_job(user.id)
            return

        for job_type in self.NOTIFY, self.FREEZE:
            job_id = self._generate_job_id(user.id, job_type)
            if self.is_exist(job_id):
                self.remove_job(job_id)
            try:
                db_api.job_delete(self.context, job_id)
            except exception.NotFound as e:
                LOG.warn(_("Failed in deleting job: %s") % six.text_type(e))

        daily_job_id = self._generate_job_id(user.id, self.DAILY)
        if not self.is_exist(daily_job_id):
            self._add_daily_job(user)

        if user.status == user.ACTIVE:
            self._add_notify_job(user)
        else:
            self._add_freeze_job(user)