{"id":44437159,"url":"https://github.com/levelfourab/jobs","last_synced_at":"2026-02-12T14:01:17.764Z","repository":{"id":56031767,"uuid":"54769429","full_name":"LevelFourAB/jobs","owner":"LevelFourAB","description":"Job runner for Java with scheduling, failure management via retries and different backends","archived":false,"fork":false,"pushed_at":"2020-11-30T05:47:01.000Z","size":157,"stargazers_count":1,"open_issues_count":11,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-11T09:46:35.864Z","etag":null,"topics":["job-queue","job-runner","job-scheduler","jobs"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LevelFourAB.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-26T08:09:57.000Z","updated_at":"2020-09-22T14:47:34.000Z","dependencies_parsed_at":"2022-08-15T11:50:26.120Z","dependency_job_id":null,"html_url":"https://github.com/LevelFourAB/jobs","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/LevelFourAB/jobs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LevelFourAB%2Fjobs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LevelFourAB%2Fjobs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LevelFourAB%2Fjobs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LevelFourAB%2Fjobs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LevelFourAB","download_url":"https://codeload.github.com/LevelFourAB/jobs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LevelFourAB%2Fjobs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29367814,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T08:51:36.827Z","status":"ssl_error","status_checked_at":"2026-02-12T08:51:26.849Z","response_time":55,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["job-queue","job-runner","job-scheduler","jobs"],"created_at":"2026-02-12T14:01:17.042Z","updated_at":"2026-02-12T14:01:17.757Z","avatar_url":"https://github.com/LevelFourAB.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Jobs\n\nJob runner for Java with support for delays, retries and different backends.\n\n```java\nLocalJobs jobs = LocalJobs.builder()\n  .setBackend(new InMemoryJobsBackend())\n  .addRunner(new SendReportRunner())\n  .build();\n\n// Submit a job that will run now\njobs.add(new SendReport(\"example@example.org\"))\n  .submit();\n\n// Submit a job that will run later\njobs.add(new SendReport(\"example@example.org\"))\n  .withSchedule(Schedule.after(Duration.ofMinutes(20)))\n  .submit();\n```\n\n## Scheduling via cron and repeating jobs\n\nOne off jobs can be scheduled via a cron expression:\n\n```java\n// Submit a job that will run at 10 am\njobs.add(new SendReport(\"example@example.org\"))\n  .withSchedule(Schedule.at(\"0 0 10 * * *\"))\n  .submit();\n```\n\nIt's also possible to schedule jobs that will repeat:\n\n```java\n// Submit a job that will run at 10 am and repeat forever\njobs.add(new SendReport(\"example@example.org\"))\n  .withId(\"report-sender\")\n  .withSchedule(\n    Schedule.at(\"0 0 10 * * *\").repeat()\n  )\n  .submit();\n```\n\nScheduling another job with the same id will replace the existing job. It's \npossible to cancel a previously submitted repeating job by fetching it and\ncalling `cancel`.\n\n```java\nOptional\u003cJob\u003c?, ?\u003e\u003e job = jobs.getViaId(\"report-sender\");\n\nif(job.isPresent()) {\n  // Cancel the job if it is still scheduled\n  job.get().cancel();\n}\n```\n\n## Job data and runners\n\nIn this library jobs are represented by data classes that have a job runner\nassociated with them.\n\nA data object should be a simple class and in most cases should be serializable:\n\n```java\nimport se.l4.commons.serialization.Expose;\nimport se.l4.commons.serialization.ReflectionSerializer;\nimport se.l4.commons.serialization.Use;\n\n@Use(ReflectionSerializer.class)\n@Named(namespace=\"reports\", name=\"send-report-job\")\npublic class SendReport extends JobData\u003cVoid\u003e {\n  @Expose\n  private final String email;\n\n  public SendReport(@Expose(\"email\") String email) {\n    this.email = email;\n  }\n\n  public String getEmail() {\n    return email;\n  }\n}\n```\n\nSuch a class then has a runner associated with it:\n\n```java\npublic class SendReportRunner implements JobRunner\u003cSendReport, Void\u003e {\n  public void run(JobEncounter\u003cSendReport, Void\u003e encounter) {\n    // Code that performs the job goes here    \n  }\n}\n```\n\nRunners are registered when `LocalJobs` are built either manually by calling\n`addRunner` or using a `TypeFinder` for automatic registration.\n\n## Returning results from jobs\n\nTo return a result from a job set the type a job will return in it's data\nclass:\n\n```java\npublic class JobDataWithResult implements JobData\u003cString\u003e {\n  ...\n}\n```\n\nA runner can then use `complete` in `JobEncounter` to send back a result:\n\n```java\npublic class JobDataWithResultRunner implements JobRunner\u003cJobDataWithResult, String\u003e {\n  public run(JobEncounter\u003cJobDataWithResult, String\u003e encounter) {\n    String result = ...;\n      \n    // Indicate that the job has completed\n    encounter.complete(result);\n  }\n}\n```\n\nWhen submitting this job you can listen for the result:\n\n```java\n// Submit the job\nJob\u003cJobDataWithResult, String\u003e job = jobs.add(new JobDataWithResult(...))\n  .submit();\n\n/* \n * Job.result can be used to retrieve a future that will resolve when the\n * job completes or fails completely.\n */\nCompletableFuture\u003cString\u003e future = job.result();\n\n// Use any method on the future, such as join to wait for the result\nString result = future.join();\n```\n\n## Managing failures and retries\n\nIn many cases it's important to have control over how a job is retried if it\nfails. The default behavior is to retry a job up to 5 times, delaying the\nrun with 1 second for the first retry and then doubling the time.\n\nControl over this behavior is done via the methods `fail` and `failNoRetry`:\n\n```java\n/* \n * Delay for 1 minute after first attempt and then double at each failed\n * attempt.\n */\nprivate final Delay customDelay = Delay.exponential(Duration.ofMinutes(1));\n\npublic run(JobEncounter\u003cData, Void\u003e encounter) {\n  try {\n    // Perform the job here\n  \n    // Indicate that the job has completed\n    encounter.complete();\n  } catch(Throwable t) {\n    if(encounter.getAttempt() \u003e= 10) {\n      /*\n       * This is the tenth attempt - lets skip retrying it at this point.\n       * The next delay would be 512 minutes (~8.5 hours) and this attempt was\n       * delayed by 256 minutes (~4.2 hours) from the previous attempt.\n       */\n      encounter.failNoRetry(t);\n    } else {\n      // Fail and retry this job later, delaying the run by customDelay\n      encounter.fail(t, customDelay);\n    }\n  }\n}\n```\n\n`Delay` supports combining as well, such as limiting clamping to a maximum \nvalue, applying a jitter or limiting the number of attempts:\n\n```java\n/*\n * Clamp to a maximum delay - when otherDelay starts to return values longer\n * than a day this will return one day forever.\n */\nDelay clamped = Delay.clampMax(otherDelay, Duration.ofDays(1));\n\n/*\n * Apply a random jitter to spread out retries a bit.\n */\nDelay jittered = Delay.jitter(otherDelay);\nDelay jittered = Delay.jitter(otherDelay, Duration.ofSeconds(1));\n\n/*\n * Limit the number of attempts of a job (alternative to getAttempt() \u003e= N).\n */\nDelay limited = Delay.limitAttempts(otherDelay, 10);\n```\n\nIt's also possible to take full control and use a specific sequence of delays,\nthis delay will use the specified durations between retries and then give up\nafter the sixth attempt of the job:\n\n```java\nDelay sequence = Delay.sequence(\n\tDuration.ofMinutes(1), // first retry 1 minute after first failure\n\tDuration.ofMinutes(10), // second retry 10 minutes after second failure\n\tDuration.ofMinutes(30), // third retry 30 minutes after third failure\n\tDuration.ofMinutes(60), // fourth retry 60 minutes after fourth failure,\n\tDuration.ofMinutes(120), // fifth retry 30 minutes after fifth failure\n);\n```\n\n## Automatic discovery of job runners\n\nJob runners can be discovered automatically using a `TypeFinder`:\n\n```java\n// The type finder used to locate job runners\nTypeFinder typeFinder = TypeFinder.builder()\n  .addPackage(\"com.example.package\")\n  .setInstanceFactory(instanceFactory)\n  .build();\n\n// Pass the type finder to the builder to automatically find runners\nLocalJobs.builder()\n  .withBackend(backend)\n  .withTypeFinder(typeFinder)\n  .build();\n```\n\n## Backends\n\n### Memory based\n\n`InMemoryJobsBackend` is a backend included within the module `jobs-engine`.\nIt provides a queue that is kept entirely in memory without any persistance,\nmeaning that any jobs submitted will be lost if the backend is stopped or the\nprocess is restarted.\n\nThere is also a risk that this type of backend will run of out memory if too\nmany jobs are submitted.\n\n### Persisted using Silo\n\n`SiloJobsBackend` is available in the module `jobs-backend-silo` and will\npersist jobs using a [Silo instance](https://github.com/levelfourab/silo).\nThis type of backend is useful for single-process systems that want to store\njobs between restarts.\n\nFor this backend an entity needs to be defined on the `SiloBuilder` when \ncreating the `LocalSilo` instance:\n\n```java\nSiloBuilder builder = LocalSilo.open(pathToStorage);\n\nSiloJobsBackend.defineJobEntity(builder, \"jobs:queue\");\n\nSilo silo = builder.build();\n```\n\nThis entity should then be passed to the backend:\n\n```java\nnew SiloJobsBackend(silo.structured(\"jobs:queue\"));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevelfourab%2Fjobs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flevelfourab%2Fjobs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevelfourab%2Fjobs/lists"}