예제 #1
0
파일: Job.cs 프로젝트: gsimoes/resque-sharp
        public static bool Create(string queue, string className, Action<Job> onSuccess, params object[] args)
        {
            if (String.IsNullOrEmpty(queue))
                throw new ArgumentException(string.Format("Queue can not be empty: {0}", queue));

            if (String.IsNullOrEmpty(className))
                throw new ArgumentException(string.Format("ClassName can not be empty: {0}", className));

            var job = new Job(queue, new Payload { @class = className, args = args });

            onSuccess(job);

            return true;
        }
예제 #2
0
        public void Process(Job job)
        {
            try
            {
                WorkingOn(job);
                job.Perform();
            }
            catch (Exception e)
            {
                _stat.Increment("failed");
                _stat.Increment(string.Format("failed:{0}", WorkerId()));

                _resque.LogFailure(new Failure(e.InnerException ?? e, this.WorkerId(), job.queue, job.payload));
            }
            finally
            {
                DoneWorking(job);
            }
        }
예제 #3
0
        private void WorkingOn(Job job)
        {
            var data = new Dictionary<string, object>() {
                { "queue", job.queue },
                { "run_at", DateTime.Now.ToString("ddd MMM dd HH:mm:ss zzzz yyyy", CultureInfo.CurrentCulture) },
                { "payload", job.payload }
            };

            this.Redis.Add(string.Format("worker:{0}", WorkerId()), data);
        }
예제 #4
0
        private void DoneWorking(Job job)
        {
            _stat.Increment("processed");
            _stat.Increment(string.Format("processed:{0}", WorkerId()));

            this.Redis.Remove(string.Format("worker:{0}", WorkerId()));
        }