<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/background-jobs-with-oban-part-1-stop-blocking-your-liveview-2rv8xz05v" -->

---
title: Background jobs with Oban, part 1: stop blocking your...
description: A screencast and written walkthrough shows moving a slow HTTP fetch out of a Phoenix LiveView event handler and into a background job using Oban, a...
canonical: https://daily.dev/posts/background-jobs-with-oban-part-1-stop-blocking-your-liveview-2rv8xz05v
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Background jobs with Oban, part 1: stop blocking your LiveView | daily.dev
og:description: A screencast and written walkthrough shows moving a slow HTTP fetch out of a Phoenix LiveView event handler and into a background job using Oban, a...
og:url: https://daily.dev/posts/background-jobs-with-oban-part-1-stop-blocking-your-liveview-2rv8xz05v
og:image: https://api.daily.dev/og/posts/2rV8xz05V.png
og:image:alt: Background jobs with Oban, part 1: stop blocking your LiveView
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Background jobs with Oban, part 1: stop blocking your LiveView

**[ElixirStatus](https://daily.dev/sources/elixirstatus)** · 8 min read · 0 upvotes · 0 comments

## Summary

A screencast and written walkthrough shows moving a slow HTTP fetch out of a Phoenix LiveView event handler and into a background job using Oban, a database-backed job processing library for Elixir. It covers installing Oban manually, creating its jobs table migration, configuring engines, queues, pruning, and job rescue, writing a worker with a perform/1 callback, and enqueuing the job from the LiveView instead of blocking on the fetch. The demo app, Unfurl, fetches URL previews; the walkthrough shows the page freezing on a slow site before the change and staying responsive after. A follow-up part two will add Phoenix PubSub for live updates and wire up the Oban Web dashboard.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://potions.io/blog/background-jobs-with-oban-part-1>

## Questions this post answers

### How do I move a slow HTTP fetch out of a Phoenix LiveView event handler so it doesn't block the page?

Enqueue the work as a background job with Oban instead of calling the fetch function directly inside the handle_event callback. Insert the job via a schedule function that builds a changeset with YourWorker.new and pipes it into Oban.insert, then have the LiveView show a flash message while the job runs asynchronously in a dedicated queue.

_See the full worked example for shipping responsive LiveViews with background jobs on daily.dev._

### How do I configure Oban queues, pruning, and job rescue for production in Elixir?

Configure Oban's engine (Oban.Engines.Basic for PostgreSQL, Oban.Engines.Lite for SQLite), point it at your repo, and define named queues with a concurrency limit, such as a previews queue running five jobs simultaneously. Add a pruner with max_age set to seven days to delete finished jobs, and set rescue_after to one hour so jobs stuck executing after a crash or deploy get rescued.

_Developers hardening job queues for production track configuration details like these on daily.dev._

### How do I cancel an Oban job instead of retrying it when the underlying record no longer exists?

Return the tuple {:cancel, :reason} from the perform/1 callback in your Oban worker. This tells Oban to stop the job permanently without further retries, which is useful when a lookup, such as fetching a link by ID, returns an error because the record was deleted before the job ran.

_daily.dev helps Elixir developers keep track of Oban worker patterns like this one._

## Similar posts on daily.dev

- [Background jobs with Oban, Part 2: Live Updates and Smarter Retries](https://daily.dev/posts/background-jobs-with-oban-part-2-live-updates-and-smarter-retries-j2obkf5hu) · Elixir Forum · 1 upvotes · 0 comments
- [Bridging Elixir and Python with Oban](https://daily.dev/posts/bridging-elixir-and-python-with-oban-ksknqtocl) · ElixirStatus · 0 upvotes · 0 comments
- [Oban.py - deep dive](https://daily.dev/posts/oban-py---deep-dive-to5vviuxh) · Hacker News · 0 upvotes · 0 comments
- [Code BEAM Europe - Learning Resources / Talks - Erlang Forums](https://daily.dev/posts/code-beam-europe---learning-resources-talks---erlang-forums-7sgqizpws) · Erlang Forums · 0 upvotes · 0 comments
- [Monitoring the Health of Oban Applications](https://daily.dev/posts/monitoring-the-health-of-oban-applications-5uicpeugt) · ElixirStatus · 0 upvotes · 0 comments

---

Tags: [#postgresql](https://daily.dev/tags/postgresql), [#elixir](https://daily.dev/tags/elixir), [#liveview](https://daily.dev/tags/liveview)

[View this post on daily.dev](https://daily.dev/posts/background-jobs-with-oban-part-1-stop-blocking-your-liveview-2rv8xz05v)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Background jobs with Oban, part 1: stop blocking your LiveView","url":"https://daily.dev/posts/background-jobs-with-oban-part-1-stop-blocking-your-liveview-2rv8xz05v","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/background-jobs-with-oban-part-1-stop-blocking-your-liveview-2rv8xz05v"},"datePublished":"2026-09-22T17:14:28.535Z","dateModified":"2026-09-22T17:14:49.241Z","description":"A screencast and written walkthrough shows moving a slow HTTP fetch out of a Phoenix LiveView event handler and into a background job using Oban, a...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/56c7981e2a3897d87229a7e0a8d6cd99?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/56c7981e2a3897d87229a7e0a8d6cd99?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"ElixirStatus","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"ElixirStatus","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/22e4640538124187827caf8cc8e39190","url":"https://daily.dev/sources/elixirstatus"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/background-jobs-with-oban-part-1-stop-blocking-your-liveview-2rv8xz05v","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"postgresql,elixir,liveview","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"ElixirStatus","item":"https://daily.dev/sources/elixirstatus"},{"@type":"ListItem","position":3,"name":"Background jobs with Oban, part 1: stop blocking your LiveView"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/background-jobs-with-oban-part-1-stop-blocking-your-liveview-2rv8xz05v#faq","mainEntity":[{"@type":"Question","name":"How do I move a slow HTTP fetch out of a Phoenix LiveView event handler so it doesn't block the page?","acceptedAnswer":{"@type":"Answer","text":"Enqueue the work as a background job with Oban instead of calling the fetch function directly inside the handle_event callback. Insert the job via a schedule function that builds a changeset with YourWorker.new and pipes it into Oban.insert, then have the LiveView show a flash message while the job runs asynchronously in a dedicated queue. See the full worked example for shipping responsive LiveViews with background jobs on daily.dev."}},{"@type":"Question","name":"How do I configure Oban queues, pruning, and job rescue for production in Elixir?","acceptedAnswer":{"@type":"Answer","text":"Configure Oban's engine (Oban.Engines.Basic for PostgreSQL, Oban.Engines.Lite for SQLite), point it at your repo, and define named queues with a concurrency limit, such as a previews queue running five jobs simultaneously. Add a pruner with max_age set to seven days to delete finished jobs, and set rescue_after to one hour so jobs stuck executing after a crash or deploy get rescued. Developers hardening job queues for production track configuration details like these on daily.dev."}},{"@type":"Question","name":"How do I cancel an Oban job instead of retrying it when the underlying record no longer exists?","acceptedAnswer":{"@type":"Answer","text":"Return the tuple {:cancel, :reason} from the perform/1 callback in your Oban worker. This tells Oban to stop the job permanently without further retries, which is useful when a lookup, such as fetching a link by ID, returns an error because the record was deleted before the job ran. daily.dev helps Elixir developers keep track of Oban worker patterns like this one."}}]}
```

