我需要能够根据配置文件设置石英来运行。我正在使用集成测试来确保每个配置文件都启动了调度程序(或未启动),但我正在检查未启用它的配置文件,并且此检查失败:
assertFalse(scheduler.isStarted());
Run Code Online (Sandbox Code Playgroud)
这是我在以下配置文件中使用的内容application.yaml:
spring:
quartz:
enabled: false
Run Code Online (Sandbox Code Playgroud)
还尝试过:
spring:
quartz:
properties:
enabled: false
Run Code Online (Sandbox Code Playgroud)
有什么想法可以让石英根本不启动吗?
作为解决方法,是否可以在配置文件上设置一个虚拟调度程序,以便完全跳过真正的石英?
PS我注意到了这一点,但如果可能的话,我想将其保留在 application.yaml 中:How to disable Quartz Scheduler for dev and stg environment
我正在尝试在我的 asp core 2.0 项目中使用 Quartz sheduker。我使用 nuget 下载了 Quartz 3.0.4,之后添加了 services.AddQuartz(new QuartezOptions {}); Startup.cs中的ConfigureService函数
我对 app.UseQuartz() 也有同样的问题
这就是 Startup.cs 现在的样子:
using AspProj.Map;
using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Swashbuckle.AspNetCore.Swagger;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Quartz;
namespace AspProj
{
public class Startup
{
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 …Run Code Online (Sandbox Code Playgroud) 我想按顺序执行多个作业。我正在以下列方式尝试它,但不知何故它不会被使用 cron 作业触发。
我不确定它是否是正确的实现方法。有人可以指导我吗?
谢谢 ..
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
JobChainingJobListener jobListener =new JobChainingJobListener("ChainListener");
JobDetail job1 = JobBuilder.newJob(MyJob1.class)
.withIdentity(MyJob1.class.getName()).
withDescription(MyJob1.class.getName())
.build();
JobDetail job2 = JobBuilder.newJob(MyJob2.class)
.withIdentity(MyJob2.class.getName()).
withDescription(MyJob2.class.getName())
.build();
JobDetail job3 = JobBuilder.newJob(MyJob3.class)
.withIdentity(MyJob3.class.getName()).
withDescription(MyJob3.class.getName())
.build();
Trigger jobTrigger = TriggerBuilder.newTrigger()
.withIdentity("MyTrigger")
.withSchedule(CronScheduleBuilder.cronSchedule(cronTrigger)).build();
scheduler.scheduleJob(job1, jobTrigger);
scheduler.addJob(job2, true);
scheduler.addJob(job3, true);
jobListener.addJobChainLink(job1.getKey(), job2.getKey());
jobListener.addJobChainLink(job2.getKey(), job3.getKey());
scheduler.getListenerManager().addJobListener(jobListener);
scheduler.start();
Run Code Online (Sandbox Code Playgroud) 我们有一个集群石英配置,有8个地理分布的节点,所有节点都由MariaDB的单个实例支持.我们反复观察到以下错误:
2018-04-26 00:14:01,186 [censored_QuartzSchedulerThread] ERROR org.quartz.core.ErrorLogger - An error occurred while firing triggers '[Trigger 'DEFAULT.a563a68e-b30d-4dab-b24f-540c5fa0cef8': triggerClass: 'org.quartz.impl.triggers.CronTriggerImpl calendar: 'null' misfireInstruction: 0 nextFireTime: Thu Apr 26 00:11:00 EDT 2018]'
org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: (conn:83) Lock wait timeout exceeded; try restarting transaction
Query is: SELECT * FROM QRTZ_LOCKS WHERE SCHED_NAME = 'censored' AND LOCK_NAME = ? FOR UPDATE, parameters ['TRIGGER_ACCESS']
at org.quartz.impl.jdbcjobstore.StdRowLockSemaphore.executeSQL(StdRowLockSemaphore.java:157)
at org.quartz.impl.jdbcjobstore.DBSemaphore.obtainLock(DBSemaphore.java:113)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3792)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.triggersFired(JobStoreSupport.java:2912)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:336)
Caused by: java.sql.SQLException: (conn:83) Lock wait timeout exceeded; try restarting …Run Code Online (Sandbox Code Playgroud) 我一直在尝试让 Quartz 在 Spring Boot 中使用 R2DBC 时工作。到目前为止,我还没有弄清楚如何做到这一点。这是因为当创建 JDBC 数据源时,它会尝试初始化我的 R2DBC 存储库,但它无法执行此操作,因为 R2DBC 本质上是反应性的,而 JDBC 本质上是阻塞的。
我考虑过的替代方案
相关 Gradle 依赖项
dependencies {
implementation("io.projectreactor.netty:reactor-netty:0.9.7.RELEASE")
implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
implementation("org.springframework.boot:spring-boot-starter-quartz")
implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
runtimeOnly("com.h2database:h2")
implementation("io.r2dbc:r2dbc-h2:0.8.3.RELEASE")
}
Run Code Online (Sandbox Code Playgroud)
我当前的石英配置
@Configuration
class QuartzConfig {
@Bean
@QuartzDataSource
fun dataSource(props: DataSourceProperties): DataSource {
return props.initializeDataSourceBuilder().type(HikariDataSource::class.java).build()
}
}
Run Code Online (Sandbox Code Playgroud)
相关R2DBC配置:
abstract class R2DbcConfiguration : AbstractR2dbcConfiguration() {
override fun getCustomConverters(): MutableList<Any> {
return mutableListOf(
// some custom converters
)
}
@Bean
fun connectionFactoryInitializer( …Run Code Online (Sandbox Code Playgroud) 我有以下内容quartz.properties:
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.dataSource=dataSource
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.tablePrefix=qrtz_
org.quartz.threadPool.threadCount=1
org.quartz.scheduler.skipUpdateCheck=true
org.quartz.plugin.triggerHistory.class=org.quartz.plugins.history.LoggingTriggerHistoryPlugin
Run Code Online (Sandbox Code Playgroud)
另外,我补充道QuartzConfiguration:
@Configuration
@EnableScheduling
public class QuartzConfiguration {
public static final String CONTEXT_KEY = "applicationContext";
@Autowired
private DataSource dataSource;
@Bean
public SchedulerFactoryBean schedulerFactoryBean() {
SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
scheduler.setApplicationContextSchedulerContextKey("applicationContext");
scheduler.setConfigLocation(new ClassPathResource("quartz.properties"));
scheduler.setDataSource(dataSource);
scheduler.setWaitForJobsToCompleteOnShutdown(true);
return scheduler;
}
}
Run Code Online (Sandbox Code Playgroud)
在application.properties我已经定义:
#PostgreSQL
spring.datasource.url=${postgresql.datasource.url}
spring.datasource.username=${postgresql.datasource.username}
spring.datasource.password=${postgresql.datasource.password}
Run Code Online (Sandbox Code Playgroud)
现在,在启动过程中,应用程序失败,并出现以下异常:
Caused by: org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'dataSource': java.sql.SQLException: There is no DataSource named 'dataSource' [See nested exception: java.sql.SQLException: …Run Code Online (Sandbox Code Playgroud) 我有一个小的独立应用程序,可将调度程序配置为正常终止。使用以下配置:
@Bean
public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setWaitForTasksToCompleteOnShutdown(true);
scheduler.setAwaitTerminationSeconds(60);
return scheduler;
}
Run Code Online (Sandbox Code Playgroud)
我可以让它正常终止调度程序,但前提是我没有任何@Scheduled(cron =)任务。一旦有了其中之一,无论什么调度程序都会卡住,直到超时。我已经尝试过使用执行器配置它,并手动执行shutdown / await,效果完全一样。
这些cron作业甚至没有运行。例如,它们设置为在夜间的固定时间运行。
春季版本:4.2.8.RELEASE
这将在超时结束时发生:
2017.07.28 01:44:56 [Thread-3] WARN Timed out while waiting for executor 'taskScheduler' to terminate
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
我需要手动调用一些 Quartz.NET 作业并等待它们完成。请参阅下面的简化示例代码:
[HttpPost("[action]/{jobKey}")]
public async Task<IActionResult> StartJob(string jobKey)
{
await _schedulerService.Scheduler.TriggerJob(new Quartz.JobKey(jobKey));
return Ok();
}
Run Code Online (Sandbox Code Playgroud)
但是,使用 TriggerJob 也不会等待作业本身的执行完成。使用 Quartz.NET 可以实现这一点吗?我在 .NET Core 上使用它,并使用以下包:
<PackageReference Include="Quartz" Version="3.0.7" />
Run Code Online (Sandbox Code Playgroud) 我将 Quartz 与 Spring Boot 和 postgres 数据库一起使用作为 Quartz 内容的持久存储。我想在控制台中查看 sql 日志,quartz 正在后台执行。我尝试了许多配置属性来启用它,但没有一个起作用。有人可以告诉我如何启用它吗?到目前为止我使用了以下道具:
spring:
quartz:
job-store-type: jdbc
jdbc:
initialize-schema: NEVER
properties:
org:
quartz:
jobStore:
driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
jpa:
show-sql: true
properties:
hibernate:
show_sql: true
use_sql_comments: true
format_sql: true
logging:
level:
org:
quartz: DEBUG
hibernate:
SQL: DEBUG
postgres: DEBUG
springframework:
jdbc:
core:
JdbcTemplate: DEBUG
StatementCreatorUtils: TRACE
Run Code Online (Sandbox Code Playgroud) 我有一项工作,只有一个步骤,其中包含JdbcPagingItemReader,Custom Processor并custom writer写入elasticsearch。
步骤配置为
jobBuilderFactory.get("job")
.<Entity, WriteRequest>chunk(10000)
.reader(reader)
.processor(processor)
.writer(elasticSearchWriter)
.faultTolerant()
.skipLimit(3)
.skip(Exception.class)
.build();
Run Code Online (Sandbox Code Playgroud)
作业配置是
stepBuilderFactory.get("step")
.preventRestart()
.incrementer(new RunIdIncrementer())
.listener(listener)
.flow(step)
.end()
.build();
Run Code Online (Sandbox Code Playgroud)
该作业由预定的 Quartz 作业每隔几分钟触发一次。
在环境中运行此程序时,STEP成功完成,但作业会在 status=COMPLETED和 exit_status=状态停留UNKNOWN很长时间,通常为 3 - 5 小时,然后完成。
在此非活动期间没有生成任何日志。
一项观察结果是,commit_countinbatch_step_execution的值几乎等于read_count通常取决于块大小的值。**此外,我可以看到作家一件一件地写产品,而不是写整块。**
*在本地计算机上运行作业时,它工作得很好。
知道为什么会发生这种情况吗?
尝试将块大小减少到 1000。现在问题不再那么频繁,但commit_count仍然会上升很多。
quartz ×10
java ×4
spring-boot ×4
quartz.net ×2
spring ×2
.net ×1
c# ×1
datasource ×1
kotlin ×1
mariadb ×1
scheduler ×1
spring-batch ×1
spring-jdbc ×1
yaml ×1