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; }
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); } }
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); }
private void DoneWorking(Job job) { _stat.Increment("processed"); _stat.Increment(string.Format("processed:{0}", WorkerId())); this.Redis.Remove(string.Format("worker:{0}", WorkerId())); }