Comments (11)
What version of Coravel are you using?
from coravel.
And what version of .NET core?
from coravel.
Coravel v2.5
.NET core v2.2
from coravel.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using IBMS.Infrastruct.Redis;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Swashbuckle.AspNetCore.Swagger;
using IBMS.Infrastruct.Context;
using IBMS.Domain.Interfaces;
using Microsoft.EntityFrameworkCore;
using Coravel;
using Coravel.Invocable;
namespace IBMS.WEBAPI
{
public class Startup
{
private const string _defaultCorsPolicyName = "localhost";
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add DbContext using SQL Server Provider
services.AddDbContext<IIPBoxContext, IPBoxContext>(options =>
options.UseMySql(Configuration.GetConnectionString("MySqlConnection")));
// services.AddScoped<ICaching, MemoryCaching>();//记得把缓存注入!!!
// services.AddScoped<IRedisCacheManager, RedisCacheManager>();//这里说下,如果是自己的项目,个人更建议使用单例模式 services.AddSingleton
services.AddScoped<IRedisMQ, RedisMQ>();
services.AddCors(options => options.AddPolicy(_defaultCorsPolicyName,
builder =>
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod().AllowCredentials()
));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddScheduler();
#region Swagger
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info
{
Version = "v0.1.0",
Title = "IBMS.WEBAPI",
Description = "框架接口说明文档",
TermsOfService = "None",
Contact = new Swashbuckle.AspNetCore.Swagger.Contact { Name = "IBMS.WEBAPI", Email = "[email protected]", Url = "https://www.cnblogs.com/JerryMouseLi/" }
});
services.AddScoped<IPBoxContext>();//上下文
// var basePath = Microsoft.DotNet.PlatformAbstractions.ApplicationEnvironment.ApplicationBasePath;
// var xmlPath = Path.Combine(basePath, "IBMS.WEBAPI.xml");//这个就是刚刚配置的xml文件名
// c.IncludeXmlComments(xmlPath, true);//默认的第二个参数是false,这个是controller的注释,记得修改
//
// var xmlModelPath = Path.Combine(basePath, "IBMS.Domain.Models.xml");//这个就是Model层的xml文件名
// c.IncludeXmlComments(xmlModelPath);
});
#endregion
}
// 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();
#region Swagger
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "ApiHelp V1");
c.RoutePrefix = "";//路径配置,设置为空,表示直接访问该文件,
//路径配置,设置为空,表示直接在根域名(localhost:8001)访问该文件,注意localhost:8001/swagger是访问不到的,
//这个时候去launchSettings.json中把"launchUrl": "swagger/index.html"去掉, 然后直接访问localhost:8001/index.html即可
});
#endregion
}
var provider = app.ApplicationServices;
provider.UseScheduler(scheduler =>
{
scheduler.Schedule(() => Console.WriteLine("Every minute during the week."))
.EverySecond()
.Weekday();
});
app.UseCors(_defaultCorsPolicyName);
app.UseMvc();
}
}
}
This is my total startup.cs file. There is no other configration of Coravel on other files. And when I remove .Weekday(); as follow:
provider.UseScheduler(scheduler =>
{
scheduler.Schedule(() => Console.WriteLine("Every minute during the week."))
.EverySecond()
});
It will be ok, no problem. Could you pls kindly help me?
from coravel.
I just do it as per your https://docs.coravel.net/Scheduler/ Config Item.
services.AddScheduler()
var provider = app.ApplicationServices;
provider.UseScheduler(scheduler =>
{
scheduler.Schedule(
() => Console.WriteLine("Every minute during the week.")
)
.EveryMinute()
.Weekday();
});
It is ok, no problem, but when I change .EveryMinute() to .EverySecond(), then goes the "System.NullReferenceException:“Object reference not set to an instance of an object.”" on System.Private.CoreLib.dll
from coravel.
Thanks - I'll have a look and get back to you 🙂
from coravel.
Have you repeated it?
from coravel.
So I found the issue, should have a new Nuget package for version 2.5.1 soon 🙂
from coravel.
When will you publish the version 2.5.1 to solve this issue?
from coravel.
Fixed it during my day job break 😋 Coravel users are not always so lucky as you 😂
2.5.1 should be available now.
from coravel.
It is really nice. Thanks very much, jamesmh.
from coravel.
Related Issues (20)
- Sample to show how to execute Task on demand in .NET core 7
- Using Dependency Injection with ScheduleAsync HOT 1
- Run Task One Another / Control Concurrency in Queues HOT 1
- Is Coravel good fit for Blazor Server? HOT 4
- Stop scheduled job HOT 2
- Cron Expressions that support Seconds
- Design/Run Time
- Add support for setting Sender in mailer
- Add support for adding attachments as LinkedResources in MailMessage HOT 1
- Dispatcher.Broadcast doesn't work correctly when my listener class implements more than one IListener<> interfaces HOT 1
- Worker Service with Scheduler doesn't execute IInvocable using EveryMinute().WeekDay() on a Friday. HOT 1
- Advanced cron expressions HOT 2
- Is it possible for a job (or something else) to know when the next execution is scheduled for? HOT 2
- Unwanted Clock Drift HOT 2
- Add throttling when queuing items
- Extend Coravel Schedule With CoravelJobAttrbutes
- Scheduler does not run until WEB API server receives its first HTTP Request HOT 7
- How to use Event Broadcasting in worker service
- Task, scheduled to run on the same second, are not run in order they were added. HOT 1
- Turn off logging "Coravel's scheduler is behind" HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coravel.