{"result":{"depiction_url":null,"edges":{"relation":{"objects":[{"created":"2026-10-07T11:13:18Z","object_id":{"id":1640,"is_a":["text","documentation","developerguide"],"name":"doc_developerguide_logging","title":{"_type":"trans","tr":{"en":"Write logs that explain an operation"}},"uri":"https:\/\/zotonic.com\/id\/1640"},"seq":1},{"created":"2026-10-07T11:13:18Z","object_id":{"id":2949,"is_a":["text","documentation","developerguide"],"name":"developer_site_context","title":{"_type":"trans","tr":{"en":"Work with a site context"}},"uri":"https:\/\/zotonic.com\/id\/2949"},"seq":2},{"created":"2026-10-07T11:13:18Z","object_id":{"id":2983,"is_a":["text","documentation","developerguide"],"name":"developer_testing_strategy","title":{"_type":"trans","tr":{"en":"Choose checks for a change"}},"uri":"https:\/\/zotonic.com\/id\/2983"},"seq":3}],"predicate":{"id":303,"is_a":["meta","predicate"],"name":"relation","title":{"_type":"trans","tr":{"nl":"Relatie","en":"Relation"}},"uri":"http:\/\/purl.org\/dc\/terms\/relation"}},"subject":{"objects":[{"created":"2026-10-07T11:13:18Z","object_id":{"id":2554,"is_a":["categorization","keyword","keyword_information_type"],"name":"zotonic_topic_how_to_guide","title":"How-to guide","uri":"https:\/\/zotonic.com\/id\/2554"},"seq":1},{"created":"2026-10-07T11:13:18Z","object_id":{"id":2564,"is_a":["categorization","keyword","keyword_audience"],"name":"zotonic_topic_backend_developer","title":"Backend developer","uri":"https:\/\/zotonic.com\/id\/2564"},"seq":2},{"created":"2026-10-07T11:13:18Z","object_id":{"id":2606,"is_a":["categorization","keyword","keyword_domain"],"name":"zotonic_topic_scheduled_and_background_work","title":"Scheduled and background work","uri":"https:\/\/zotonic.com\/id\/2606"},"seq":3},{"created":"2026-10-07T11:13:18Z","object_id":{"id":2633,"is_a":["categorization","keyword","keyword_architecture"],"name":"zotonic_topic_background_task","title":"Background task","uri":"https:\/\/zotonic.com\/id\/2633"},"seq":4}],"predicate":{"id":308,"is_a":["meta","predicate"],"name":"subject","title":{"_type":"trans","tr":{"en":"Keyword"}},"uri":"http:\/\/purl.org\/dc\/elements\/1.1\/subject"}}},"id":2963,"is_a":["text","documentation","developerguide"],"links":[{"rel":"self","target":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/2963"},{"rel":"hub","target":"https:\/\/zotonic.com\/.zotonic\/websub"}],"medium":null,"medium_url":null,"name":"developer_background_work","page_url":{"en":"https:\/\/zotonic.com\/docs\/2963\/run-work-outside-a-request","x-default":"https:\/\/zotonic.com\/docs\/2963\/run-work-outside-a-request"},"preview_url":null,"resource":{"body":{"_type":"trans","tr":{"en":"<p>Define what happens if the process, site, or node restarts. An in-memory job is not durable simply because it runs outside the request. Make external effects retryable where possible and record enough state to distinguish a retry from a new job.<\/p>\n<p>Pass the correct site context and keep authorization decisions explicit. Report failures with structured logs and a useful job identifier.<\/p>\n<p>For a database-backed, deferred task, the pivot task queue accepts a module, exported function, stable job key, and argument list:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">z_pivot_rsc:insert_task_after(10, garden_jobs, refresh, JobKey, [ResourceId], C).\n<\/code><\/pre>\n<p>Implement <code>garden_jobs:refresh(ResourceId, Context)<\/code> in <code>src\/support\/garden_jobs.erl<\/code> before queuing it. The queue appends the site context. A completed callback can return <code>ok<\/code>; <code>{delay, Seconds}<\/code> requests another attempt and <code>{delay, Seconds, NewArgs}<\/code> changes the retry arguments. The unique key identifies pending work for that module\/function; it is not a guarantee that an external side effect happens only once.<\/p>\n<p>Authorize the request before queuing, validate the saved arguments again in the worker, and handle a resource deleted before execution. Verify completion in the worker&#39;s output or saved result, not just the queue-insertion response. Check the current <code>z_pivot_rsc<\/code> and <code>z_pivot_rsc_task_job<\/code> sources for failure\/retry handling before relying on it for deliveries or payments.<\/p>"}},"category_id":{"id":317,"is_a":["meta","category"],"name":"developerguide","title":"Developer guide","uri":"https:\/\/zotonic.com\/id\/developerguide"},"content_group_id":{"id":339,"is_a":["meta","content_group"],"name":"default_content_group","title":{"_type":"trans","tr":{"en":"Default Content Group"}},"uri":"https:\/\/zotonic.com\/id\/default_content_group"},"created":"2026-10-07T11:12:56Z","creator_id":{"id":1,"is_a":["person"],"name":"administrator","title":"Site Administrator","uri":"https:\/\/zotonic.com\/id\/1"},"doc_editorial_bundle":true,"doc_editorial_edges":{"relation":[1640,2949,2983],"subject":[2554,2564,2606,2633]},"is_authoritative":true,"is_dependent":false,"is_featured":false,"is_protected":false,"is_published":true,"is_unfindable":false,"language":["en"],"modified":"2026-10-07T20:45:39Z","modifier_id":{"id":1,"is_a":["person"],"name":"administrator","title":"Site Administrator","uri":"https:\/\/zotonic.com\/id\/1"},"name":"developer_background_work","pivot_geocode":null,"pivot_location_lat":null,"pivot_location_lng":null,"privacy":0,"publication_end":"9999-06-01T00:00:00Z","publication_start":"2026-10-07T11:12:56Z","slug":"run-work-outside-a-request","summary":{"_type":"trans","tr":{"en":"Use an existing Zotonic task mechanism when it fits the job. Use a supervised worker when the work needs a persistent process with its own lifecycle."}},"title":{"_type":"trans","tr":{"en":"Run work outside a request"}},"title_slug":{"_type":"trans","tr":{"en":"run-work-outside-a-request"}},"tz":"UTC","uri":null,"version":19,"visible_for":0},"uri":"https:\/\/zotonic.com\/id\/2963","uri_template":"https:\/\/zotonic.com\/id\/:id","websub":{"hub":"https:\/\/zotonic.com\/.zotonic\/websub","topic":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/2963"}},"status":"ok"}