@@ -59,10 +59,11 @@ def process_stdin_records() -> int:
5959 """
6060 from django .utils import timezone
6161
62- from archivebox .misc .jsonl import read_stdin , write_record , TYPE_CRAWL , TYPE_SNAPSHOT , TYPE_ARCHIVERESULT
62+ from archivebox .misc .jsonl import read_stdin , write_record , TYPE_CRAWL , TYPE_SNAPSHOT , TYPE_ARCHIVERESULT , TYPE_BINARY
6363 from archivebox .base_models .models import get_or_create_system_user_pk
6464 from archivebox .core .models import Snapshot , ArchiveResult
6565 from archivebox .crawls .models import Crawl
66+ from archivebox .machine .models import Binary
6667 from archivebox .workers .orchestrator import Orchestrator
6768
6869 records = list (read_stdin ())
@@ -137,6 +138,26 @@ def process_stdin_records() -> int:
137138 output_records .append (archiveresult .to_json ())
138139 queued_count += 1
139140
141+ elif record_type == TYPE_BINARY :
142+ # Binary records - create or update and queue for installation
143+ if record_id :
144+ # Existing binary - re-queue
145+ try :
146+ binary = Binary .objects .get (id = record_id )
147+ except Binary .DoesNotExist :
148+ binary = Binary .from_json (record )
149+ else :
150+ # New binary - create it
151+ binary = Binary .from_json (record )
152+
153+ if binary :
154+ binary .retry_at = timezone .now ()
155+ if binary .status != Binary .StatusChoices .INSTALLED :
156+ binary .status = Binary .StatusChoices .QUEUED
157+ binary .save ()
158+ output_records .append (binary .to_json ())
159+ queued_count += 1
160+
140161 else :
141162 # Unknown type - pass through
142163 output_records .append (record )
@@ -222,7 +243,8 @@ def run_snapshot_worker(snapshot_id: str) -> int:
222243@click .option ('--daemon' , '-d' , is_flag = True , help = "Run forever (don't exit on idle)" )
223244@click .option ('--crawl-id' , help = "Run orchestrator for specific crawl only" )
224245@click .option ('--snapshot-id' , help = "Run worker for specific snapshot only" )
225- def main (daemon : bool , crawl_id : str , snapshot_id : str ):
246+ @click .option ('--binary-id' , help = "Run worker for specific binary only" )
247+ def main (daemon : bool , crawl_id : str , snapshot_id : str , binary_id : str ):
226248 """
227249 Process queued work.
228250
@@ -231,11 +253,27 @@ def main(daemon: bool, crawl_id: str, snapshot_id: str):
231253 - No args + TTY: Run orchestrator for all work
232254 - --crawl-id: Run orchestrator for that crawl only
233255 - --snapshot-id: Run worker for that snapshot only
256+ - --binary-id: Run worker for that binary only
234257 """
235258 # Snapshot worker mode
236259 if snapshot_id :
237260 sys .exit (run_snapshot_worker (snapshot_id ))
238261
262+ # Binary worker mode
263+ if binary_id :
264+ from archivebox .workers .worker import BinaryWorker
265+ try :
266+ worker = BinaryWorker (binary_id = binary_id , worker_id = 0 )
267+ worker .runloop ()
268+ sys .exit (0 )
269+ except KeyboardInterrupt :
270+ sys .exit (0 )
271+ except Exception as e :
272+ rprint (f'[red]Worker error: { type (e ).__name__ } : { e } [/red]' , file = sys .stderr )
273+ import traceback
274+ traceback .print_exc ()
275+ sys .exit (1 )
276+
239277 # Crawl worker mode
240278 if crawl_id :
241279 from archivebox .workers .worker import CrawlWorker
0 commit comments