public void SetJob(Delegate function, 
                    object[] functionParameter, 
                    Delegate assignResult = null,
                    JobPriority priority = JobPriority.High)
 {
     this.SetJob(new Job(function, functionParameter, assignResult), priority);
 }
Example #2
0
 /// <summary>
 /// This is the constructor.
 /// </summary>
 /// <param name="level">The job priority level.</param>
 /// <param name="jobID">The job id.</param>
 /// <param name="TTL">The time to live.</param>
 public JobPriorityRecord(JobPriority level, Guid jobID, TimeSpan TTL)
 {
     PushTime = DateTime.Now;
     Priority = level;
     ID = jobID;
     mTTL = TTL;
 }
	public Job (uint id, string job_options, JobPriority job_priority, DateTime run_at, bool persistent) : base (id)
	{
		this.job_options = job_options;
		this.job_priority = job_priority;
		this.run_at = run_at;
		this.persistent = persistent;
	}
Example #4
0
 /// <summary>
 /// This is main constructor.
 /// </summary>
 /// <param name="maxCapacity">The maximum number of jobs that the class can contain.</param>
 /// <param name="PriorityOverride">The priority override level. Jobs that have the same or greater priority will be allowed
 /// to submit jobs regardless of the collection status.</param>
 /// <param name="useDependency">This method will track jobs having the same dependency.</param>
 internal JobCollection(int maxCapacity, JobPriority PriorityOverride, bool useDependency)
 {
     mCapacity = maxCapacity;
     mFixedSize = maxCapacity != -1;
     mDisposed = false;
     this.PriorityOverride = PriorityOverride;
 }
Example #5
0
        public SessionJob JobGet(Guid jobID, IXimuraRQRSEnvelope data, 
            CommandRSCallback RSCallback, CommandProgressCallback ProgressCallback, 
                JobSignature? signature, JobPriority priority)
        {
            if (delSessionJobReturn == null)
                throw new SecurityException("Not authenticated");

            return delGetSessionJob(ID, jobID, data, RSCallback, ProgressCallback, signature, priority);
        }
Example #6
0
		/// <summary>
		/// This method resets the job to its unitialized state.
		/// </summary>
		public override void Reset()
		{
			mSessionID = null;
			mJobID = null;
			mData = null;
			mSignature = null;
			mPriority= JobPriority.Normal;
            mEnvelopeHelper = null;
		}
Example #7
0
        /// <summary>
        /// This factory method can be used to Get a request object and set its 
        /// parameters
        /// </summary>
        /// <returns>Returns an object from the pool.</returns>
        public static CDSData Get(CDSAction action, string refType, string refValue, JobPriority priority)
        {
            CDSData rq = new CDSData();

            rq.ByReference = true;
            rq.RefType = refType;
            rq.RefValue = refValue;
            rq.Action = action;
            rq.Priority = priority;

            return rq;
        }
Example #8
0
 public static DetectionJob Create(Photo photo,JobPriority priority)
 {
     Log.Debug("DetectionJob .Create "+photo.Id);
     uint id = 0;
     DetectionJob job = new DetectionJob(id,photo.Id.ToString(),
                                         DateTime.Now,
                                         priority,
                                         persistent);
     Scheduler.Schedule(job,priority);
     job.Status = FSpot.Jobs.JobStatus.Scheduled;
     return job;
 }
Example #9
0
 public static RecognitionJob Create(Face face,JobPriority priority)
 {
     Log.Debug("RecognitionJob .Create "+face.Id);
     uint id = 0;
     RecognitionJob job = new RecognitionJob(id,face.Id.ToString(),
                                         DateTime.Now,
                                         priority,
                                         persistent);
     Scheduler.Schedule(job,priority);
     job.Status = FSpot.Jobs.JobStatus.Scheduled;
     return job;
 }
Example #10
0
        public static void Schedule(IJob job, JobPriority priority)
        {
            lock(this_mutex) {
                if(IsDisposed()) {
                    return;
                }

                heap.Push(job, (int)priority);
                //Log.DebugFormat("Job scheduled ({0}, {1})", job, priority);
                OnJobScheduled(job);
                CheckRun();
            }
        }
Example #11
0
        public static void Schedule(IJob job, JobPriority priority)
        {
            lock (this_mutex) {
                if (IsDisposed())
                {
                    return;
                }

                heap.Push(job, (int)priority);
                //Log.DebugFormat("Job scheduled ({0}, {1})", job, priority);
                OnJobScheduled(job);
                CheckRun();
            }
        }
Example #12
0
        public void Add(IJob job, JobPriority priority = JobPriority.Normal)
        {
            if (job == null)
            {
                throw new ArgumentNullException(nameof(job));
            }
            if (!Enum.IsDefined(typeof(JobPriority), priority))
            {
                throw new InvalidEnumArgumentException(nameof(priority), (int)priority, typeof(JobPriority));
            }

            _jobs[priority].Enqueue(job);

            _idleSemaphore.Release();
        }
Example #13
0
 private static BaseJob InstanceJob(JobType jobType, string[] line, int length)
 {
     if (length > 2)
     {
         string      last        = line[length - 1];
         JobPriority jobPriority = JobPriority.Normal;
         if (!Int32.TryParse(last, out int digit) && Enum.TryParse(last, true, out jobPriority))     // bad behavior, reflection?
         {
             length -= 1;
         }
         string arguments = ConcatArguments(line, length);
         return(JobResolver.Resolve(jobType, jobPriority, arguments));
     }
     return(JobResolver.Resolve(jobType));
 }
Example #14
0
        /// <summary>
        /// This factory method can be used to Get a request object and set its 
        /// parameters
        /// </summary>
        /// <returns>Returns an object from the pool.</returns>
        public static CDSData Get(CDSAction action, Guid? CID, Guid? VID, JobPriority priority)
        {
            CDSData rq = new CDSData();
            rq.ByReference = false;

            if (CID.HasValue)
                rq.IDContent = CID.Value;

            if (VID.HasValue)
                rq.IDVersion = VID.Value;

            rq.Action = action;
            rq.Priority = priority;
            return rq;
        }
Example #15
0
        public HumanoidCharacterProfile WithJobPriority(string jobId, JobPriority priority)
        {
            var dictionary = new Dictionary <string, JobPriority>(_jobPriorities);

            if (priority == JobPriority.Never)
            {
                dictionary.Remove(jobId);
            }
            else
            {
                dictionary[jobId] = priority;
            }

            return(new HumanoidCharacterProfile(Name, Age, Sex, Appearance, dictionary, PreferenceUnavailable, _antagPreferences));
        }
        public async Task <ActionResult <bool> > UpdatePriority(JobPriority jobPriority)
        {
            var tenant = (await _tenantService.GetTenantFromHostAsync());

            if (tenant != null)
            {
                Console.WriteLine($"updating priority {jobPriority.Name}");
                using (var context = _tenantService.CreateContext(tenant))
                {
                    var jobExtrasService = new JobExtrasService(context);
                    return(Ok(await jobExtrasService.UpdateJobPriority(jobPriority)));
                }
            }

            return(BadRequest("Tenant doesn't exist"));
        }
Example #17
0
        public async Task <bool> UpdateJobPriority(JobPriority jobPriority)
        {
            _tenantDataContext.JobPriorities.Update(jobPriority);

            try
            {
                await _tenantDataContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Example #18
0
 public int NotifyBackgroundJobStarted(string message, JobPriority priority, int count = -1)
 {
     return(Dispatcher.Invoke(() =>
     {
         lock (lockObject)
         {
             var job = new JobProgressViewModel(ServiceProvider, message, priority, count);
             jobList.Add(++currentToken, job);
             if (CurrentJob == null || CurrentJob.Priority <= priority)
             {
                 CurrentJob = job;
             }
             return currentToken;
         }
     }));
 }
Example #19
0
        private void QueueFeedUpdate(IResource feed, int attempt, JobPriority jobPriority)
        {
            if (feed.Type != "RSSFeed")
            {
                throw new ArgumentException("Invalid resource type for QueueFeedUpdate: " + feed.Type);
            }

            if (!HttpReader.IsSupportedProtocol(feed.GetPropText(Props.URL)))
            {
                return;
            }

            //  Do not update feeds which were manually set into
            //  hybernating state.
            if (feed.HasProp(Props.IsPaused))
            {
                return;
            }

            lock (this)
            {
                if (_updatingCount >= _maxCount)
                {
                    _pendingFeeds.Push((int)jobPriority, new PendingFeed(feed, attempt));
                }
                else
                {
                    RSSUnitOfWork uow = new RSSUnitOfWork(feed, true, false);
                    uow.Attempts   = attempt;
                    uow.ParseDone += new EventHandler(OnRSSParseDone);
                    Core.NetworkAP.QueueJob(jobPriority, uow);
                    _updatingCount++;
                }
            }
            if (feed.HasProp(Props.AutoUpdateComments))
            {
                foreach (IResource commentFeed in feed.GetLinksTo(null, Props.FeedComment2Feed))
                {
                    if (NeedUpdate(commentFeed))
                    {
                        QueueFeedUpdate(commentFeed);
                    }
                }
            }
        }
Example #20
0
		/// <summary>
		/// This method initializes the job.
		/// </summary>
		/// <param name="sessionid">The session id</param>
		/// <param name="id">The job id</param>
		/// <param name="data">The data</param>
		/// <param name="signature">The signature</param>
		/// <param name="priority">The job priority.</param>
		public void Initialize(Guid sessionid, Guid id, IXimuraRQRSEnvelope data,
            JobSignature signature, JobPriority priority, IXimuraEnvelopeHelper envelopeHelper)
		{
			try
			{
				mSessionID = sessionid;
				mJobID = id;
				mData = data;
				mSignature = signature;
				mPriority = priority;
                mEnvelopeHelper = envelopeHelper;
			}
			catch (Exception ex)
			{
				Reset();
				throw ex;
			}
		}
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Job"/> class.
 /// </summary>
 /// <param name="jobId">The job identifier.</param>
 /// <param name="jobType">Type of the job.</param>
 /// <param name="numberOfFiles">The number of files.</param>
 /// <param name="filesTransferred">The files transferred.</param>
 /// <param name="totalSizeInBytes">The total size in bytes.</param>
 /// <param name="creationDate">The created.</param>
 /// <param name="lastUpdated">The last updated.</param>
 /// <param name="progress">The progress.</param>
 /// <param name="status">The status.</param>
 /// <param name="files">The files.</param>
 /// <param name="name">The job name.</param>
 /// <param name="foreignJobs">The foreign jobs.</param>
 /// <param name="priority">The job priority.</param>
 public Job(Guid jobId, JobType jobType, int numberOfFiles, int filesTransferred,
            long totalSizeInBytes, string creationDate, string lastUpdated, double progress,
            JobStatus status, IList <JobFileStatus> files, string name, IDictionary <Guid, ForeignJobDetails> foreignJobs, JobPriority priority)
 {
     JobId            = jobId;
     JobType          = jobType;
     NumberOfFiles    = numberOfFiles;
     FilesTransferred = filesTransferred;
     TotalSizeInBytes = totalSizeInBytes;
     CreationDate     = creationDate.ToDateTime();
     LastUpdated      = lastUpdated.ToDateTime();
     Progress         = progress;
     Status           = status;
     Files            = files;
     Name             = name;
     ForeignJobs      = foreignJobs;
     Priority         = priority;
 }
        public void SetJob(Job job, JobPriority priority = JobPriority.High)
        {
            lock (queueLock)
            {
                if (priority == JobPriority.High)
                {
                    this.PriorityQueue.AddFirst(job);
                }
                else if (priority == JobPriority.Default)
                {
                    this.PriorityQueue.AddLast(job);
                }
            }

            if (!this.Thread.IsAlive)
            {
                this.Thread.Start();
            }
        }
Example #23
0
 Job CreateJob(string type, uint id, string options, DateTime runAt, JobPriority priority)
 {
     using (var childContainer = container.GetChildContainer()) {
         childContainer.Register(new JobData
         {
             Id          = id,
             JobOptions  = options,
             JobPriority = priority,
             RunAt       = runAt,
             Persistent  = true
         });
         childContainer.TryResolve <Job> (type, out var job);
         if (job == null)
         {
             Log.Error($"Unknown job type {type} ignored.");
         }
         return(job);
     }
 }
Example #24
0
 public void AddProductionJob(Building building, JobPriority prod, JobPriority feed, JobPriority workermovetobuilding)
 {
     Jobs.Add(prod, new Job
     {
         Type       = JobType.Production,
         Target     = building,
         WorkerType = building.WorkerType
     });
     Jobs.Add(feed, new Job
     {
         Type   = JobType.FeedProduction,
         Target = building
     });
     Jobs.Add(workermovetobuilding, new Job
     {
         Type       = JobType.EnterWorkplace,
         Target     = building,
         WorkerType = building.WorkerType
     });
 }
Example #25
0
        public void Lookup(IBasicTrackInfo track, JobPriority priority)
        {
            if (track == null || queries == null || track.ArtworkId == null)
            {
                return;
            }

            lock (((ICollection)queries).SyncRoot) {
                if (!queries.ContainsKey(track))
                {
                    IMetadataLookupJob job = CreateJob(track);
                    if (job == null)
                    {
                        return;
                    }

                    queries.Add(track, job);
                    Scheduler.Schedule(job, priority);
                }
            }
        }
Example #26
0
 /// <summary>Create a job status object for a given jobid.</summary>
 /// <param name="jobid">The jobid of the job</param>
 /// <param name="setupProgress">The progress made on the setup</param>
 /// <param name="mapProgress">The progress made on the maps</param>
 /// <param name="reduceProgress">The progress made on the reduces</param>
 /// <param name="cleanupProgress">The progress made on the cleanup</param>
 /// <param name="runState">The current state of the job</param>
 /// <param name="jp">Priority of the job.</param>
 /// <param name="user">userid of the person who submitted the job.</param>
 /// <param name="jobName">user-specified job name.</param>
 /// <param name="queue">queue name</param>
 /// <param name="jobFile">job configuration file.</param>
 /// <param name="trackingUrl">link to the web-ui for details of the job.</param>
 /// <param name="isUber">Whether job running in uber mode</param>
 public JobStatus(JobID jobid, float setupProgress, float mapProgress, float reduceProgress
                  , float cleanupProgress, JobStatus.State runState, JobPriority jp, string user,
                  string jobName, string queue, string jobFile, string trackingUrl, bool isUber)
 {
     this.jobid           = jobid;
     this.setupProgress   = setupProgress;
     this.mapProgress     = mapProgress;
     this.reduceProgress  = reduceProgress;
     this.cleanupProgress = cleanupProgress;
     this.runState        = runState;
     this.user            = user;
     this.queue           = queue;
     if (jp == null)
     {
         throw new ArgumentException("Job Priority cannot be null.");
     }
     priority         = jp;
     this.jobName     = jobName;
     this.jobFile     = jobFile;
     this.trackingUrl = trackingUrl;
     this.isUber      = isUber;
 }
Example #27
0
        protected async Task SubmitPipelineJob(string jobName, string pipelineId, JobPriority jobPriority, string basePath, IList <InstanceStorageInfo> instances)
        {
            Guard.Against.NullOrWhiteSpace(pipelineId, nameof(pipelineId));
            if (instances.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(instances));
            }

            jobName = jobName.FixJobName();
            Guard.Against.NullOrWhiteSpace(jobName, nameof(jobName));

            _logger.Log(LogLevel.Information, "Queueing a new job '{0}' with pipeline '{1}', priority={2}, instance count={3}", jobName, pipelineId, jobPriority, instances.Count);

            var job = await _jobsApi.Create(pipelineId, jobName, jobPriority);

            using (_logger.BeginScope(new Dictionary <string, object> {
                { "JobId", job.JobId }, { "PayloadId", job.PayloadId }
            }))
            {
                await _jobStore.Add(job, jobName, instances);
            }
        }
Example #28
0
        private bool TryGetNextJob(out JobPriority priority, out IJob job)
        {
            var highPriorityJobs = _jobs
                                   .Where(pair => pair.Value.Count > 0)
                                   .Select(pair => new
            {
                Priority = pair.Key,
                Queue    = pair.Value,
            })
                                   .FirstOrDefault();

            if (highPriorityJobs == null)
            {
                priority = default;
                job      = null;
                return(false);
            }

            priority = highPriorityJobs.Priority;
            job      = highPriorityJobs.Queue.Dequeue();
            return(true);
        }
Example #29
0
 public NntpDownloadGroupsUnit(IResource server, bool refresh, JobPriority priority)
 {
     Interlocked.Increment(ref NntpPlugin._deliverNewsUnitCount);
     _serverResource = new ServerResource(server);
     Core.UIManager.GetStatusWriter(typeof(NntpDownloadGroupsUnit),
                                    StatusPane.Network).ShowStatus("Downloading groups from " + _serverResource.DisplayName + "...");
     _priority = priority;
     _nntpCmd  = "list";
     if (!refresh)
     {
         DateTime lastUpdated = _serverResource.LastUpdateTime;
         if (lastUpdated > DateTime.MinValue)
         {
             _nntpCmd = "newgroups " + ParseTools.NNTPDateString(lastUpdated);
         }
     }
     _count                  = 0;
     _responseChecked        = false;
     _groupList              = new ArrayList();
     _groupListLock          = new SpinWaitLock();
     _flushGroupListDelegate = new MethodInvoker(FlushGroupList);
 }
Example #30
0
        public async Task <Job> Create(string pipeline, string jobName, JobPriority jobPriority)
        {
            return(await Policy.Handle <Exception>()
                   .WaitAndRetryAsync(
                       3,
                       retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
                       (exception, retryCount, context) =>
            {
                _logger.Log(LogLevel.Error, "Exception while creating a new job: {exception}", exception);
            })
                   .ExecuteAsync(async() =>
            {
                if (!PipelineId.TryParse(pipeline, out PipelineId pipelineId))
                {
                    throw new ConfigurationException($"Invalid Pipeline ID configured: {pipeline}");
                }

                var response = await _jobsClient.CreateJob(pipelineId, jobName, jobPriority);
                var job = ConvertResponseToJob(response);
                _logger.Log(LogLevel.Information, "Clara Job.Create API called successfully, Pipeline={0}, JobId={1}, JobName={2}", pipeline, job.JobId, jobName);
                return job;
            }).ConfigureAwait(false));
        }
Example #31
0
    internal Job Create(Type job_type, string job_options, DateTime run_at, JobPriority job_priority, bool persistent)
    {
        int id = 0;

        if (persistent)
        {
            id = Database.Execute(new DbCommand("INSERT INTO jobs (job_type, job_options, run_at, job_priority) VALUES (:job_type, :job_options, :run_at, :job_priority)",
                                                "job_type", job_type.ToString(),
                                                "job_options", job_options,
                                                "run_at", DbUtils.UnixTimeFromDateTime(run_at),
                                                "job_priority", job_priority));
        }

        Job job = (Job)Activator.CreateInstance(job_type, (uint)id, job_options, run_at, job_priority, true);

        AddToCache(job);
        job.Finished += HandleRemoveJob;
        Scheduler.Schedule(job, job.JobPriority);
        job.Status = JobStatus.Scheduled;
        EmitAdded(job);

        return(job);
    }
Example #32
0
        internal Job Create(Type job_type, string job_options, DateTime run_at, JobPriority job_priority, bool persistent)
        {
            long id = 0;

            if (persistent)
            {
                id = Database.Execute(new HyenaSqliteCommand("INSERT INTO jobs (job_type, job_options, run_at, job_priority) VALUES (?, ?, ?, ?)",
                                                             job_type.ToString(),
                                                             job_options,
                                                             DateTimeUtil.FromDateTime(run_at),
                                                             Convert.ToInt32(job_priority)));
            }

            Job job = (Job)Activator.CreateInstance(job_type, Db, (uint)id, job_options, run_at, job_priority, true);

            AddToCache(job);
            job.Finished += HandleRemoveJob;
            Scheduler.Schedule(job, job.JobPriority);
            job.Status = JobStatus.Scheduled;
            EmitAdded(job);

            return(job);
        }
Example #33
0
    // Constructor used when loading game, because actions can't be serialized
    public Job(TileOWW tileOWW, float jobTime, string jobType, bool tileExcludeOtherJobs, JobPriority jobPriority, Job prerequisiteJob = null)
    {
        Action actionNew = null;

        if (jobType == "Build Hull")
        {
            actionNew = delegate() { BuildModeController.Instance.PlaceHull(tileOWW); };
        }
        else if (jobType == "Build Wall")
        {
            actionNew = delegate() { BuildModeController.Instance.PlaceFurniture(tileOWW, "Wall"); };
        }
        else if (BuildModeController.Instance.furnitureTypes.ContainsKey(jobType) && jobType.Contains("Build"))
        {
            actionNew = delegate() { BuildModeController.Instance.PlaceFurniture(tileOWW, jobType); };
        }
        else if (jobType == "Destroy Hull")
        {
            actionNew = delegate() { BuildModeController.Instance.RemoveHull(tileOWW); };
        }
        else if (BuildModeController.Instance.furnitureTypes.ContainsKey(jobType) && jobType.Contains("Remove"))
        {
            actionNew = delegate() { BuildModeController.Instance.RemoveFurniture(tileOWW); };
        }
        else
        {
            Debug.LogWarning("The job type: " + jobType + " loaded is not present in the Job constructor!!");
        }
        this.action  = actionNew;
        this.tileOWW = tileOWW;
        this.jobTime = jobTime;
        this.jobType = jobType;
        this.tileExcludeOtherJobs = tileExcludeOtherJobs;
        this.prerequisiteJob      = prerequisiteJob;
        this.jobPriority          = jobPriority;
        tileOWW.currentJobType    = jobType;
    }
Example #34
0
        /// <summary>Submit a job to the job server in the background, with a particular priority</summary>
        /// <example>
        /// <code>
        /// </code>
        /// </example>
        public string submitJobInBackground(string callback, byte[] data, JobPriority priority)
        {
            try {
                Connection c = null;

                string jobid = System.Guid.NewGuid().ToString();

                SubmitJob p = new SubmitJob(callback, jobid, data, true, priority);

                Packet result;

                while (true)
                {
                    // Simple round-robin submission for now
                    c = managers[connectionIndex++ % managers.Count];

                    c.sendPacket(p);

                    Log.DebugFormat("Sent background job request to {0}...", c);

                    // We need to get back a JOB_CREATED packet
                    result = c.getNextPacket();

                    // If we get back a JOB_CREATED packet, we can continue,
                    // otherwise try the next job manager
                    if (result.Type == PacketType.JOB_CREATED)
                    {
                        Log.DebugFormat("Created background job {0}, with priority {1}", ((JobCreated)result).jobhandle, priority.ToString());
                        return(((JobCreated)result).jobhandle);
                    }
                }
            } catch (Exception e) {
                Log.DebugFormat("Error submitting job: {0}", e.ToString());
                return(null);
            }
        }
Example #35
0
        public void Lookup (IBasicTrackInfo track, JobPriority priority)
        {
            if (track == null || queries == null || track.ArtworkId == null) {
                return;
            }

            if (String.IsNullOrEmpty (track.AlbumTitle) || track.AlbumTitle == AlbumInfo.UnknownAlbumTitle ||
                String.IsNullOrEmpty (track.ArtistName) || track.ArtistName == ArtistInfo.UnknownArtistName) {
                // Do not try to fetch album art for these
                return;
            }

            lock (((ICollection)queries).SyncRoot) {
                if (!queries.ContainsKey (track)) {
                    IMetadataLookupJob job = CreateJob (track);
                    if (job == null) {
                        return;
                    }

                    queries.Add (track, job);
                    Scheduler.Schedule (job, priority);
                }
            }
        }
		/// <summary>
		/// This protected method is used to add a job to the collection.
		/// </summary>
		/// <param name="jobID">The job ID. This should be set to a new Guid.</param>
		/// <param name="data">The data</param>
		/// <param name="RSCallback">The call back completion delegate.</param>
		/// <param name="ProgessCallback">The request progress delegate. Set this to null if not needed.</param>
		/// <param name="priority">The request priority.</param>
		/// <returns>The guid of the job queued.</returns>
		protected virtual Guid AddJob(Guid jobID, IXimuraRQRSEnvelope data, 
			CommandRSCallback RSCallback, CommandProgressCallback ProgessCallback, 
			JobPriority priority)
		{
			//Create a new job holder.
			JobHolder jh = new JobHolder(jobID, data, RSCallback, ProgessCallback, priority);

			//We add the job to the queue as it will only be executed when the Execute()
			//command is called.
			lock (this)
			{
				WorkTable.Add(jh);
				Interlocked.Increment(ref jobRequests);
#if (DEBUG)
				//System.Diagnostics.Debug.WriteLine("Inc: " + jobID.ToString() + " -> " + jobRequests.ToString());
#endif
			}

			return jobID;
		}
		/// <summary>
		/// Process an asychronous request.
		/// </summary>
		/// <param name="jobID">The job ID. This should be set to a new Guid.</param>
		/// <param name="data">The data</param>
		/// <param name="RSCallback">The call back completion delegate.</param>
		/// <param name="ProgessCallback">The request progress delegate. Set this to null if not needed.</param>
		/// <param name="priority">The request priority.</param>
		/// <returns>The job guid.</returns>
		public abstract Guid ProcessRequestAsync(Guid jobID, IXimuraRQRSEnvelope data, 
			CommandRSCallback RSCallback, CommandProgressCallback ProgessCallback, JobPriority priority);
 public ScheduleParams(JobPriority priority, string customArgument, string[] scheduleCommandData)
 {
     Priority            = priority;
     CustomArgument      = customArgument;
     ScheduleCommandData = scheduleCommandData;
 }
Example #39
0
 public void QueueJob(JobPriority priority)
 {
     OutlookSession.OutlookProcessor.QueueJob(priority, this);
 }
Example #40
0
		/// <summary>
		/// Enqueues this job into the JobManager system.
		/// Locks: this.SyncRoot->JobManager.m_ThreadStatsLock
		/// </summary>
		/// <param name="priority">The priority at which to enqueue this job.</param>
		/// <returns>True on success, false if the JobManager was full or if this job was already started.</returns>
		public bool Start(JobPriority priority)
		{
			try
			{
				using (TimedLock.Lock(SyncRoot)) // this.SyncRoot
				{
					if (m_Status == JobStatus.New)
					{
						m_Enqueued = DateTime.Now;
						if (JobManager.Enqueue(this, priority))
						{
							m_Status = JobStatus.Enqueued;
							return true;
						}
						else
							return false;
					}
					else
						return false;
				}
			}
			catch (LockTimeoutException e)
			{
				Console.WriteLine("\n\nDeadlock detected!\n");
				Console.WriteLine(e.ToString());
				return false;
			}
		}
		/// <summary>
		/// This method pushes a job on to the priority queue.
		/// </summary>
		/// <param name="job">The job.</param>
		/// <param name="priority">The job priority.</param>
		/// <returns>The current position on the queue.</returns>
		public void Push(SecurityManagerJob job, JobPriority priority)
		{
            lock (syncObject)
			{
                if (job == null)
                    throw new ArgumentNullException("job", "job cannot be null.");

                if (!job.ID.HasValue)
                    throw new ArgumentNullException("job.ID", "job.ID cannot be null.");

                if (JobList.ContainsKey(job.ID.Value))
					throw new ArgumentException("The job is already queued.","job");

				//Add the job to the job pending queue. This is a seperate object
				//in order to increase the productivity of the Queue.
				JobList.Add(job.ID.Value,job);

				//Push the job to the list. We do this first in case the queue
				//is full and it throws an error.
				QueueList.Push(job.ID.Value,priority,JobTTL);
			}
		}
		public SyncMetadataJob (uint id, string job_options, DateTime run_at, JobPriority job_priority, bool persistent) : base (id, job_options, job_priority, run_at, persistent)
		{
		}
Example #43
0
 bool IAsyncProcessor.QueueJob(JobPriority priority, Delegate method, params object[] args)
 {
     return(true); // TODO:  Add MockAsyncProcessor.OmniaMea.OpenAPI.IAsyncProcessor.QueueJob implementation
 }
Example #44
0
        /// <summary>
        /// This overriden method adds a job to the collection. Jobs with a dependency ID will be
        /// queued behind earlier jobs with the same ID.
        /// </summary>
        /// <param name="newJobID">The job identifier.</param>
        /// <param name="data">The data.</param>
        /// <param name="RSCallback">The callback.</param>
        /// <param name="ProgressCallback">The progress callback.</param>
        /// <param name="priority">The job priority.</param>
        /// <param name="dependencyID">The dependency identifier.</param>
        /// <param name="ValidateRSCallBack"></param>
        /// <returns>The job ID.</returns>
        protected virtual Guid AddJob(Guid newJobID, IXimuraRQRSEnvelope data, 
            CommandRSCallback RSCallback, CommandProgressCallback ProgressCallback,
            JobPriority priority, string dependencyID, DependencyValidateRSCallback ValidateRSCallBack)
        {
            bool jobNotLinked = true;

            lock (this)
            {
                //Create the job holder object.
                JobHolder newJob = new JobHolder(newJobID, data, RSCallback, ProgressCallback, priority,
                    null, null, ValidateRSCallBack);
                //OK, let's continue as normal.
                //Add the job.
                WorkTable.Add(newJob);

                if (dependencyID != null)
                {
                    //Register the dependency job in the dependency tree.
                    jobNotLinked = RegisterLinkedJob(dependencyID, newJobID);

                    newJob.DependencyID = dependencyID;
                }

                Interlocked.Increment(ref jobRequests);

                if (JobShouldTrace)
                {
                    string dependencyInfo = "";
                    if (dependencyID != null)
                    {
                        dependencyInfo = " Dependency: " + dependencyID + " " + 
                            (string)(jobNotLinked ? "Not Linked" : "Linked");
                    }
                    JobTrace("-->" + jobRequests.ToString() + " CJ=" + CompletionJobID.ToString()
                        + " Job=" + newJobID.ToString() + dependencyInfo);
                }
            }

            if (autoExecute && jobNotLinked)
                SubmitJob(newJobID);

            return newJobID;
        }
Example #45
0
 public SyncMetadataJob(IDb db, uint id, string job_options, int run_at, JobPriority job_priority, bool persistent) : this(db, id, job_options, DateTimeUtil.ToDateTime(run_at), job_priority, persistent)
 {
 }
 public int JobPriorityCapacity(JobPriority priority)
 {
     return 500;
 }
Example #47
0
 /// <summary>
 /// This factory method can be used to Get a request object and set its 
 /// parameters
 /// </summary>
 /// <returns>Returns an object from the pool.</returns>
 public static CDSData Get(CDSAction action, JobPriority priority)
 {
     CDSData rq = new CDSData();
     rq.Action = action;
     rq.Priority = priority;
     return rq;
 }
		/// <summary>
		/// Process an asychronous request.
		/// </summary>
		/// <param name="data">The data</param>
		/// <param name="RSCallback">The call back completion delegate.</param>
		/// <param name="ProgessCallback">The request progress delegate. Set this to null if not needed.</param>
		/// <param name="priority">The request priority.</param>
		/// <returns>The job guid.</returns>
		public Guid ProcessRequestAsync(IXimuraRQRSEnvelope data, 
			CommandRSCallback RSCallback, CommandProgressCallback ProgessCallback, JobPriority priority)
		{
			return ProcessRequestAsync(Guid.NewGuid(),data,RSCallback,ProgessCallback, priority);
		}
		public SyncMetadataJob (uint id, string job_options, int run_at, JobPriority job_priority, bool persistent) : this (id, job_options, DbUtils.DateTimeFromUnixTime (run_at), job_priority, persistent)
		{
		}
Example #50
0
 bool IAsyncProcessor.QueueJob(JobPriority priority, AbstractJob uow)
 {
     // TODO:  Add MockAsyncProcessor.OmniaMea.OpenAPI.IAsyncProcessor.QueueJob implementation
     return(false);
 }
Example #51
0
 public void QueueIdleJob(JobPriority priority, AbstractJob uow)
 {
     // TODO:  Add MockAsyncProcessor.QueueIdleUnitOfWork implementation
 }
Example #52
0
 public SyncMetadataJob(uint id, string job_options, int run_at, JobPriority job_priority, bool persistent) : this(id, job_options, DbUtils.DateTimeFromUnixTime(run_at), job_priority, persistent)
 {
 }
Example #53
0
 /// <summary>
 /// This method redirects any job requests without a dependency ID to this code with this callback.
 /// </summary>
 /// <param name="jobID">The job identifier.</param>
 /// <param name="data">The data.</param>
 /// <param name="RSCallback">The callback.</param>
 /// <param name="ProgessCallback">The progress callback.</param>
 /// <param name="priority">The job priority.</param>
 /// <returns>The job ID.</returns>
 protected override Guid AddJob(Guid jobID, IXimuraRQRSEnvelope data,
     CommandRSCallback RSCallback, CommandProgressCallback ProgessCallback,
     JobPriority priority)
 {
     return AddJob(jobID, data, RSCallback, ProgessCallback, priority, null, null);
 }
Example #54
0
		/// <summary>
		/// Adds a job to the JobManager.
		/// Locks: JobManager.m_ThreadStatsLock
		/// </summary>
		/// <param name="job">The job to enqueue.</param>
		/// <param name="priority">The priority of the job.</param>
		/// <returns>True if added, false if queue was full.</returns>
		internal static bool Enqueue(ThreadJob job, JobPriority priority)
		{
			if (TotalEnqueuedJobs >= QueueLengthLimit && priority != JobPriority.Critical)
			{
                try
                {
                    bool print = false;
                    using (TimedLock.Lock(m_ThreadStatsLock))
                    {
                        if (m_LastError != 2)
                            print = true;
                        m_LastError = 2;
                    }
                    if (print)
                        Console.WriteLine("{0} JM Error: Rejected job because queue was full.", DateTime.Now);
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("Exception Caught in JobManager code: " + e.Message);
                    System.Console.WriteLine(e.StackTrace);
                }
				return false;
			}

			if (TotalEnqueuedJobs >= QueueLengthLimit / 2)
			{
                try
                {
                    bool print = false;
                    using (TimedLock.Lock(m_ThreadStatsLock))
                    {
                        if (m_LastError != 1)
                            print = true;
                        m_LastError = 1;
                    }
                    if (print)
                        Console.WriteLine("{0} JM Warning: Queue length exceeds half of hard limit.", DateTime.Now);
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("Exception Caught in JobManager code: " + e.Message);
                    System.Console.WriteLine(e.StackTrace);
                    return false;
                }
			}

			m_Jobs[(int)priority].Enqueue(job);

			return true;
		}
Example #55
0
 public TrainingJob(uint id, string job_options, DateTime run_at, JobPriority job_priority, bool persistent)
     : base(id, job_options, job_priority, run_at, persistent)
 {
     this.priority = job_priority;
 }
 /// <sumary>
 /// This method pushes a new item onto the queue.
 /// </summary>
 /// <param name="jobID">The job id</param>
 /// <param name="priority">The job priority</param>
 /// <param name="jobTTL">The job Time To Live</param>
 /// <returns>The job position.</returns>
 public void Push(Guid jobID, JobPriority priority, TimeSpan jobTTL)
 {
     JobPriorityRecord newJob = new JobPriorityRecord(priority, jobID, jobTTL);
     Push(newJob);
 }
Example #57
0
        public void ShouldBeAbleToCreateJobModelTypes()
        {
            var created = from simpleCommand in Command.NewSimpleCommand("echo 'Hello, World!'").Lift("simple-command")
                          from parameterizedCommand in
                          Command.NewParametrizedCommand(
                new ParametrizedCommand(
                    "echo 'Hello, %user%'",
                    new[]
            {
                "user"
            }.ToFSharpList())).Lift()
                          from tryWithCatch in
                          new CommandWithErrorHandler(parameterizedCommand, FSharpOption <Command> .Some(simpleCommand)).Lift(
                "try-with-catch")
                          from tryWithoutCatch in
                          new CommandWithErrorHandler(simpleCommand, FSharpOption <Command> .None).Lift("try-without-catch")
                          from commandSet0 in CommandSet.Zero.Lift()
                          from commandSet in new CommandSet(
                new[]
            {
                tryWithCatch
            }.ToFSharpList(),
                new[]
            {
                simpleCommand
            }.ToFSharpList()).Lift()
                          from localFiles0 in LocalFiles.Zero.Lift()
                          from localFiles in LocalFiles.NewLocalFiles(
                new[]
            {
                new FileInfo("temp.txt")
            }.ToFSharpList()).Lift()
                          from uploadedFiles0 in UploadedFiles.Zero.Lift()
                          from uploadedFiles in UploadedFiles.NewUploadedFiles(
                new[]
            {
                new ResourceFile("blobSource", "blobPath")
            }.ToFSharpList()).Lift("uploaded-files")
                          from workloadUnitTemplate0 in WorkloadUnitTemplate.Zero.Lift()
                          from workloadUnitTemplate in new WorkloadUnitTemplate(commandSet, localFiles, false).Lift()
                          from workloadArguments0 in WorkloadArguments.Zero.Lift()
                          from workloadArguments in
                          WorkloadArguments.NewWorkloadArguments(
                new Dictionary <string, FSharpList <string> >
            {
                {
                    "users", new[]
                    {
                        "john",
                        "pradeep"
                    }.ToFSharpList()
                }
            }.ToFSharpMap()).Lift()
                          from workloadSpecification in new WorkloadSpecification(
                new[]
            {
                workloadUnitTemplate
            }.ToFSharpList(),
                LocalFiles.Zero,
                workloadArguments).Lift()
                          from taskName in TaskName.NewTaskName("simple-task").Lift()
                          from taskArguments0 in TaskArguments.Zero.Lift()
                          from taskArguments in TaskArguments.NewTaskArguments(
                new Dictionary <string, string>
            {
                { "name", "john" }
            }.ToFSharpMap()).Lift()
                          from defaultTaskSpecification in TaskSpecification.Zero.Lift()
                          from jobName in JobName.NewJobName("simple-job").Lift()
                          from nullJobPriority in JobPriority.NewJobPriority(null).Lift()
                          from jobPriority in JobPriority.NewJobPriority(10).Lift()
                          from defaultJobSpecification in JobSpecification.Zero.Lift()
                          select "done";

            Assert.AreEqual("done", created.Value);
        }
Example #58
0
 public CalculateHashJob(uint id, string job_options, DateTime run_at, JobPriority job_priority, bool persistent)
     : base(id, job_options, job_priority, run_at, persistent)
 {
 }
Example #59
0
 public SyncMetadataJob(IDb db, uint id, string job_options, DateTime run_at, JobPriority job_priority, bool persistent) : base(db, id, job_options, job_priority, run_at, persistent)
 {
 }
Example #60
0
		private void handleJobSubmitted(Packet p, JobPriority priority, bool background)
		{
            Guid jobid = Guid.NewGuid();
			string jobhandle = String.Format("{0}:{1}", hostName, jobid);

			SubmitJob sj = (SubmitJob)p;
            
            var job = new Job() {
				TaskName = sj.taskname,
				JobHandle = jobhandle, 
				Unique = sj.unique_id, 
				When = sj.when, 
				Priority = (int)priority, 
				Data = sj.data, 
				Dispatched = false,
            };

            bool success = queue.storeJob(job, true);
			
			Console.WriteLine("{0} == {1}", job.JobHandle, job.Id);
			GearmanServer.Log.Info ("Job was submitted!");
			conn.sendPacket(new JobCreated(jobhandle));

            if(sj.when <= DateTime.UtcNow && workers.ContainsKey(sj.taskname))
            {
                foreach (Gearman.Connection c in workers[sj.taskname])
                {
                    c.sendPacket(new NoOp());
                }
            }
		}