Hi sunkai, I have some questions about this API: 1. What's the returning of `build()`? 2. What if the Job has multiple ElasticJob annotations? 3. Could we consider move the RegCenter parameter to `newBuilder` or somewhere like require-args constructor? I think the RegCenter is a necessary arrangement.
I think it would be helpful if you can provide a document to describe the detail about your API design. ------------------ Sincerely, Weijie Wu (TeslaCN) Apache ShardingSphere sk c <[email protected]> 于2021年8月13日周五 下午4:32写道: > > Hello Weijie, > > Yes, passing an instance is batter. > > ``` > ScheduleAnnotationJobBootstrap.newBuilder(new > SimpleTestJob()).setRegCenter(regCenter).addExtraConfigurations(tracingConfig).build().schedule(); > ``` > > it looks good. > > ------------------ > Sincerely, > SunKai Cai (skai) > > 吴伟杰 <[email protected]> 于2021年8月13日周五 下午3:18写道: > > > Hi sunkai > > > > ``` > > > > ScheduleAnnotationJobBootstrap.newBuilder(SimpleTestJob.class).setRegCenter(regCenter).addExtraConfigurations(tracingConfig).build().schedule(); > > ``` > > The API require a class means it force developer to provide a no-args > > constructor. How about passing an instance? > > > > > > ------------------ > > > > Sincerely, > > Weijie Wu (TeslaCN) > > Apache ShardingSphere > > > > sk c <[email protected]> 于2021年8月12日周四 下午12:37写道: > > > > > > Hello Weijie, > > > > > > Annotation to use it without Spring, maybe we can do that: > > > > > > ``` > > > @ElasticScheduled( > > > cron = "0/5 * * * * ?", > > > jobName = "SimpleTestJob", > > > shardingTotalCount = 3, > > > shardingItemParameters = "0=Beijing,1=Shanghai,2=Guangzhou", > > > props = { > > > @ElasticJobProp(key = "print.title", value = "test > > title"), > > > @ElasticJobProp(key = "print.content", value = "test > > > content") > > > } > > > ) > > > public class SimpleTestJob implements CustomJob { > > > > > > @Override > > > public void execute(final ShardingContext shardingContext) { > > > } > > > > > > } > > > ``` > > > > > > ``` > > > > > > public final class JavaMain { > > > ..... > > > public static void main(final String[] args) throws IOException { > > > CoordinatorRegistryCenter regCenter = setUpRegistryCenter(); > > > TracingConfiguration<DataSource> tracingConfig = new > > > TracingConfiguration<>("RDB", setUpEventTraceDataSource()); > > > > > > > > ScheduleAnnotationJobBootstrap.newBuilder(SimpleTestJob.class).setRegCenter(regCenter).addExtraConfigurations(tracingConfig).build().schedule(); > > > } > > > ..... > > > } > > > > > > ``` > > > > > > > > > ------------------ > > > Sincerely, > > > SunKai Cai (skai) > > > > > > 吴伟杰 <[email protected]> 于2021年8月12日周四 上午11:07写道: > > > > > > > Hi sunkai, > > > > > > > > If we define the annotations in API module, we also need to define how > > > > to use it without Spring. > > > > > > > > ------------------ > > > > > > > > Sincerely, > > > > Weijie Wu (TeslaCN) > > > > Apache ShardingSphere > > > > > > > > sk c <[email protected]> 于2021年8月11日周三 下午7:53写道: > > > > > > > > > > Hello Weijie, > > > > > > > > > > Thank you, good ideas. Maybe we can do that: > > > > > > > > > > > > > > > 1. Move the `@ElasticScheduled` annotation to `api/annotation`. We > > can > > > > > have the same annotation , and different annotation processor without > > > > > Spring. > > > > > > > > > > 2. Yes, this is important. I have a idea like that: > > > > > > > > > > Set Scheduled > > > > > ``` > > > > > package > > > > > > > > > > > org.apache.shardingsphere.elasticjob.lite.spring.core.annotation.job.impl; > > > > > @ElasticScheduled( > > > > > cron = "0/5 * * * * ?", > > > > > jobName = SimpleTestJobFirst > > > > > shardingTotalCount = 3, > > > > > shardingItemParameters = "0=Beijing,1=Shanghai,2=Guangzhou", > > > > > extraConfigurations = {"SimpleTracingConfiguration"} > > > > > ) > > > > > public class SimpleTestJob implements CustomJob { > > > > > > > > > > @Override > > > > > public void execute(final ShardingContext shardingContext) { > > > > > } > > > > > > > > > > } > > > > > ``` > > > > > > > > > > Set Configurable > > > > > > > > > > ``` > > > > > //spring example > > > > > @Configurable > > > > > @EnableElastic(scanBasePackages = > > > > > > > > > > > "org.apache.shardingsphere.elasticjob.lite.spring.core.annotation.job.impl") > > > > > public class ElasticConfig { > > > > > > > > > > @Bean > > > > > public DataSource dataSource() { > > > > > BasicDataSource dataSource = new BasicDataSource(); > > > > > dataSource.setDriverClassName("org.h2.Driver"); > > > > > dataSource.setUrl("jdbc:h2:mem:job_event_storage"); > > > > > dataSource.setUsername("sa"); > > > > > dataSource.setPassword(""); > > > > > } > > > > > > > > > > @Bean("SimpleTracingConfiguration") > > > > > public TracingConfiguration<DataSource> myTracingConfiguration() > > { > > > > > return new TracingConfiguration<>("RDB", dataSource()); > > > > > } > > > > > } > > > > > ``` > > > > > or > > > > > > > > > > ``` > > > > > //spring boot example > > > > > @Configurable > > > > > @EnableElastic(scanBasePackages = > > > > > > > > > > > "org.apache.shardingsphere.elasticjob.lite.spring.core.annotation.job.impl") > > > > > public class ElasticConfig { > > > > > > > > > > @ConditionalOnBean(DataSource.class) > > > > > @Bean("SimpleTracingConfiguration") > > > > > public TracingConfiguration<DataSource> > > myTracingConfiguration(final > > > > > DataSource dataSource) { > > > > > return new TracingConfiguration<>("RDB", dataSource); > > > > > } > > > > > } > > > > > ``` > > > > > > > > > > 3. Of course > > > > > > > > > > ------------------ > > > > > Sincerely, > > > > > SunKai Cai (skai) > > > > > > > > > > 吴伟杰 <[email protected]> 于2021年8月11日周三 下午6:38写道: > > > > > > > > > > > Hi Sunkai, > > > > > > > > > > > > I have some ideas about your proposal: > > > > > > 1. Could we consider using the annotation without Spring? > > > > > > 2. Could we configure the jobs by annotations only? How to > > configure > > > > > > the JobExtraConfiguration like TracingConfiguration by annotations? > > > > > > 3. Support using YAML to configure jobs without Spring. This can > > refer > > > > > > to how ShardingSphere does. > > > > > > > > > > > > ------------------ > > > > > > > > > > > > Sincerely, > > > > > > Weijie Wu (TeslaCN) > > > > > > Apache ShardingSphere > > > > > > > > > > > > sk c <[email protected]> 于2021年8月10日周二 下午3:43写道: > > > > > > > > > > > > > > Hi everyone, > > > > > > > > > > > > > > I prefer to discuss the annotation of ElasticJob plan. > > > > > > > > > > > > > > example: > > > > > > > > > > > > > > ``` > > > > > > > @ElasticScheduled( > > > > > > > cron = "0/5 * * * * ?", > > > > > > > jobName = "SimpleTestJobSecond", > > > > > > > shardingTotalCount = 3, > > > > > > > shardingItemParameters = > > "0=Beijing,1=Shanghai,2=Guangzhou", > > > > > > > jobListenerTypes = {"NOOP", "LOG"}, > > > > > > > props = { > > > > > > > @ElasticJobProp(key = "print.title", value = > > "test > > > > > > title"), > > > > > > > @ElasticJobProp(key = "print.content", value = > > "test > > > > > > > content") > > > > > > > } > > > > > > > ) > > > > > > > public class SimpleTestJob implements CustomJob { > > > > > > > > > > > > > > @Override > > > > > > > public void execute(final ShardingContext shardingContext) { > > > > > > > } > > > > > > > > > > > > > > } > > > > > > > ``` > > > > > > > > > > > > > > ``` > > > > > > > @Configuration > > > > > > > @EnableElastic(scanBasePackages = > > > > > > > "org.apache.shardingsphere.elasticjob.lite.example.job.simple") > > > > > > > public class ElasticConfig { > > > > > > > > > > > > > > } > > > > > > > ``` > > > > > > > > > > > > > > we can look at it on > > > > > > > https://github.com/apache/shardingsphere-elasticjob/pull/1954 > > > > > > > > > > > > > > I am going to work it soon. Please remind me if you have a > > > > suggestion. > > > > > > > > > > > > > > > > > > > > > ------------------ > > > > > > > Sincerely, > > > > > > > SunKai Cai (skai) > > > > > > > > > > > >
