Exemple #1
0
        public async Task <IOperableTrigger> RetrieveTrigger(TriggerKey triggerKey,
                                                             CancellationToken cancellationToken = default)
        {
            using var session = Store.OpenAsyncSession();
            var trigger = await session.LoadAsync <Trigger>(triggerKey.GetDatabaseId(), cancellationToken);

            return(trigger?.Deserialize());
        }
Exemple #2
0
        public async Task <bool> RemoveTrigger(TriggerKey triggerKey, CancellationToken cancellationToken = default)
        {
            using var session = Store.OpenAsyncSession();

            if (!await session.Advanced.ExistsAsync(triggerKey.GetDatabaseId(), cancellationToken))
            {
                return(false);
            }

            // Request trigger and associated job
            var trigger = await session
                          .Include <Trigger>(t => t.JobKey)
                          .LoadAsync <Trigger>(triggerKey.GetDatabaseId(), cancellationToken);

            // Get pre-loaded associated job
            var job = (await session.LoadAsync <Job>(trigger.JobKey, cancellationToken)).Deserialize();

            // Check for more triggers
            var hasMoreTriggers = await session
                                  .Query <Trigger>()
                                  .Where(t =>
                                         Equals(t.JobName, job.Key.Name) &&
                                         Equals(t.Group, job.Key.Group) &&
                                         !Equals(t.Key, trigger.Key)) // exclude our own since not yet deleted
                                  .AnyAsync(cancellationToken);

            // Remove the trigger's job if it is not associated with any other triggers
            if (!hasMoreTriggers && !job.Durable)
            {
                session.Delete(job.Key.GetDatabaseId());
                await _signaler.NotifySchedulerListenersJobDeleted(job.Key, cancellationToken);
            }

            // Delete trigger
            session.Delete(triggerKey.GetDatabaseId());

            await session.SaveChangesAsync(cancellationToken);

            return(true);
        }
Exemple #3
0
 private async Task RemoveTriggerOnly(TriggerKey triggerKey, CancellationToken cancellationToken = default)
 {
     using var session = Store.OpenAsyncSession();
     session.Delete(triggerKey.GetDatabaseId());
     await session.SaveChangesAsync(cancellationToken);
 }