public void JobKey()
        {
            var expected = new JobKey("job1", "group1");

            var bsonDoc = expected.ToBsonDocument();

            var actual = BsonSerializer.Deserialize <JobKey>(bsonDoc);

            Assert.AreEqual(expected, actual);
        }
예제 #2
0
        /// <summary>
        /// Remove (delete) the <see cref="IJob" /> with the given
        /// name, and any <see cref="ITrigger" /> s that reference
        /// it.
        /// </summary>
        /// <returns>
        /// 	<see langword="true" /> if a <see cref="IJob" /> with the given name and
        /// group was found and removed from the store.
        /// </returns>
        public virtual bool RemoveJob(JobKey jobKey)
        {
            bool found;

            lock (lockObject)
            {
                // keep separated to clean up any staled trigger
                IList<IOperableTrigger> triggersForJob = this.GetTriggersForJob(jobKey);
                foreach (IOperableTrigger trigger in triggersForJob)
                {
                    this.RemoveTrigger(trigger.Key);
                }

                found = this.CheckExists(jobKey);

                if (found)
                {
                    this.Jobs.Remove(
                    Query.EQ("_id", jobKey.ToBsonDocument()));

                    this.BlockedJobs.Remove(
                        Query.EQ("_id", jobKey.ToBsonDocument()));

                    var others = this.Jobs.FindAs<BsonDocument>(
                        Query.EQ("Group", jobKey.Group));

                    if (others.Count() == 0)
                    {
                        this.PausedJobGroups.Remove(
                            Query.EQ("_id", jobKey.Group));
                    }
                }
            }

            return found;
        }
예제 #3
0
 /// <summary>
 /// Get all of the Triggers that are associated to the given Job.
 /// <para>
 /// If there are no matches, a zero-length array should be returned.
 /// </para>
 /// </summary>
 public virtual IList<IOperableTrigger> GetTriggersForJob(JobKey jobKey)
 {
     lock (lockObject)
     {
         return this.Triggers
             .FindAs<Spi.IOperableTrigger>(
                 Query.EQ("JobKey", jobKey.ToBsonDocument()))
             .ToList();
     }
 }
예제 #4
0
 /// <summary>
 /// Determine whether a <see cref="IJob"/> with the given identifier already 
 /// exists within the scheduler.
 /// </summary>
 /// <param name="jobKey">the identifier to check for</param>
 /// <returns>true if a Job exists with the given identifier</returns>
 public bool CheckExists(JobKey jobKey)
 {
     lock (lockObject)
     {
         return this.Jobs.FindOneByIdAs<BsonDocument>(jobKey.ToBsonDocument()) != null;
     }
 }
예제 #5
0
 /// <summary>
 /// Retrieve the <see cref="IJobDetail" /> for the given
 /// <see cref="IJob" />.
 /// </summary>
 /// <returns>
 /// The desired <see cref="IJob" />, or null if there is no match.
 /// </returns>
 public virtual IJobDetail RetrieveJob(JobKey jobKey)
 {
     lock (lockObject)
     {
         return this.Jobs
             .FindOneByIdAs<IJobDetail>(jobKey.ToBsonDocument());
     }
 }
예제 #6
0
 /// <summary>
 /// Retrieve the <see cref="IJobDetail" /> for the given
 /// <see cref="IJob" />.
 /// </summary>
 /// <returns>
 /// The desired <see cref="IJob" />, or null if there is no match.
 /// </returns>
 public IJobDetail RetrieveJob(JobKey jobKey)
 {
     try
     {
         var jobInfo = JobCollection.FindOneById(jobKey.ToBsonDocument());
         return jobInfo.Job;
     }
     catch (Exception e)
     {
         throw new JobPersistenceException("Couldn't retrieve job: " + e.Message, e);
     }
 }
예제 #7
0
 /// <summary>
 /// Get all of the Triggers that are associated to the given Job.
 /// </summary>
 /// <remarks>
 /// If there are no matches, a zero-length array should be returned.
 /// </remarks>
 public IList<IOperableTrigger> GetTriggersForJob(JobKey jobKey)
 {
     var id = jobKey.ToBsonDocument();
     var jobInfo = JobCollection.FindOneById(id);
     foreach (var triggerInfo in jobInfo.Triggers)
     {
         triggerInfo.Trigger.Key = triggerInfo.Id;
         triggerInfo.Trigger.JobKey = jobKey;
     }
     var triggers = jobInfo.Triggers.Select(x => x.Trigger);
     return triggers.ToList();
 }
예제 #8
0
 /// <summary>
 /// Determine whether a <see cref="IJob" /> with the given identifier already
 /// exists within the scheduler.
 /// </summary>
 /// <remarks>
 /// </remarks>
 /// <param name="jobKey">the identifier to check for</param>
 /// <returns>true if a job exists with the given identifier</returns>
 public bool CheckExists(JobKey jobKey)
 {
     var id = jobKey.ToBsonDocument();
     var count = JobCollection.Count(Query.EQ("_id", id));
     return (count > 0);
 }
예제 #9
0
 private void DeleteJob(JobKey key)
 {
     var query = Query.EQ("_id", key.ToBsonDocument());
     JobCollection.Remove(query);
 }