예제 #1
0
    def update(self, value, account=None, emit=True):
        if self.scope == 'account':
            if account is None:
                raise ValueError('Account option requires the "account" parameter')

            if not self._validate_account(account):
                raise ValueError('Invalid value for "account" parameter: %r' % account)

        if self.scope == 'server' and account is not None:
            raise ValueError("Server option can't be called with the \"account\" parameter")

        # Get/Create `SchedulerTask`
        task, _ = SchedulerTask.get_or_create(
            key=self.key
        )

        # Get/Create `SchedulerJob`
        job, _ = SchedulerJob.get_or_create(
            account=account or 0,
            task=self.key
        )

        # Update job
        self.update_trigger(job, value)

        # Emit database change to handler (if enabled)
        if emit:
            self._preferences.on_database_changed(self.key, value, account=account)
예제 #2
0
    def get(self, account=None):
        # Verify get() call is valid
        if self.scope == 'account':
            if account is None:
                raise ValueError('Account option requires the "account" parameter')

            if not self._validate_account(account):
                raise ValueError('Invalid value for "account" parameter: %r' % account)

        if self.scope == 'server' and account is not None:
            raise ValueError("Server option can't be called with the \"account\" parameter")

        # Get/Create `SchedulerTask`
        task, _ = SchedulerTask.get_or_create(
            key=self.key
        )

        # Get/Create `SchedulerJob`
        job, _ = SchedulerJob.get_or_create(
            account=account or 0,
            task=self.key,

            defaults={
                'trigger': self.default
            }
        )

        if job.trigger and job.due_at is None:
            job.due_at = self.get_next(job)
            job.save()

        return self._clone(task, job)