feat: printing files go into each machine's hot folder, part by part (item 10)
All checks were successful
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m13s
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 3m56s
All checks were successful
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m13s
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 3m56s
Pulled to Imprimindo, an order's files go as a copy into 3. Imprimindo/<máquina>/<C1|C2|C3>/, the class of each item (chosen in the Kanban, or measured by the Site), where FlexiPRINT takes them (Dropstar's third round, item 10). A film in parts goes to the same machine, in order, never more than two parts in its folder: the next is written when Flexi takes one. The card says "Parte 3/7 imprimindo · 4/7 ripando". The server decides what each folder gets (app/hotfolder.py, dtf_local.hot_parts) and the Kanban's computers write it: each part is claimed by one computer, so Flexi never gets it twice; a claim that did not finish goes back to the queue; a part gone from its folder was taken and is never written again; a card that leaves Imprimindo or is cancelled has what Flexi did not take deleted. A part without a class waits for one, and the class may still change in Imprimindo until its file is written. The folder sync also follows files one by one, so the parts of a film over 15 m are no longer taken for replaced copies of each other. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,7 @@ from ..core.auth import (COOKIE_SECURE, DUMMY_PASSWORD_HASH, MOVERS, audit, can,
|
||||
login_failed, may_move, may_reorder, password_matches, throttle)
|
||||
from ..core.models import Contraction, Move, OperatorLogin, Resolution, Review, StrictModel, UploadStart
|
||||
from ..printjobs import file_prefix, queue as queue_print_files
|
||||
from .. import cnpj, machines, mail, payments, proof, quote_review, receipt
|
||||
from .. import cnpj, hotfolder, machines, mail, payments, proof, quote_review, receipt
|
||||
from .. import tiny
|
||||
from ..runtime import (BACK, BOARD_FINISHED_LIMIT, BOARD_QUOTE_LIMIT, ENVIRONMENT, PUBLIC_ORIGIN, STATES,
|
||||
TRANSITIONS, payment, enqueue, freight, operator_identity, quote_view, quote_views, storage, upload_row)
|
||||
@@ -236,7 +236,10 @@ def with_print_files(c, orders):
|
||||
# Why each order was last sent to correction, for the notice to the customer.
|
||||
reasons = {row['order_id']: row['reason'] for row in c.execute('''SELECT DISTINCT ON (order_id) order_id,reason
|
||||
FROM dtf_local.movements WHERE order_id=ANY(%s) AND to_state='cor' ORDER BY order_id,id DESC''', (ids,)).fetchall()}
|
||||
# Where a printing order's files are in its machine's hot folder (item 10).
|
||||
hot = hotfolder.progress(c, [o['id'] for o in orders if o['state'] == 'imp'])
|
||||
for order in orders:
|
||||
order['hot'] = hot.get(order['id'])
|
||||
order['correction_reason'] = reasons.get(order['id']) if order['state'] == 'cor' else None
|
||||
order['print_files'] = [row for row in generated if row['order_id'] == order['id']]
|
||||
approved = [row for row in finals if row['order_id'] == order['id']]
|
||||
@@ -646,6 +649,7 @@ def cancel_order(uid: UUID, body: Resolution, user=Depends(can('cancel'))):
|
||||
(user, body.note, uid)).fetchone()
|
||||
if not row:
|
||||
raise HTTPException(404, 'Pedido não encontrado ou já cancelado.')
|
||||
hotfolder.stop(c, uid)
|
||||
if payments.in_tiny(row):
|
||||
sale = c.execute("SELECT receipt FROM dtf_local.outbox WHERE event_key=%s AND delivered_at IS NOT NULL",
|
||||
(f'{uid}:paid:tiny',)).fetchone()
|
||||
@@ -693,10 +697,14 @@ def choose_contraction(uid: UUID, body: Contraction, user=Depends(can('produce')
|
||||
(uid,)).fetchone()
|
||||
if not row:
|
||||
raise HTTPException(404, 'Pedido não encontrado.')
|
||||
if row['cancelled_at'] or row['state'] not in ('rec', 'tra', 'cor'):
|
||||
raise HTTPException(409, 'A contração muda até o pedido ir para Imprimindo.')
|
||||
if body.item_index >= len(row['snapshot']['items']):
|
||||
raise HTTPException(422, 'Item não encontrado no pedido.')
|
||||
# Printing, the class still changes while the item's files wait to go
|
||||
# into the hot folder: the class is its folder (item 10).
|
||||
written = row['state'] == 'imp' and c.execute('''SELECT 1 FROM dtf_local.hot_parts WHERE order_id=%s
|
||||
AND item_index=%s AND state NOT IN ('queued','gone') LIMIT 1''', (uid, body.item_index)).fetchone()
|
||||
if row['cancelled_at'] or row['state'] not in ('rec', 'tra', 'cor', 'imp') or written:
|
||||
raise HTTPException(409, 'A contração muda até o arquivo ir para a hot folder da máquina.')
|
||||
chosen = dict(row['contraction'] or {})
|
||||
key = str(body.item_index)
|
||||
if body.value is None:
|
||||
@@ -972,6 +980,12 @@ def move(uid: UUID, body: Move, request: Request, user=Depends(operator)):
|
||||
(row['machine_id'],)).fetchone() or {}).get('name')
|
||||
c.execute('''INSERT INTO dtf_local.movements(order_id,from_state,to_state,operator,reason,back,machine)
|
||||
VALUES(%s,%s,%s,%s,%s,%s,%s)''', (uid,row['state'],body.state,user,body.reason,back,machine_name))
|
||||
# Pulled to Imprimindo, its files go to its machine's hot folder; out
|
||||
# of it, what Flexi did not take leaves (item 10).
|
||||
if row['state'] == 'imp':
|
||||
hotfolder.stop(c, uid)
|
||||
if body.state == 'imp':
|
||||
hotfolder.start(c, uid)
|
||||
# A pickup reaching Finalizado has its receipt due (item 14), once.
|
||||
due = body.state == 'fin' and not back and receipt.is_pickup(row['snapshot'])
|
||||
changed = c.execute('''UPDATE dtf_local.orders SET state=%s, version=version+1, updated_at=now(), queue_key=NULL,
|
||||
@@ -1418,6 +1432,42 @@ class FolderSync(StrictModel):
|
||||
since: datetime | None = None
|
||||
|
||||
|
||||
@router.post('/api/operator/queue/hot')
|
||||
def queue_hot(user=Depends(can('print'))):
|
||||
"""For a computer with the automatic folders: the parts it should write
|
||||
into the machines' hot folders now, claimed for it alone; those written
|
||||
and not yet taken by Flexi, to see whether they still are; and those to
|
||||
delete, withdrawn from cards that left Imprimindo (item 10)."""
|
||||
with db.connect() as c:
|
||||
due = hotfolder.claim(c, user)
|
||||
keys = {str(r['upload_id']): r['object_key'] for r in c.execute(
|
||||
'SELECT id AS upload_id, object_key FROM dtf_local.uploads WHERE id=ANY(%s)',
|
||||
([r['upload_id'] for r in due],)).fetchall()} if due else {}
|
||||
watched = hotfolder.watched(c)
|
||||
return {'folder': hotfolder.PRINTING_FOLDER,
|
||||
'write': [{'id': r['id'], 'order': str(r['order_id']), 'folder': r['folder'], 'name': r['name'],
|
||||
'url': storage.download(keys[str(r['upload_id'])], r['name'])} for r in due],
|
||||
'watch': [{'id': r['id'], 'order': str(r['order_id']), 'folder': r['folder'], 'name': r['name']}
|
||||
for r in watched if r['state'] == 'written'],
|
||||
'withdraw': [{'id': r['id'], 'order': str(r['order_id']), 'folder': r['folder'], 'name': r['name']}
|
||||
for r in watched if r['state'] == 'withdraw']}
|
||||
|
||||
|
||||
class HotReport(StrictModel):
|
||||
state: Literal['written', 'released', 'consumed', 'gone']
|
||||
|
||||
|
||||
@router.post('/api/operator/queue/hot/{part_id}')
|
||||
def report_hot(part_id: int, body: HotReport, user=Depends(can('print'))):
|
||||
"""What a computer saw of a part: written, not written, taken by Flexi,
|
||||
or deleted after it was withdrawn."""
|
||||
with db.connect() as c:
|
||||
applied = hotfolder.report(c, part_id, body.state, user)
|
||||
if applied and body.state == 'written':
|
||||
audit('hot_folder_written', part=part_id, operator=user)
|
||||
return {'ok': applied}
|
||||
|
||||
|
||||
@router.post('/api/operator/queue/folder')
|
||||
def queue_folder(body: FolderSync, user=Depends(can('print'))):
|
||||
"""What the Kanban's automatic folders should hold. `early` is Dropstar's
|
||||
|
||||
Reference in New Issue
Block a user