{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9bc5dd71",
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4f4daf0f",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pathlib import Path\n",
    "\n",
    "import rich\n",
    "from sqlmodel.ext.asyncio.session import AsyncSession\n",
    "\n",
    "from transcription.config import Settings\n",
    "from transcription.config import configure_logging\n",
    "from transcription.config import get_settings\n",
    "from transcription.db.operations import create_all\n",
    "from transcription.db.runtime import get_engine\n",
    "from transcription.db.runtime import get_session\n",
    "from transcription.models import Document\n",
    "from transcription.models import Job\n",
    "from transcription.services import ServiceBundle\n",
    "from transcription.services import workflows as wf\n",
    "from transcription.services.jobs import JobStatus\n",
    "from transcription.services.store import create_upload_job\n",
    "from transcription.services.transcription import transcribe_document_image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c81d7c26",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2026-06-28 12:53:12 DEBUG    | Logging configured\n",
      "2026-06-28 12:53:12 DEBUG    | Initialized async database runtime for database_url=sqlite+aiosqlite:///./transcription.db\n",
      "2026-06-28 12:53:12 DEBUG    | Database schema bootstrap complete for database_url=sqlite+aiosqlite:///./transcription.db\n"
     ]
    }
   ],
   "source": [
    "configure_logging()\n",
    "settings = get_settings(worker_max_retries=2)\n",
    "engine = get_engine(settings=settings)\n",
    "await create_all(engine=engine)\n",
    "s = ServiceBundle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7aca0ba3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'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'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "settings.openrouter_api_key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ee1d5b0c",
   "metadata": {},
   "outputs": [],
   "source": [
    "test_file = Path(\"uploads/7c6ee648-4171-4e70-b901-ba94ee227d6a_Time Rolls On - page 013.jpg\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "90e14eca",
   "metadata": {},
   "outputs": [],
   "source": [
    "async def upload_file(file_path: str | Path, session: AsyncSession):\n",
    "    path = Path(file_path)\n",
    "    filename = path.name.rpartition(\"_\")[2]\n",
    "    return await create_upload_job(\n",
    "        filename=filename,\n",
    "        file_bytes=path.read_bytes(),\n",
    "        session=session,\n",
    "    )\n",
    "\n",
    "\n",
    "async with get_session() as session:\n",
    "    result = await upload_file(test_file, session)\n",
    "\n",
    "rich.print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "59413342",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">[</span>\n",
       "    <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Job</span><span style=\"font-weight: bold\">(</span>\n",
       "        <span style=\"color: #808000; text-decoration-color: #808000\">document_id</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">UUID</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008000; text-decoration-color: #008000\">'5c769d26-30bf-4950-ba3d-5dcabce690e7'</span><span style=\"font-weight: bold\">)</span>,\n",
       "        <span style=\"color: #808000; text-decoration-color: #808000\">status</span>=<span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">JobStatus.QUEUED:</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'queued'</span><span style=\"font-weight: bold\">&gt;</span>,\n",
       "        <span style=\"color: #808000; text-decoration-color: #808000\">created_at</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">datetime</span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">.datetime</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2026</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">6</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">28</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">17</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">9</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">26</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">395914</span><span style=\"font-weight: bold\">)</span>,\n",
       "        <span style=\"color: #808000; text-decoration-color: #808000\">id</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">UUID</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008000; text-decoration-color: #008000\">'7a0d5e44-64e9-4916-83e0-bde3a8fb8c58'</span><span style=\"font-weight: bold\">)</span>,\n",
       "        <span style=\"color: #808000; text-decoration-color: #808000\">retry_count</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span>,\n",
       "        <span style=\"color: #808000; text-decoration-color: #808000\">updated_at</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">datetime</span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">.datetime</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2026</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">6</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">28</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">17</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">47</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">26</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">755438</span><span style=\"font-weight: bold\">)</span>\n",
       "    <span style=\"font-weight: bold\">)</span>\n",
       "<span style=\"font-weight: bold\">]</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1m[\u001b[0m\n",
       "    \u001b[1;35mJob\u001b[0m\u001b[1m(\u001b[0m\n",
       "        \u001b[33mdocument_id\u001b[0m=\u001b[1;35mUUID\u001b[0m\u001b[1m(\u001b[0m\u001b[32m'5c769d26-30bf-4950-ba3d-5dcabce690e7'\u001b[0m\u001b[1m)\u001b[0m,\n",
       "        \u001b[33mstatus\u001b[0m=\u001b[1m<\u001b[0m\u001b[1;95mJobStatus.QUEUED:\u001b[0m\u001b[39m \u001b[0m\u001b[32m'queued'\u001b[0m\u001b[1m>\u001b[0m,\n",
       "        \u001b[33mcreated_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2026\u001b[0m, \u001b[1;36m6\u001b[0m, \u001b[1;36m28\u001b[0m, \u001b[1;36m17\u001b[0m, \u001b[1;36m9\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m395914\u001b[0m\u001b[1m)\u001b[0m,\n",
       "        \u001b[33mid\u001b[0m=\u001b[1;35mUUID\u001b[0m\u001b[1m(\u001b[0m\u001b[32m'7a0d5e44-64e9-4916-83e0-bde3a8fb8c58'\u001b[0m\u001b[1m)\u001b[0m,\n",
       "        \u001b[33mretry_count\u001b[0m=\u001b[1;36m2\u001b[0m,\n",
       "        \u001b[33mupdated_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2026\u001b[0m, \u001b[1;36m6\u001b[0m, \u001b[1;36m28\u001b[0m, \u001b[1;36m17\u001b[0m, \u001b[1;36m47\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m755438\u001b[0m\u001b[1m)\u001b[0m\n",
       "    \u001b[1m)\u001b[0m\n",
       "\u001b[1m]\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Document</span><span style=\"font-weight: bold\">(</span>\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">uploaded_at</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">datetime</span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">.datetime</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2026</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">6</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">28</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">17</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">9</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">26</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">392233</span><span style=\"font-weight: bold\">)</span>,\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">file_path</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'uploads/86a8f2c6-bfb7-4980-9941-56768902a9c0_Time Rolls On - page 013.jpg'</span>,\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">filename</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'Time Rolls On - page 013.jpg'</span>,\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">id</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">UUID</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008000; text-decoration-color: #008000\">'5c769d26-30bf-4950-ba3d-5dcabce690e7'</span><span style=\"font-weight: bold\">)</span>\n",
       "<span style=\"font-weight: bold\">)</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1;35mDocument\u001b[0m\u001b[1m(\u001b[0m\n",
       "    \u001b[33muploaded_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2026\u001b[0m, \u001b[1;36m6\u001b[0m, \u001b[1;36m28\u001b[0m, \u001b[1;36m17\u001b[0m, \u001b[1;36m9\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m392233\u001b[0m\u001b[1m)\u001b[0m,\n",
       "    \u001b[33mfile_path\u001b[0m=\u001b[32m'uploads/86a8f2c6-bfb7-4980-9941-56768902a9c0_Time Rolls On - page 013.jpg'\u001b[0m,\n",
       "    \u001b[33mfilename\u001b[0m=\u001b[32m'Time Rolls On - page 013.jpg'\u001b[0m,\n",
       "    \u001b[33mid\u001b[0m=\u001b[1;35mUUID\u001b[0m\u001b[1m(\u001b[0m\u001b[32m'5c769d26-30bf-4950-ba3d-5dcabce690e7'\u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[1m)\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "jobs = await s.jobs.list_jobs()\n",
    "rich.print(jobs)\n",
    "document = jobs[0].document\n",
    "rich.print(document)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d89041bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2026-06-28 12:53:20 INFO     | Loaded prompt artifact: prompts/transcribe_document.md\n",
      "2026-06-28 12:53:20 INFO     | Starting transcription for image=uploads/86a8f2c6-bfb7-4980-9941-56768902a9c0_Time Rolls On - page 013.jpg mime_type=image/jpeg\n",
      "2026-06-28 12:53:22 INFO     | HTTP Request: POST https://openrouter.ai/api/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
      "2026-06-28 12:53:26 INFO     | OpenRouter transcription completed using model=google/gemini-2.5-flash\n",
      "2026-06-28 12:53:26 INFO     | Transcription completed for image=uploads/86a8f2c6-bfb7-4980-9941-56768902a9c0_Time Rolls On - page 013.jpg provider=openrouter\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "TranscriptionResult(text='-13-\\nWe lived fairly well. We had plenty of wheat at the flour mill. We had\\n[taken this wheat as pay for our work in harvest. Beef was very cheap,\\nfour and five cents per pound, syrup one dollar per gallon in tin cans,\\nsugar five cents a pound, brown sugar, and my sister Texie was a good\\ncook, and Billy and Pleas would entertain us of an evening with their\\nwierd tales of their hardships in their travels to the railroad to\\nget work. They got $2.00 per day driving scraper teams on the dump.\\nThey had to go to Sprague, a distance of 60 miles, and carry their\\nblankets on their backs. Billy always carried a pistol and Pleas a\\npipe. They were pretty short of change and finally went broke. This\\ntook place near Rock Lake, Washington Territory. So Billy traded his\\npistol for two loaves of bread and supper and breakfast for both of\\nthem. But before they got a job Pleas had to trade his pipe for a\\ncouple more loaves.\\n\\nNow this winter of 1880 was a long and dreary winter. There was lots\\nof snow and we did not go to any of the social activities such as church\\nor debates at the school house, or singings in the neighborhood, and\\nTexie and I named the entertainments given from time to time each\\nevening \"The Modoc Struggle.\" Until this day the phrase used in the\\nCochran or Kittrell families expresses some memorable hardships in the\\nbattle of life.\\n\\nIn February of 1881 I visited our old friends, the Stevensons, and Mr.\\nStevenson was wanting a man to help him cut some cordwood and would\\npay one dollar per day. Snow! Snow! Snow! Everyday I was expecting\\nhim to have to quit work. Mr. Stevenson told me afterward he was expect-\\ning me to quit anytime on account of the snow and cold and he was anxious\\nto get enough wood cut to give him employment hauling wood to Colfax\\nduring the summer to get his groceries and pay his store bill, as credit\\nwas all the go with the homesteader.\\n\\nCapital stood in with men who were trying to improve the land and make\\na home. This credit system worked, especially for the merchant and the\\nimplement concerns and fairly well for the banker. The common interest\\nwas 1½ percent per month, and sometimes as high as two percent. There\\nwere many stock mortgages or a man on your note. The notes were usually\\npayable in 90 days or renew your note.\\n\\nSo the spring of 1881 was here and the O.R. and N. railroad was being\\nbuilt from Texas Ferry on the Snake River to Colfax. Men teams were\\nwanted at $4.00 per day. Pleas, Texie, Billy and I were anxious to\\nstart. We bought us a tent and a team apiece and went to Texas Ferry\\nto make our fortune. The roads were not very good. The horses were\\nrather cold shouldered and we had to be pulled out of the mud sometimes\\nbut teamsters were good hearted and seldom charged each other. This\\nwas March. When we go[t] to Snake River it was fine spring weather.\\n\\nNow it was December 1880 that Billy and I had come from Walla Walla in\\na storm of snow and hundreds of head of cattle were in the road. They\\nwere lowing and taking shelter along the bluffs. Now as we were going\\nalong the same road for miles a person could step from one [carcass?] to\\nanother. There were carcasses of cows, calves, big steers, and some\\nhorses, lining the road.\\n\\nThe Company had to clear the way for travel. Stock men had prepared\\nno feed. Now they had no stock. It was referred to as the \"Cow Killer\"', provider='openrouter', prompt_name='', model='google/gemini-2.5-flash')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "await transcribe_document_image(document.file_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5e66d40",
   "metadata": {},
   "outputs": [],
   "source": [
    "async with get_session() as session:\n",
    "    queued_jobs = await s.jobs.query_jobs(status=JobStatus.QUEUED, session=session)\n",
    "    job = await s.jobs.read_job(queued_jobs[0].id, session=session)\n",
    "\n",
    "rich.print(job)\n",
    "job = Job.model_copy(job)\n",
    "rich.print(job.document)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b8695009",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2026-06-28 12:53:53 DEBUG    | Initialized async database runtime for database_url=sqlite+aiosqlite:///./transcription.db\n",
      "2026-06-28 12:53:53 INFO     | Loaded prompt artifact: prompts/transcribe_document.md\n",
      "2026-06-28 12:53:53 INFO     | Starting transcription for image=uploads/86a8f2c6-bfb7-4980-9941-56768902a9c0_Time Rolls On - page 013.jpg mime_type=image/jpeg\n",
      "2026-06-28 12:53:54 INFO     | HTTP Request: POST https://openrouter.ai/api/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
      "2026-06-28 12:53:58 INFO     | OpenRouter transcription completed using model=google/gemini-2.5-flash\n",
      "2026-06-28 12:53:58 INFO     | Transcription completed for image=uploads/86a8f2c6-bfb7-4980-9941-56768902a9c0_Time Rolls On - page 013.jpg provider=openrouter\n",
      "2026-06-28 12:53:58 INFO     | Job transcribed operation=worker.process_job job_id=7a0d5e44-64e9-4916-83e0-bde3a8fb8c58 document_id=5c769d26-30bf-4950-ba3d-5dcabce690e7 provider=openrouter\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Job</span><span style=\"font-weight: bold\">(</span>\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">document_id</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">UUID</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008000; text-decoration-color: #008000\">'5c769d26-30bf-4950-ba3d-5dcabce690e7'</span><span style=\"font-weight: bold\">)</span>,\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">status</span>=<span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">JobStatus.TRANSCRIBED:</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'transcribed'</span><span style=\"font-weight: bold\">&gt;</span>,\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">created_at</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">datetime</span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">.datetime</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2026</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">6</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">28</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">17</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">9</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">26</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">395914</span><span style=\"font-weight: bold\">)</span>,\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">id</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">UUID</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008000; text-decoration-color: #008000\">'7a0d5e44-64e9-4916-83e0-bde3a8fb8c58'</span><span style=\"font-weight: bold\">)</span>,\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">retry_count</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span>,\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">updated_at</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">datetime</span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">.datetime</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2026</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">6</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">28</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">17</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">53</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">58</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">96639</span><span style=\"font-weight: bold\">)</span>\n",
       "<span style=\"font-weight: bold\">)</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1;35mJob\u001b[0m\u001b[1m(\u001b[0m\n",
       "    \u001b[33mdocument_id\u001b[0m=\u001b[1;35mUUID\u001b[0m\u001b[1m(\u001b[0m\u001b[32m'5c769d26-30bf-4950-ba3d-5dcabce690e7'\u001b[0m\u001b[1m)\u001b[0m,\n",
       "    \u001b[33mstatus\u001b[0m=\u001b[1m<\u001b[0m\u001b[1;95mJobStatus.TRANSCRIBED:\u001b[0m\u001b[39m \u001b[0m\u001b[32m'transcribed'\u001b[0m\u001b[1m>\u001b[0m,\n",
       "    \u001b[33mcreated_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2026\u001b[0m, \u001b[1;36m6\u001b[0m, \u001b[1;36m28\u001b[0m, \u001b[1;36m17\u001b[0m, \u001b[1;36m9\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m395914\u001b[0m\u001b[1m)\u001b[0m,\n",
       "    \u001b[33mid\u001b[0m=\u001b[1;35mUUID\u001b[0m\u001b[1m(\u001b[0m\u001b[32m'7a0d5e44-64e9-4916-83e0-bde3a8fb8c58'\u001b[0m\u001b[1m)\u001b[0m,\n",
       "    \u001b[33mretry_count\u001b[0m=\u001b[1;36m2\u001b[0m,\n",
       "    \u001b[33mupdated_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2026\u001b[0m, \u001b[1;36m6\u001b[0m, \u001b[1;36m28\u001b[0m, \u001b[1;36m17\u001b[0m, \u001b[1;36m53\u001b[0m, \u001b[1;36m58\u001b[0m, \u001b[1;36m96639\u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[1m)\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "async with get_session() as session:\n",
    "    queued_jobs = await s.jobs.list_jobs(session=session)\n",
    "    job = await s.jobs.read_job(queued_jobs[0].id, session=session)\n",
    "\n",
    "result = await wf.advance_job(\n",
    "    job,\n",
    "    services=s,\n",
    "    settings=settings,\n",
    "    # session=session,\n",
    ")\n",
    "rich.print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5b767e7f",
   "metadata": {},
   "outputs": [],
   "source": [
    "rich.print(settings)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a140db21",
   "metadata": {},
   "outputs": [],
   "source": [
    "async def reset_jobs():\n",
    "    \"\"\"Reset all jobs to QUEUED for testing purposes.\"\"\"\n",
    "    async with get_session() as session:\n",
    "        jobs = await s.jobs.query_jobs(session=session)\n",
    "        for job in jobs:\n",
    "            job.status = JobStatus.QUEUED\n",
    "            await s.jobs.update_job(job, session=session)\n",
    "        await session.commit()\n",
    "\n",
    "\n",
    "await reset_jobs()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "477aaa2a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "transcription (3.12.11)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
