{"id":23959562,"url":"https://github.com/otobrglez/zio-backtask","last_synced_at":"2025-04-13T08:12:59.669Z","repository":{"id":138274406,"uuid":"596508274","full_name":"otobrglez/zio-backtask","owner":"otobrglez","description":"ZIO Backtask is background job framework for your next Scala 3 application.","archived":false,"fork":false,"pushed_at":"2023-04-17T15:31:12.000Z","size":63,"stargazers_count":26,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T08:12:51.406Z","etag":null,"topics":["redis","scala","zio"],"latest_commit_sha":null,"homepage":"","language":"Scala","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/otobrglez.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-02T10:37:47.000Z","updated_at":"2023-07-20T06:43:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"8d6148f3-2d94-46ff-8dd0-b705e4893103","html_url":"https://github.com/otobrglez/zio-backtask","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otobrglez%2Fzio-backtask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otobrglez%2Fzio-backtask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otobrglez%2Fzio-backtask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otobrglez%2Fzio-backtask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/otobrglez","download_url":"https://codeload.github.com/otobrglez/zio-backtask/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248681495,"owners_count":21144700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["redis","scala","zio"],"created_at":"2025-01-06T18:49:25.487Z","updated_at":"2025-04-13T08:12:59.657Z","avatar_url":"https://github.com/otobrglez.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ZIO Backtask\n\n![scala-version][scala-version-badge]\n\n## Overview\n\nZIO Backtask is background job framework that you can simply implement in your ZIO application. \nIt is backed by [Redis], an in-memory key-value store known for its flexibility and performance.\n\nZIO Backtask was heavily inspired by [sidekiq] - very popular Ruby framework for background jobs.\n\nThe project uses ZIO 2, Scala 3 and its capabilities and relies upon [Lettuce] Redis Client.\n\n\u003e ⚠️ This project is in proof-of-concept phase. It lacks a lot of basic and expected \n\u003e functionalities and its APIs are subject to change. Please feel free to reach-out\n\u003e if you would like to support or help with this project or you see potential in it.\n\n## Getting started\n\n```scala\n// A few example user-defined tasks.\nobject tasks:\n\n  // Task that adds two numbers together and outputs the result.\n  case class add(a: Int, b: Int, yes: Option[String] = None) extends Backtask[Any]:\n    override def queueName = \"math\"\n    def run = printLine(s\"Add: $a + $b = ${a + b}\")\n\n  // Task that outputs whatever string it got.\n  case class saySomething(raw: String) extends Backtask[Any]:\n    def run = printLine(s\"Said ${raw}\")\n\n  // A task that counts and generates new tasks with delay until a condition is reached\n  case class countFromTo(from: Int, to: Int, delay: Int) extends Backtask[Redis]:\n    override def queueName = \"counting\"\n    def run =\n      for\n        _ \u003c- printLine(s\"n: $from, queueName: $queueName\")\n        _ \u003c-\n          if (from + 1 \u003c= to)\n            countFromTo(from + 1, to, delay).performIn(delay.seconds)\n          else ZIO.unit\n      yield ()\n\nobject BacktaskApp extends ZIOAppDefault:\n  import tasks.*\n\n  def clientProgram: ZIO[Redis, Throwable, Unit] =\n    for\n      _ \u003c- logInfo(\"Booting.\")\n      _ \u003c- add(40, 2).performAsync\n      _ \u003c- add(20, 22).performAsync(\"math\")\n      _ \u003c- saySomething(\"Hello world!\").performAsync\n      _ \u003c- saySomething(\"Doing this in one hour\").performAt(LocalDateTime.now.plusHours(1), \"hello\")\n      _ \u003c- saySomething(\"Hello after 10 seconds\").performIn(10.seconds, \"hello\")\n      _ \u003c- saySomething(\"Do this in 1 minute!\").performIn(1.minute, \"delayed\")\n      _ \u003c- saySomething(\"Experiment is done!\").performIn(2.minutes, \"hello\")\n      _ \u003c- countFromTo(0, 20, 3).performAsync\n      _ \u003c- saySomething(\"Mail was sent! ✉️\").performIn(5.seconds, \"mail\")\n    yield ()\n\n  def program =\n    for\n      fib1 \u003c- clientProgram.fork\n      // TODO: The BacktaskScheduler will be embedded in the Worker in the near future. \n      fib2 \u003c- BacktaskScheduler.run.fork\n      _    \u003c- fib1.join\n      _    \u003c- fib2.join\n    yield ()\n\n  // Core program is started with two additional workers that actually consume tasks and execute them.\n  def run =\n    program.provideLayer(RedisClient.live) \u003c\u0026\u003e\n      Worker.run.delay(2.seconds).provideLayer(RedisClient.live) \u003c\u0026\u003e\n      Worker.run.delay(3.seconds).provideLayer(RedisClient.live)\n```\n\nPlease check the [examples](modules/examples/src/main/scala/zio/backtask/examples) for more examples and details.\n\n## Supported methods\n\n### `performAsync`\n\nMoves the given `Backtask` to `default` queue for instant consumption.\n\nThe `queueName` is set to default, however it can be overriden.\n\n### `performIn`\n\nMoves the `Backtask` to a given queue. The task will be executed after the given\n`FiniteDelay`. Tasks, that are delayed or scheduled can not be scheduled on `default`\nqueue.\n\n### `performAt`\n\nFunction accepts `LocalDateTime` defining the exact time when the `Backtask` should \nbe executed. The system works on UTC; whatever timezone will be given gets converted to it.\n\nSame as with `performIn`, this function can't schedule on `default` queue, \nmeaning that some other queue needs to be given.\n\n\n## Resources\n\n- [Redis / ZRANGEBYSCORE](https://redis.io/commands/zrangebyscore/)\n- [Redis / BRPOPLPUSH](https://redis.io/commands/brpoplpush/)\n- [How Sidekiq really works](https://www.paweldabrowski.com/articles/how-sidekiq-really-works)\n- [Jesque](https://github.com/gresrun/jesque)\n- [sidekiq](https://github.com/mperham/sidekiq)\n\n## Authors\n\n- [Oto Brglez](https://github.com/otobrglez) / [@otobrglez](https://twitter.com/otobrglez)\n\n[Redis]: https://redis.io\n[Lettuce]: https://lettuce.io\n[sidekiq]: https://github.com/mperham/sidekiq\n[scala-version-badge]: https://img.shields.io/badge/scala-3.2.2-blue?logo=scala\u0026color=red\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotobrglez%2Fzio-backtask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fotobrglez%2Fzio-backtask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotobrglez%2Fzio-backtask/lists"}