### Start Casdoor Frontend Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/operation/web-console.en.md Navigate to the `web` directory and install dependencies, then start the Casdoor frontend development server. This step is necessary for the Casdoor SSO integration. ```bash cd web yarn install yarn start ``` -------------------------------- ### Setup Environment and Run Native Tests Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/configuration/graalvm-native-image.en.md Installs necessary tools, clones the repository, and executes native tests using a specific Maven profile. Ensure Docker is installed if testcontainers are used. ```bash sudo apt install unzip zip curl sed -y curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" sdk install java 22.0.2-graalce sdk use java 22.0.2-graalce sudo apt-get install build-essential zlib1g-dev -y git clone git@github.com:apache/shardingsphere-elasticjob.git cd ./shardingsphere-elasticjob/ ./mvnw -PnativeTestInElasticJob -T1C -e clean test ``` -------------------------------- ### Spring Boot Auto-configuration Example Source: https://context7.com/apache/shardingsphere-elasticjob/llms.txt Illustrates how to configure ElasticJob using `application.yml` for automatic setup and how to inject and trigger one-off jobs via `OneOffJobBootstrap`. ```APIDOC ## Spring Boot Auto-configuration Add `elasticjob-spring-boot-starter` and configure everything in `application.yml`. Job beans and bootstrap instances are created automatically; inject `OneOffJobBootstrap` beans by name for manual triggering. ### `application.yml` Configuration ```yaml # application.yml elasticjob: regCenter: serverLists: localhost:2181 namespace: my-springboot-app tracing: type: RDB # uses the application's primary DataSource automatically jobs: # Cron-scheduled SimpleJob orderJob: elasticJobClass: com.example.jobs.OrderJob cron: "0/30 * * * * ?" shardingTotalCount: 3 shardingItemParameters: "0=shard-A,1=shard-B,2=shard-C" failover: true overwrite: true # Cron-scheduled DataflowJob messageJob: elasticJobClass: com.example.jobs.MessageQueueJob cron: "0/5 * * * * ?" shardingTotalCount: 4 shardingItemParameters: "0=queue-0,1=queue-1,2=queue-2,3=queue-3" props: streaming.process: "true" # SCRIPT job (no Java class needed) cleanupScript: elasticJobType: SCRIPT cron: "0 0 2 * * ?" shardingTotalCount: 1 props: script.command.line: "/opt/scripts/cleanup.sh" # Manual one-off job exposed via HTTP reportJob: elasticJobClass: com.example.jobs.ReportGeneratorJob jobBootstrapBeanName: reportJobBean # name used to inject OneOffJobBootstrap shardingTotalCount: 4 shardingItemParameters: "0=Q1,1=Q2,2=Q3,3=Q4" jobErrorHandlerType: EMAIL props: email.host: smtp.example.com email.port: "465" email.username: alerts@example.com email.password: secret email.from: alerts@example.com email.to: ops@example.com ``` ### Job Class Example ```java // Job class — Spring beans are autowired normally @Component public class OrderJob implements SimpleJob { @Autowired private OrderRepository orderRepo; @Override public void execute(ShardingContext ctx) { orderRepo.findPendingByShard(ctx.getShardingParameter(), 100) .forEach(order -> orderRepo.markProcessed(order.getId())); } } ``` ### Triggering One-Off Job via REST ```java // Trigger the one-off job via a REST endpoint @RestController public class ReportController { @Resource(name = "reportJobBean") private OneOffJobBootstrap reportJob; @PostMapping("/api/reports/generate") public String generate() { reportJob.execute(); return "{\"status\":\"triggered\"}"; } } ``` ``` -------------------------------- ### Expand Shortcode Demo (Commented Example) Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/shortcodes/expand.en.md This is a commented-out example demonstrating the expand shortcode with default text. ```gohtml {{%/*expand*/%}} Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. {{%/* /expand*/%}} ``` -------------------------------- ### Configure and Start Restful Service Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/restful/README.md Configures the NettyRestfulService with a port, adds custom controllers and exception handlers, and then starts the service. ```java NettyRestfulServiceConfiguration configuration = new NettyRestfulServiceConfiguration(8080); configuration.addControllerInstance(new JobController()); configuration.addExceptionHandler(IllegalStateException.class, new CustomIllegalStateExceptionHandler()); RestfulService restfulService = new NettyRestfulService(configuration); restfulService.startup(); ``` -------------------------------- ### Get All Servers Brief Information Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/operation-api/_index.en.md Retrieve brief information for all job servers. ```java Collection getAllServersBriefInfo(); ``` -------------------------------- ### Expand Shortcode Demo (Uncommented) Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/shortcodes/expand.en.md This example demonstrates the expand shortcode with default text, suitable for a demo. ```gohtml {{%expand%}}Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.{{% /expand%}} ``` -------------------------------- ### HTTP Job Execution Output Example Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/job-api/job-interface.en.md This example shows the expected log output when the HTTP job is executed, including the source data and the sharding context transmitted as a JSON string. ```log execute from source : ejob, shardingContext : {"jobName":"scriptElasticDemoJob","shardingTotalCount":3,"jobParameter":"","shardingItem":0,"shardingParameter":"Beijing"} ``` -------------------------------- ### Markdown Ordered List Example Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/cont/markdown.en.md Demonstrates a standard ordered list in Markdown. ```markdown 1. Lorem ipsum dolor sit amet 2. Consectetur adipiscing elit 3. Integer molestie lorem at massa 4. Facilisis in pretium nisl aliquet 5. Nulla volutpat aliquam velit 6. Faucibus porta lacus fringilla vel 7. Aenean sit amet erat nunc 8. Eget porttitor lorem ``` -------------------------------- ### Script Job Example Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/job-api/job-interface.en.md Example of a simple bash script for a Script job. The script receives sharding execution context as arguments. ```bash #!/bin/bash echo sharding execution context is $* ``` -------------------------------- ### Get All Jobs Brief Information Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/operation-api/_index.en.md Retrieve brief information for all jobs in the system. ```java Collection getAllJobsBriefInfo(); ``` -------------------------------- ### Expand Shortcode with Custom Label (Commented Example) Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/shortcodes/expand.en.md This shows how to use the expand shortcode with a custom label, with the shortcode syntax commented out. ```gohtml {{%/*expand "Is this learn theme rocks ?" */%}}Yes !.{{%/* /expand*/%}} ``` -------------------------------- ### Sequence Diagram Example Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/shortcodes/mermaid.en.md Shows how to generate a sequence diagram using Mermaid syntax. This is useful for visualizing interactions between different participants over time. ```html {{}} sequenceDiagram participant Alice participant Bob Alice->>John: Hello John, how are you? loop Healthcheck John->John: Fight against hypochondria end Note right of John: Rational thoughts
prevail... John-->Alice: Great! John->Bob: How about you? Bob-->John: Jolly good! {{}} ``` -------------------------------- ### GANTT Chart Example Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/shortcodes/mermaid.en.md Illustrates the creation of a Gantt chart using Mermaid syntax. This is ideal for project management, showing task durations and dependencies. ```html {{}} gantt dateFormat YYYY-MM-DD title Adding GANTT diagram functionality to mermaid section A section Completed task :done, des1, 2014-01-06,2014-01-08 Active task :active, des2, 2014-01-09, 3d Future task : des3, after des2, 5d Future task2 : des4, after des3, 5d section Critical tasks Completed task in the critical line :crit, done, 2014-01-06,24h Implement parser and jison :crit, done, after des1, 2d Create tests for parser :crit, active, 3d Future task in critical line :crit, 5d Create tests for renderer :2d Add to mermaid :1d {{}} ``` -------------------------------- ### Start One-Off Scheduling Job Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/job-api/java-api.en.md Execute a one-off job using OneOffJobBootstrap. The `execute()` method can be called multiple times to trigger the job on demand. Proper setup of the registry center and job configuration is required. ```java public class JobDemo { public static void main(String[] args) { OneOffJobBootstrap jobBootstrap = new OneOffJobBootstrap(createRegistryCenter(), new MyJob(), createJobConfiguration()); // One-time scheduling can be called multiple times jobBootstrap.execute(); jobBootstrap.execute(); jobBootstrap.execute(); } private static CoordinatorRegistryCenter createRegistryCenter() { CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration("zk_host:2181", "elastic-job-demo")); regCenter.init(); return regCenter; } private static JobConfiguration createJobConfiguration() { // Create job configuration ... } } ``` -------------------------------- ### Start Casdoor Backend Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/operation/web-console.en.md Run the Casdoor backend server in development mode using the provided Go command. This is a prerequisite for integrating Casdoor SSO with the ShardingSphere-ElasticJob console. ```bash go run main.go ``` -------------------------------- ### HTML Ordered List Example Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/cont/markdown.en.md The HTML equivalent of a standard ordered list. ```html
  1. Lorem ipsum dolor sit amet
  2. Consectetur adipiscing elit
  3. Integer molestie lorem at massa
  4. Facilisis in pretium nisl aliquet
  5. Nulla volutpat aliquam velit
  6. Faucibus porta lacus fringilla vel
  7. Aenean sit amet erat nunc
  8. Eget porttitor lorem
``` -------------------------------- ### Configure Database Tracing with Java API Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/tracing/java-api.en.md Initialize a DataSource, define a `TracingConfiguration` using the database type and DataSource, and then add this configuration to the job's extra configurations before scheduling the job. This setup is for database-based tracing. ```java // init DataSource DataSource dataSource = ...; // define tracing configuration based on relation database TracingConfiguration tracingConfig = new TracingConfiguration<>("RDB", dataSource); // init registry center CoordinatorRegistryCenter regCenter = ...; // init job configuration JobConfiguration jobConfig = ...; jobConfig.getExtraConfigurations().add(tracingConfig); new ScheduleJobBootstrap(regCenter, jobConfig).schedule(); ``` -------------------------------- ### Markdown Unordered List Example Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/cont/markdown.en.md Demonstrates a nested unordered list structure in Markdown. ```markdown + Lorem ipsum dolor sit amet + Consectetur adipiscing elit + Integer molestie lorem at massa + Facilisis in pretium nisl aliquet + Nulla volutpat aliquam velit - Phasellus iaculis neque - Purus sodales ultricies - Vestibulum laoreet porttitor sem - Ac tristique libero volutpat at + Faucibus porta lacus fringilla vel + Aenean sit amet erat nunc + Eget porttitor lorem ``` -------------------------------- ### ElasticJob Execution Log Fragments Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/spring/boot-starter/README.md Example log output demonstrating the execution of SimpleJob, DataflowJob (fetch and process), and ScriptJob. ```log Item: 2 | Time: 14:18:00 | Thread: 391 | DATAFLOW FETCH Item: 0 | Time: 14:18:00 | Thread: 386 | DATAFLOW FETCH Item: 0 | Time: 14:18:00 | Thread: 387 | SIMPLE Item: 1 | Time: 14:18:00 | Thread: 389 | SIMPLE Item: 2 | Time: 14:18:00 | Thread: 393 | SIMPLE Item: 1 | Time: 14:18:00 | Thread: 388 | DATAFLOW FETCH Item: 1 | Time: 14:18:00 | Thread: 388 | DATAFLOW PROCESS Item: 0 | Time: 14:18:00 | Thread: 386 | DATAFLOW PROCESS Item: 2 | Time: 14:18:00 | Thread: 391 | DATAFLOW PROCESS SCRIPT Job: {"jobName":"scriptJob","taskId":"scriptJob@-@0,1,2@-@READY@-@192.168.3.233@-@28250","shardingTotalCount":3,"jobParameter":"","shardingItem":1} SCRIPT Job: {"jobName":"scriptJob","taskId":"scriptJob@-@0,1,2@-@READY@-@192.168.3.233@-@28250","shardingTotalCount":3,"jobParameter":"","shardingItem":2} SCRIPT Job: {"jobName":"scriptJob","taskId":"scriptJob@-@0,1,2@-@READY@-@192.168.3.233@-@28250","shardingTotalCount":3,"jobParameter":"","shardingItem":0} ``` -------------------------------- ### Start Timed Scheduling Job Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/job-api/java-api.en.md Initiate a timed scheduling job using ScheduleJobBootstrap. This can be done by providing a job class instance or a job type string. Ensure the registry center and job configuration are correctly set up. ```java public class JobDemo { public static void main(String[] args) { // Class-based Scheduling Jobs new ScheduleJobBootstrap(createRegistryCenter(), new MyJob(), createJobConfiguration()).schedule(); // Type-based Scheduling Jobs new ScheduleJobBootstrap(createRegistryCenter(), "MY_TYPE", createJobConfiguration()).schedule(); } private static CoordinatorRegistryCenter createRegistryCenter() { CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration("zk_host:2181", "elastic-job-demo")); regCenter.init(); return regCenter; } private static JobConfiguration createJobConfiguration() { // Create job configuration ... } } ``` -------------------------------- ### Configure Distributed Job Listeners with Java API Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/job-listener/java-api.en.md This example shows how to configure a job to use distributed listener types via the Java API. It includes setting up the registry center and job configuration. ```java public class JobMain { public static void main(String[] args) { new ScheduleJobBootstrap(createRegistryCenter(), createJobConfiguration()).schedule(); } private static CoordinatorRegistryCenter createRegistryCenter() { CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration("zk_host:2181", "elastic-job-demo")); regCenter.init(); return regCenter; } private static JobConfiguration createJobConfiguration() { JobConfiguration jobConfiguration = JobConfiguration.newBuilder("test", 2) .jobListenerTypes("simpleListener", "distributeListener").build(); } } ``` -------------------------------- ### Add Icon to Menu Entry Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/cont/pages/_index.en.md Prepend an icon to a menu entry by using the `pre` parameter in the Front Matter. This example uses a Font Awesome Github icon. ```toml +++ title = "Github repo" pre = " " +++ ``` -------------------------------- ### Get Jobs Brief Information by IP Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/operation-api/_index.en.md Retrieve brief information for all jobs running on a specific server IP address. ```java Collection getJobsBriefInfo(String ip); ``` -------------------------------- ### Flowchart Example with Alignment Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/shortcodes/mermaid.en.md Demonstrates how to create a flowchart using Mermaid syntax within the shortcode. The `align="left"` attribute controls the horizontal alignment of the diagram. ```html {{}} graph LR; A[Hard edge] -->|Link text| B(Round edge) B --> C{Decision} C -->|One| D[Result one] C -->|Two| E[Result two] {{}} ``` -------------------------------- ### Import Maven Dependency Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/quick-start/_index.en.md Add the elasticjob-bootstrap dependency to your Maven project to get started. ```xml org.apache.shardingsphere.elasticjob elasticjob-bootstrap ${latest.release.version} ``` -------------------------------- ### Launch Simple, Script, and Annotated Jobs with ScheduleJobBootstrap Source: https://context7.com/apache/shardingsphere-elasticjob/llms.txt Demonstrates launching different job types using ScheduleJobBootstrap. Ensure CoordinatorRegistryCenter is initialized. The 'SCRIPT' job type does not require a Java class. ```java import org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap; import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter; import org.apache.shardingsphere.elasticjob.api.JobConfiguration; CoordinatorRegistryCenter regCenter = /* initialised ZookeeperRegistryCenter */; // 1. Launch a SimpleJob instance ScheduleJobBootstrap simpleBootstrap = new ScheduleJobBootstrap( regCenter, new OrderJob(), JobConfiguration.newBuilder("orderProcessingJob", 3) .cron("0/30 * * * * ?") .shardingItemParameters("0=shard-A,1=shard-B,2=shard-C") .failover(true) .build() ); simpleBootstrap.schedule(); // 2. Launch a SCRIPT job (type-string form, no Java class needed) ScheduleJobBootstrap scriptBootstrap = new ScheduleJobBootstrap( regCenter, "SCRIPT", JobConfiguration.newBuilder("cleanupScript", 1) .cron("0 0 2 * * ?") // every day at 02:00 .setProperty("script.command.line", "/opt/scripts/cleanup.sh") .build() ); scriptBootstrap.schedule(); // 3. Launch via annotation (reads config from @ElasticJobConfiguration on the class) ScheduleJobBootstrap annotationBootstrap = new ScheduleJobBootstrap(regCenter, new AnnotatedJob()); annotationBootstrap.schedule(); // Graceful shutdown simpleBootstrap.shutdown(); ``` -------------------------------- ### Configure Data Source and Tracing Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/tracing/spring-boot-starter.en.md Set up your data source connection details and specify the tracing type in your application.yaml or application.properties file. ```yaml spring: datasource: url: jdbc:h2:mem:job_event_storage driver-class-name: org.h2.Driver username: sa password: elasticjob: tracing: type: RDB ``` -------------------------------- ### HTML Unordered List Example Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/cont/markdown.en.md The HTML equivalent of a nested unordered list. ```html
  • Lorem ipsum dolor sit amet
  • Consectetur adipiscing elit
  • Integer molestie lorem at massa
  • Facilisis in pretium nisl aliquet
  • Nulla volutpat aliquam velit
    • Phasellus iaculis neque
    • Purus sodales ultricies
    • Vestibulum laoreet porttitor sem
    • Ac tristique libero volutpat at
  • Faucibus porta lacus fringilla vel
  • Aenean sit amet erat nunc
  • Eget porttitor lorem
``` -------------------------------- ### Get Job Sharding Information Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/operation-api/_index.en.md Retrieve the sharding information for a specific job. ```java Collection getShardingInfo(String jobName); ``` -------------------------------- ### Import PGP Keys Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/downloads/_index.en.md Import the PGP keys from the KEYS file to verify signatures. Use the appropriate command for your GPG or PGP version. ```shell gpg -i KEYS ``` ```shell pgpk -a KEYS ``` ```shell pgp -ka KEYS ``` -------------------------------- ### Schedule Job with Bootstrap Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/quick-start/_index.en.md Use ScheduleJobBootstrap to schedule your job. This requires a registry center and job configuration. ```java public class MyJobDemo { public static void main(String[] args) { new ScheduleJobBootstrap(createRegistryCenter(), new MyJob(), createJobConfiguration()).schedule(); } private static CoordinatorRegistryCenter createRegistryCenter() { CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration("zk_host:2181", "my-job")); regCenter.init(); return regCenter; } private static JobConfiguration createJobConfiguration() { // create job configuration // ... } } ``` -------------------------------- ### Configure Basic Menu Shortcuts Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/cont/menushortcuts.en.md Add custom links to the navigation menu by defining `[[menu.shortcuts]]` entries in your `config.toml`. Use `name`, `url`, and `weight` to define each shortcut. An `identifier` can be used for programmatic access. ```toml [[menu.shortcuts]] name = " Github repo" identifier = "ds" url = "https://github.com/matcornic/hugo-theme-learn" weight = 10 [[menu.shortcuts]] name = " Showcases" url = "/showcase" weight = 11 [[menu.shortcuts]] name = " Hugo Documentation" identifier = "hugodoc" url = "https://gohugo.io/" weight = 20 [[menu.shortcuts]] name = " Credits" url = "/credits" weight = 30 ``` -------------------------------- ### HTML Blockquote Example Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/cont/markdown.en.md Blockquotes can also be represented using HTML `
` tags. ```html

Fusion Drive combines a hard drive with a flash storage (solid-state drive) and presents it as a single logical volume with the space of both drives combined.

``` -------------------------------- ### Get Brief Job Information Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/operation-api/_index.en.md Retrieve brief information for a specific job by its name. ```java JobBriefInfo getJobBriefInfo(String jobName); ``` -------------------------------- ### Get Total Job Count Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/operation-api/_index.en.md Retrieve the total number of jobs managed by the system. ```java int getJobsTotalCount(); ``` -------------------------------- ### Configure Simple Job in Properties Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/configuration/spring-boot-starter.en.md Define a ScheduleJobBootstrap using properties format. 'elastic-job-class' and 'cron' are required for schedule jobs. ```properties elasticjob.jobs.simpleJob.elastic-job-class=org.apache.shardingsphere.elasticjob.kernel.example.job.SpringBootSimpleJob elasticjob.jobs.simpleJob.cron=0/5 * * * * ? elasticjob.jobs.simpleJob.time-zone=GMT+08:00 elasticjob.jobs.simpleJob.sharding-total-count=3 elasticjob.jobs.simpleJob.sharding-item-parameters=0=Beijing,1=Shanghai,2=Guangzhou ``` -------------------------------- ### Markdown Blockquote Example Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/cont/markdown.en.md Use `>` to create a blockquote in Markdown. This can also be used for nested blockquotes. ```markdown > **Fusion Drive** combines a hard drive with a flash storage (solid-state drive) and presents it as a single logical volume with the space of both drives combined. ``` ```markdown > Donec massa lacus, ultricies a ullamcorper in, fermentum sed augue. Nunc augue augue, aliquam non hendrerit ac, commodo vel nisi. >> Sed adipiscing elit vitae augue consectetur a gravida nunc vehicula. Donec auctor odio non est accumsan facilisis. Aliquam id turpis in dolor tincidunt mollis ac eu diam. ``` -------------------------------- ### Get Total Server Count Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/operation-api/_index.en.md Retrieve the total number of job servers in the distributed system. ```java int getServersTotalCount(); ``` -------------------------------- ### Markdown Notice Example Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/cont/markdown.en.md Notices are handled via a dedicated plugin, overriding the old blockquote syntax. ```markdown {{% notice note %}} The old mechanism for notices overriding the block quote syntax (`>>>`) has been deprecated. Notices are now handled via a dedicated plugin called [Markdown Notices](https://github.com/getgrav/grav-plugin-markdown-notices) {{% /notice %}} ``` -------------------------------- ### Configure Common Job Listeners with Java API Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/job-listener/java-api.en.md This snippet demonstrates how to initialize a job with common listener types using the Java API. Ensure the CoordinatorRegistryCenter and JobConfiguration are properly set up. ```java public class JobMain { public static void main(String[] args) { new ScheduleJobBootstrap(createRegistryCenter(), createJobConfiguration()).schedule(); } private static CoordinatorRegistryCenter createRegistryCenter() { CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration("zk_host:2181", "elastic-job-demo")); regCenter.init(); return regCenter; } private static JobConfiguration createJobConfiguration() { JobConfiguration jobConfiguration = JobConfiguration.newBuilder("test", 2) .jobListenerTypes("simpleListener", "distributeListener").build(); } } ``` -------------------------------- ### Activate Search in config.toml Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/basics/configuration/_index.en.md Configure the `outputs` section in your `config.toml` to include 'JSON' for home page output. This enables the generation of a `lunr.js` search index. ```toml [outputs] home = [ "HTML", "RSS", "JSON"] ``` -------------------------------- ### Configure Multilingual Menu Shortcuts Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/cont/menushortcuts.en.md For multilingual websites, define language-specific shortcuts by prefixing the menu configuration with `Languages.` in `config.toml`. This allows different menu items for each language. ```toml [Languages] [Languages.en] title = "Documentation for Hugo Learn Theme" weight = 1 languageName = "English" [[Languages.en.menu.shortcuts]] name = " Github repo" identifier = "ds" url = "https://github.com/matcornic/hugo-theme-learn" weight = 10 [[Languages.en.menu.shortcuts]] name = " Showcases" url = "/showcase" weight = 11 [[Languages.en.menu.shortcuts]] name = " Hugo Documentation" identifier = "hugodoc" url = "https://gohugo.io/" weight = 20 [[Languages.en.menu.shortcuts]] name = " Credits" url = "/credits" weight = 30 [Languages.fr] title = "Documentation du thème Hugo Learn" weight = 2 languageName = "Français" [[Languages.fr.menu.shortcuts]] name = " Repo Github" identifier = "ds" url = "https://github.com/matcornic/hugo-theme-learn" weight = 10 [[Languages.fr.menu.shortcuts]] name = " Vitrine" url = "/showcase" weight = 11 [[Languages.fr.menu.shortcuts]] name = " Documentation Hugo" identifier = "hugodoc" url = "https://gohugo.io/" weight = 20 [[Languages.fr.menu.shortcuts]] name = " Crédits" url = "/credits" weight = 30 ``` -------------------------------- ### Trigger job execution Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/operation-api/_index.en.md Triggers a job execution if it does not conflict with the currently running job. This flag is automatically cleared after the job starts. ```APIDOC ## Trigger job execution ### Description The job will only trigger execution if it does not conflict with the currently running job, and this flag will be automatically cleared after it is started. ### Method Signature `void trigger(String jobName)` ### Parameters #### Path Parameters - **jobName** (String) - Required - Job name ``` -------------------------------- ### Configure Listener Port for Job Dump Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/job-api/java-api.en.md Set up a SnapshotService to listen on a specified port for job dumping. This is useful for exporting job runtime information for debugging in production environments. Ensure the registry center is initialized. ```java public class JobMain { public static void main(final String[] args) { SnapshotService snapshotService = new SnapshotService(regCenter, 9888).listen(); } private static CoordinatorRegistryCenter createRegistryCenter() { // create registry center } } ``` -------------------------------- ### Implement a SimpleJob in Spring Boot Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/spring/boot-starter/README.md Example of implementing a `SimpleJob` for ElasticJob within a Spring Boot application. Ensure the job class is annotated with `@Component`. ```java @Component public class SpringBootSimpleJob implements SimpleJob { @Autowired private FooRepository fooRepository; @Override public void execute(ShardingContext shardingContext) { System.out.println(String.format("Item: %s | Time: %s | Thread: %s | %s", shardingContext.getShardingItem(), new SimpleDateFormat("HH:mm:ss").format(new Date()), Thread.currentThread().getId(), "SIMPLE")); List data = fooRepository.findTodoData(shardingContext.getShardingParameter(), 10); for (Foo each : data) { fooRepository.setCompleted(each.getId()); } } } ``` -------------------------------- ### Create New Hugo Site Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/basics/installation/_index.en.md Use the Hugo CLI to create a new website project. Replace '' with your desired project name. ```bash hugo new site ``` -------------------------------- ### Verify Release Signature with GPG Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/downloads/_index.en.md Verify the integrity of downloaded binaries or source files using their corresponding .asc signature files and GPG. Ensure you have downloaded both the release file and its .asc signature file. ```shell gpg --verify apache-shardingsphere-********.asc apache-shardingsphere-elasticjob-********* ``` -------------------------------- ### Basic Button Shortcode Usage Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/shortcodes/button.en.md Demonstrates the basic usage of the button shortcode to create a clickable link. ```go-html-template {{%/* button href="https://getgrav.org/" */%}}Get Grav{{%/* /button */%}} ``` ```go-html-template {{% button href="https://getgrav.org/" %}}Get Grav{{% /button %}} ``` -------------------------------- ### Trigger Job Execution Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/operation-api/_index.en.md Trigger a job execution. The job will only execute if it does not conflict with a currently running job. This flag is automatically cleared after the job starts. ```java void trigger(String jobName); ``` -------------------------------- ### Create RestfulController Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/restful/README.md Defines a controller for handling RESTful requests with specified mappings for POST and GET methods. It includes parameters from path, query, and request body. ```java @ContextPath("/job") public class JobController implements RestfulController { @Mapping(method = Http.POST, path = "/{group}/{jobName}") public JobPojo createJob(@Param(name = "group", source = ParamSource.PATH) final String group, @Param(name = "jobName", source = ParamSource.PATH) final String jobName, @Param(name = "cron", source = ParamSource.QUERY) final String cron, @RequestBody String description) { JobPojo jobPojo = new JobPojo(); jobPojo.setName(jobName); jobPojo.setCron(cron); jobPojo.setGroup(group); jobPojo.setDescription(description); return jobPojo; } @Mapping(method = Http.GET, pattern = "/code/204") @Returning(code = 204) public Object return204() { return null; } } ``` -------------------------------- ### Verify Release Signature with PGP Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/downloads/_index.en.md Verify the integrity of downloaded binaries or source files using their corresponding .asc signature files and PGP. Ensure you have downloaded both the release file and its .asc signature file. ```shell pgpv apache-shardingsphere-elasticjob-********.asc ``` ```shell pgp apache-shardingsphere-elasticjob-********.asc ``` -------------------------------- ### Serve Hugo Website Locally Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/basics/installation/_index.en.md Launch a local development server to preview your Hugo website. The site will be accessible at http://localhost:1313 and will automatically refresh on file changes. ```bash hugo serve ``` -------------------------------- ### Configure Job Info Dump with Properties Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/configuration/spring-boot-starter.en.md Configure the port for job info dumping using properties. The Spring Boot Starter automatically enables dumping if a port is specified. ```properties elasticjob.dump.port=9888 ``` -------------------------------- ### Configure Event Tracing with Properties Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/configuration/spring-boot-starter.en.md Use these properties to enable RDB event tracing. Specify job names to include or exclude from tracing. If both are null, all jobs are traced. ```properties elasticjob.tracing.type=RDB elasticjob.tracing.excludeJobNames=[ job-name ] ``` -------------------------------- ### Checkout Old Version of Hugo Learn Theme Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/README.md To use an older version of the Hugo Learn Theme, checkout a specific git tag. This example shows how to checkout version 1.1.0. ```bash cd themes/hugo-theme-learn git checkout tags/1.1.0 ``` -------------------------------- ### Enable Job Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/operation-api/_index.en.md Enable a job on a specific server. ```java void enable(String jobName, String serverIp); ``` -------------------------------- ### Configure ElasticJob with YAML Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/job-api/spring-boot-starter.en.md Configure ZooKeeper connection details and job settings in the application's YAML file. The starter automatically creates job bootstrap instances. ```yaml elasticjob: regCenter: serverLists: localhost:6181 namespace: elasticjob-springboot jobs: dataflowJob: elasticJobClass: org.apache.shardingsphere.elasticjob.dataflow.job.DataflowJob cron: 0/5 * * * * ? shardingTotalCount: 3 shardingItemParameters: 0=Beijing,1=Shanghai,2=Guangzhou scriptJob: elasticJobType: SCRIPT cron: 0/10 * * * * ? shardingTotalCount: 3 props: script.command.line: "echo SCRIPT Job: " ``` -------------------------------- ### Trigger One-Off Job via REST Endpoint in Spring Boot Source: https://context7.com/apache/shardingsphere-elasticjob/llms.txt Inject `OneOffJobBootstrap` by its configured bean name to manually trigger a one-off job. This example shows triggering a report generation job via a POST request. ```java // Trigger the one-off job via a REST endpoint @RestController public class ReportController { @Resource(name = "reportJobBean") private OneOffJobBootstrap reportJob; @PostMapping("/api/reports/generate") public String generate() { reportJob.execute(); return "{\"status\":\"triggered\"}"; } } ``` -------------------------------- ### Configure Snapshot Service for Job Dump Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/job-api/spring-namespace.en.md This XML configuration sets up a ZooKeeper registry center and enables the `SnapshotService` to listen on a specified port for dumping job runtime information. ```xml ``` -------------------------------- ### Trigger On-Demand Jobs with OneOffJobBootstrap Source: https://context7.com/apache/shardingsphere-elasticjob/llms.txt Shows how to use OneOffJobBootstrap for jobs without a cron expression, ideal for event-driven or ad-hoc tasks. The JobConfiguration must not include a cron value. An example of exposing an HTTP endpoint to trigger the job is also provided. ```java import org.apache.shardingsphere.elasticjob.bootstrap.type.OneOffJobBootstrap; // Note: JobConfiguration must NOT have a cron value JobConfiguration oneOffConfig = JobConfiguration .newBuilder("reportGeneratorJob", 4) .shardingItemParameters("0=Q1,1=Q2,2=Q3,3=Q4") .jobParameter("year=2024") .build(); OneOffJobBootstrap oneOffBootstrap = new OneOffJobBootstrap(regCenter, new ReportGeneratorJob(), oneOffConfig); // Trigger all instances oneOffBootstrap.execute(); // In a Spring REST controller — expose HTTP endpoint to trigger the job on demand @RestController public class ReportController { @Resource(name = "reportJobBean") private OneOffJobBootstrap reportJob; @PostMapping("/api/reports/generate") public String triggerReport() { reportJob.execute(); return "{\"status\":\"triggered\"}"; } } ``` -------------------------------- ### Configure and Schedule HTTP Job Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/usage/job-api/job-interface.en.md This Java snippet demonstrates how to configure an HTTP job with its URL, method, data, cron expression, and sharding parameters using the ScheduleJobBootstrap. ```java public class HttpJobMain { public static void main(String[] args) { new ScheduleJobBootstrap(regCenter, "HTTP", JobConfiguration.newBuilder("javaHttpJob", 1) .setProperty(HttpJobProperties.URI_KEY, "http://xxx.com/execute") .setProperty(HttpJobProperties.METHOD_KEY, "POST") .setProperty(HttpJobProperties.DATA_KEY, "source=ejob") .cron("0/5 * * * * ?").shardingItemParameters("0=Beijing").build()).schedule(); } } ``` -------------------------------- ### Gradle Configuration for GraalVM Native Image Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/configuration/graalvm-native-image.en.md Set up your Gradle project for GraalVM Native Image builds. This includes applying the `org.graalvm.buildtools.native` plugin and adding necessary dependencies, including the reachability metadata repository. ```groovy plugins { id 'org.graalvm.buildtools.native' version '0.10.3' } dependencies { implementation 'org.apache.shardingsphere.elasticjob:elasticjob-bootstrap:${elasticjob.version}' implementation(group: 'org.graalvm.buildtools', name: 'graalvm-reachability-metadata', version: '0.10.3', classifier: 'repository', ext: 'zip') } graalvmNative { metadataRepository { enabled.set(false) } } ``` -------------------------------- ### Configure Job Dump with Spring Namespace Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/configuration/spring-namespace.en.md Enable job dump functionality with the `` tag. This requires 'id', 'registry-center-ref', and 'dump-port'. The 'dump-port' is used for communication, for example: `echo "dump@jobName" | nc 127.0.0.1 9888`. ```xml ``` -------------------------------- ### Add ElasticJob Spring Boot Starter Dependency Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/content/user-manual/configuration/spring-boot-starter.en.md Include this dependency in your pom.xml to use the ElasticJob Spring Boot Starter. ```xml org.apache.shardingsphere.elasticjob elasticjob-spring-boot-starter ${latest.release.version} ``` -------------------------------- ### Initialize and Use Lifecycle APIs in Java Source: https://context7.com/apache/shardingsphere-elasticjob/llms.txt Factory methods create API instances for job operations, statistics, configuration, and sharding. Use these APIs to query job counts, trigger jobs, enable/disable jobs or servers, and update configurations at runtime. ```java import org.apache.shardingsphere.elasticjob.lifecycle.api.*; // Factory creates API instances from ZK connection details JobOperateAPI operateAPI = JobAPIFactory.createJobOperateAPI( "zk1:2181,zk2:2181", "my-app-jobs", null); JobStatisticsAPI statsAPI = JobAPIFactory.createJobStatisticsAPI( "zk1:2181,zk2:2181", "my-app-jobs", null); JobConfigurationAPI configAPI = JobAPIFactory.createJobConfigurationAPI( "zk1:2181,zk2:2181", "my-app-jobs", null); ShardingOperateAPI shardingAPI = JobAPIFactory.createShardingOperateAPI( "zk1:2181,zk2:2181", "my-app-jobs", null); // --- Query statistics --- int total = statsAPI.getJobsTotalCount(); statsAPI.getAllJobsBriefInfo().forEach(info -> System.out.printf("Job: %-30s Status: %s%n", info.getJobName(), info.getStatus())); // --- Operate a specific job --- operateAPI.trigger("orderProcessingJob"); // fire once immediately operateAPI.disable("orderProcessingJob", null); // disable on all servers operateAPI.enable("orderProcessingJob", null); // re-enable operateAPI.shutdown("orderProcessingJob", null); // shutdown on all servers // --- Disable a specific server's participation --- operateAPI.disable("orderProcessingJob", "10.0.0.5"); // --- Disable a specific shard --- shardingAPI.disable("orderProcessingJob", 1); // pause shard 1 shardingAPI.enable("orderProcessingJob", 1); // resume shard 1 // --- Update job configuration at runtime --- var pojo = configAPI.getJobConfiguration("orderProcessingJob"); pojo.setCron("0/60 * * * * ?"); // slow down to every 60 s configAPI.updateJobConfiguration(pojo); ``` -------------------------------- ### Set Page Order with Weight Source: https://github.com/apache/shardingsphere-elasticjob/blob/master/docs/themes/hugo-theme-learn/exampleSite/content/cont/pages/_index.en.md Use the `weight` parameter in the front matter to define the order of pages in the menu. Higher numbers appear later in the order. ```toml +++ title = "My page" weight = 5 +++ ```