@param Key $triggerKey

@return bool

@throws JobPersistenceException
514978
protected function doRemoveTrigger(Key $triggerKey)
    {
        if (false == $trigger = $this->retrieveTrigger($triggerKey)) {
            return false;
        }

        $result = $this->res->getTriggerStorage()->delete($trigger);

        $removedTrigger = true;
        if (false == $result->isAcknowledged() || false == $result->getDeletedCount()) {
            $removedTrigger = false;
        }

        $jobKey = $trigger->getJobKey();
        $job = $this->retrieveJob($jobKey);

        if ($job && false == $job->isDurable()) {
            $numTriggers = $this->res->getTriggerStorage()->count([
                'jobName' => $jobKey->getName(),
                'jobGroup' => $jobKey->getGroup(),
            ]);

            if ($numTriggers == 0) {
                // Don't call removeJob() because we don't want to check for triggers again.
                $this->res->getJobStorage()->delete($job);
            }
        }

        return $removedTrigger;
    }
1139332
protected void releaseTriggersCron(T jedis) throws JobPersistenceException {
        // has it been more than 10 minutes since we last released orphaned triggers
        // or is this the first check upon initialization
        if(isTriggerLockTimeoutExceeded(jedis) || !isActiveInstance(schedulerInstanceId, jedis)){
            releaseOrphanedTriggers(RedisTriggerState.ACQUIRED, RedisTriggerState.WAITING, jedis);
            releaseOrphanedTriggers(RedisTriggerState.BLOCKED, RedisTriggerState.WAITING, jedis);
            releaseOrphanedTriggers(RedisTriggerState.PAUSED_BLOCKED, RedisTriggerState.PAUSED, jedis);
            settLastTriggerReleaseTime(System.currentTimeMillis(), jedis);
        }
    }
625905
protected function doRemoveJob(Key $jobKey)
    {
        if (false == $job = $this->retrieveJob($jobKey)) {
            return false;
        }

        $result = $this->res->getTriggerStorage()->getCollection()->deleteMany([
            'jobName' => $jobKey->getName(),
            'jobGroup' => $jobKey->getGroup()
        ]);

        if (false == $result->isAcknowledged()) {
            throw new JobPersistenceException(sprintf('Couldn\'t remove job: "%s"', $jobKey));
        }

        $result = $this->res->getJobStorage()->delete($job);

        if (false == $result->isAcknowledged() || false == $result->getDeletedCount()) {
            return false;
        }

        return true;
    }
643544
@Override
	public List<? extends Trigger> getTriggers(JobKey jobKey) throws SchedulerException {
		List<Trigger> triggers = new ArrayList<>();
		if (!CollectionUtils.isEmpty(scheduler.getTriggersOfJob(jobKey))) {
			triggers.addAll(scheduler.getTriggersOfJob(jobKey));
			Collections.sort(triggers, new Comparator<Trigger>() {
				@Override
				public int compare(Trigger o1, Trigger o2) {
					return o1.getKey().compareTo(o2.getKey());
				}
			});
		}
		return triggers;
	}
946537
public function getPersister($key)
    {
        if (empty($key) || false === $this->hasPersister($key)) {
            throw PersisterException::persisterNotFound($key);
        }
        return $this->persisters[$key];
    }
138073
private Trigger createTrigger(JobKey jobKey, JobSpec jobSpec) {
    // Build a trigger for the job with the given cron-style schedule
    return TriggerBuilder.newTrigger()
        .withIdentity("Cron for " + jobSpec.getUri())
        .forJob(jobKey)
        .withSchedule(CronScheduleBuilder.cronSchedule(
                         jobSpec.getConfig().getString(ConfigurationKeys.JOB_SCHEDULE_KEY)))
        .build();
  }
29321
@Override
    public OperableTrigger retrieveTrigger(final TriggerKey triggerKey) throws JobPersistenceException {
        return doWithLock(new LockCallback<OperableTrigger>() {
            @Override
            public OperableTrigger doWithLock(JedisCommands jedis) throws JobPersistenceException {
                return storage.retrieveTrigger(triggerKey, jedis);
            }
        }, "Could not retrieve trigger.");
    }
1102717
public ITrigger getTrigger (final TriggerKey triggerKey) throws SchedulerException
  {
    validateState ();

    return m_aResources.getJobStore ().retrieveTrigger (triggerKey);
  }
123469
@Override
    public Trigger.TriggerState getTriggerState(TriggerKey triggerKey, Jedis jedis){
        final String triggerHashKey = redisSchema.triggerHashKey(triggerKey);
        Pipeline pipe = jedis.pipelined();
        Map<RedisTriggerState, Response<Double>> scores = new HashMap<>(RedisTriggerState.values().length);
        for (RedisTriggerState redisTriggerState : RedisTriggerState.values()) {
            scores.put(redisTriggerState, pipe.zscore(redisSchema.triggerStateKey(redisTriggerState), triggerHashKey));
        }
        pipe.sync();
        for (Map.Entry<RedisTriggerState, Response<Double>> entry : scores.entrySet()) {
            if(entry.getValue().get() != null){
                return entry.getKey().getTriggerState();
            }
        }
        return Trigger.TriggerState.NONE;
    }
80120
public function deleteJob(Key $jobKey)
    {
        $triggers = $this->store->getTriggersForJob($jobKey);

        $this->unscheduleJobs($triggers);

        if ($this->store->removeJob($jobKey)) {
            $this->notify(Event::JOB_DELETED, new KeyEvent($jobKey));

            return true;
        }

        return false;
    }
800171
@Override
    public void pauseTrigger(TriggerKey triggerKey, JedisCluster jedis) throws JobPersistenceException {
        final String triggerHashKey = redisSchema.triggerHashKey(triggerKey);
        Boolean exists = jedis.exists(triggerHashKey);
        Double completedScore = jedis.zscore(redisSchema.triggerStateKey(RedisTriggerState.COMPLETED), triggerHashKey);
        String nextFireTimeResponse = jedis.hget(triggerHashKey, TRIGGER_NEXT_FIRE_TIME);
        Double blockedScore = jedis.zscore(redisSchema.triggerStateKey(RedisTriggerState.BLOCKED), triggerHashKey);

        if (!exists) {
            return;
        }
        if (completedScore != null) {
            // doesn't make sense to pause a completed trigger
            return;
        }

        final long nextFireTime = nextFireTimeResponse == null
                || nextFireTimeResponse.isEmpty() ? -1 : Long.parseLong(nextFireTimeResponse);
        if (blockedScore != null) {
            setTriggerState(RedisTriggerState.PAUSED_BLOCKED, (double) nextFireTime, triggerHashKey, jedis);
        } else {
            setTriggerState(RedisTriggerState.PAUSED, (double) nextFireTime, triggerHashKey, jedis);
        }
    }
176487
@Override
  public OperableTrigger retrieveTrigger(String triggerKey) {

    synchronized (lock) {
      TriggerWrapper tw = wrappedTriggersByKey.get(triggerKey);

      return (tw != null) ? (OperableTrigger) tw.getTrigger().clone() : null;
    }
  }
804601
protected function triggerRequest(\PermissionKey $pk)
    {
        if (!$this->wrID) {
            $this->save();
        }

        if (!$pk->canPermissionKeyTriggerWorkflow()) {
            throw new \Exception(t('This permission key cannot start a workflow.'));
        }

        $pa = $pk->getPermissionAccessObject();
        $skipWorkflow = true;
        if (is_object($pa)) {
            $workflows = $pa->getWorkflows();
            foreach ($workflows as $wf) {
                if ($wf->validateTrigger($this)) {
                    $wp = $this->addWorkflowProgress($wf);
                    $response = $wp->getWorkflowProgressResponseObject();
                    if ($response instanceof SkippedResponse) {
                        // Since the response was skipped, we delete the workflow progress operation and keep moving.
                        $wp->delete();
                    } else {
                        $skipWorkflow = false;
                    }
                    $event = new GenericEvent();
                    $event->setArgument('progress', $wp);
                    Events::dispatch('workflow_triggered', $event);
                }
            }
        }

        if ($skipWorkflow) {
            $defaultWorkflow = new EmptyWorkflow();
            $wp = $this->addWorkflowProgress($defaultWorkflow);

            $event = new GenericEvent();
            $event->setArgument('progress', $wp);
            Events::dispatch('workflow_triggered', $event);

            return $wp->getWorkflowProgressResponseObject();
        }
    }
69509
public function tooManyFailures($key, $maxFailures, $decayMinutes = 1)
    {
        if ($this->cache->has($key.':breakout')) {
            return true;
        }

        if ($this->failures($key) > $maxFailures) {
            $this->cache->add($key.':breakout', Carbon::now()->getTimestamp() + ($decayMinutes * 60), $decayMinutes);

            $this->resetFailures($key);

            return true;
        }

        return false;
    }
106420
@Override
    public Trigger.TriggerState getTriggerState(final TriggerKey triggerKey) throws JobPersistenceException {
        return doWithLock(new LockCallback<Trigger.TriggerState>() {
            @Override
            public Trigger.TriggerState doWithLock(JedisCommands jedis) throws JobPersistenceException {
                return storage.getTriggerState(triggerKey, jedis);
            }
        }, "Could not retrieve trigger state.");
    }
36102
protected function doStoreTrigger(Trigger $newTrigger, $replaceExisting = false, $state = Trigger::STATE_WAITING)
    {
        $triggerKey = $newTrigger->getKey();
        $existingTrigger = $this->retrieveTrigger($triggerKey);

        if ($existingTrigger && false == $replaceExisting) {
            throw ObjectAlreadyExistsException::create($newTrigger);
        }

        $shouldBePaused = $this->isTriggerGroupPaused($triggerKey->getGroup());

        if (false == $shouldBePaused) {
            $shouldBePaused = $this->isTriggerGroupPaused(self::ALL_GROUPS_PAUSED);

            if ($shouldBePaused) {
                $this->insertPausedTriggerGroup($triggerKey->getGroup());
            }
        }

        if ($shouldBePaused && ($state == Trigger::STATE_WAITING || $state == Trigger::STATE_ACQUIRED)) {
            $state = Trigger::STATE_PAUSED;
        }

        $newTrigger->setState($state);

//        if (null == $job) {
//            $job = $this->retrieveJob($newTrigger->getJobKey());
//        }
//
//        if (null == $job) {
//            throw new JobPersistenceException(sprintf('The job referenced by the trigger does not exist. trigger: "%s", job: "%s"',
//                $triggerKey, $newTrigger->getJobKey()));
//        }

        if ($existingTrigger) {
            $id = get_object_id($existingTrigger);
            $values = get_values($newTrigger);

            set_values($existingTrigger, $values);
            set_object_id($existingTrigger, $id);

            $result = $this->res->getTriggerStorage()->update($existingTrigger, [
                'name' => $triggerKey->getName(),
                'group' => $triggerKey->getGroup()
            ], ['upsert' => false]);

            if ($result && (false == $result->isAcknowledged() || false == $result->getModifiedCount())) {
                throw new JobPersistenceException(sprintf('Couldn\'t store trigger.  Update failed: "%s"', $triggerKey));
            }
        } else {
            $result = $this->res->getTriggerStorage()->update($newTrigger, [
                'name' => $triggerKey->getName(),
                'group' => $triggerKey->getGroup()
            ], ['upsert' => true]);

            if ($result && (false == $result->isAcknowledged() || false == $result->getUpsertedCount())) {
                throw new JobPersistenceException(sprintf('Couldn\'t store trigger.  Insert failed: "%s"', $triggerKey));
            }
        }
    }
1002450
@Override
	public void executeJob(String groupName, String jobName) throws SchedulerException {
		if (!config.isExecuteJobAllowed()) {
			LOGGER.warn("not allowed to execute any job");
			return;
		}
		scheduler.triggerJob(new JobKey(jobName, groupName));
	}