private async Task <IFetchedJob> FetchNextDelayedJobCoreAsync(string sql, object args = null) { DelayedJob fetchedJob = null; var connection = _storage.CreateAndOpenConnection(); var transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted); try { fetchedJob = (await connection.QueryAsync <DelayedJob>(sql, args, transaction)) .FirstOrDefault(); } catch (SqlException) { transaction.Dispose(); _storage.ReleaseConnection(connection); throw; } if (fetchedJob == null) { transaction.Rollback(); transaction.Dispose(); _storage.ReleaseConnection(connection); return(null); } return(new SqlServerFetchedJob( fetchedJob, _storage, connection, transaction)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseHangfireDashboard(); app.UseHangfireServer(); var ffj = new FireAndForgetJob(); var dj = new DelayedJob(); var rj = new Recurring_Job(); var cj = new ContinuationsJob(); app.UseMvc(); }
public SqlServerFetchedJob( DelayedJob job, SqlServerStorage storage, IDbConnection connection, IDbTransaction transaction) { Job = job; _storage = storage; _connection = connection; _transaction = transaction; }
public static DelayedJob DoAfterDelay(float delaySeconds, Action action, bool useScaledTime = true, Component owner = null) { if (delaySeconds < 0) { throw new ArgumentException("Must have positive delay"); } var job = new DelayedJob { ExecuteInSeconds = delaySeconds, Job = action, UseScaledTime = useScaledTime, Owner = owner }; Instance.jobs.Add(job); return(job); }
private async Task EnqueueCore(DateTime?due, MethodInvocation method) { var data = InvocationData.Serialize(method); var job = new DelayedJob() { Due = due, Data = Helper.ToJson(data) }; using (var connection = _storage.GetConnection()) { await connection.StoreJobAsync(job); } }
public Task StoreJobAsync(DelayedJob job) { if (job == null) { throw new ArgumentNullException(nameof(job)); } var sql = $@" INSERT INTO {_schema}.DelayedJobs (Id, Data, Due) VALUES (@id, @data, @due)" ; return(_storage.UseConnectionAsync(connection => { return connection.ExecuteAsync(sql, new { id = job.Id, data = job.Data, due = job.Due.HasValue ? NormalizeDateTime(job.Due.Value) : job.Due }); })); }
public ActionResult <IEnumerable <string> > Get() { DelayedJob job = new DelayedJob(); return(new string[] { "value1", "value2" }); }