Пример #1
0
def add(**kwargs):
    torrent = Torrent(**kwargs)
    torrent.status = Status.ENQUEUED
    DB.session.add(torrent)
    DB.session.commit()
    QUEUE.put_nowait(torrent.id)
    events.send_torrent(torrent)
Пример #2
0
def retry(torrent_id):
    query = Torrent.query.filter_by(id=torrent_id)
    torrent = query.first_or_404()
    torrent.status = Status.ENQUEUED
    DB.session.commit()
    _add_line(
        torrent,
        "[betanin] retrying... "
        f"(there are {len(QUEUE)} items in the queue)",
    )
    events.send_torrent(torrent)
    QUEUE.put_nowait(torrent.id)
Пример #3
0
def _read_and_send_pty_out(proc, torrent):
    while True:
        try:
            data = gevent.os.tp_read(proc.fd, 65536)
        except OSError:
            break
        text = data.decode()
        if text.isspace():
            continue
        _add_line(torrent, text)
        if any(match in text for match in NEEDS_INPUT_SNIPPETS):
            torrent.status = Status.NEEDS_INPUT
            DB.session.commit()
            events.send_torrent(torrent)
            notifications.send_async(torrent)
Пример #4
0
def _start():
    while True:
        torrent_id = QUEUE.get()
        logger.info(f"got new torrent with id {torrent_id}")
        torrent = Torrent.query.get(torrent_id)
        torrent.status = Status.PROCESSING
        DB.session.commit()
        _add_line(torrent, "[betanin] starting cli program")
        events.send_torrent(torrent)
        return_code = _import_torrent(torrent)
        _add_line(
            torrent,
            f"[betanin] program finished with exit status `{return_code}`",
        )
        torrent.status = Status.FAILED
        if return_code == 0:
            torrent.status = Status.COMPLETED
        logger.info(f"torrent finished with return code {return_code}")
        DB.session.commit()
        events.send_torrent(torrent)
        notifications.send_async(torrent)