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

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:
Cauê Faleiros
2026-11-03 17:05:08 -03:00
parent 353935bed3
commit e3a5ad6fa0
6 changed files with 289 additions and 10 deletions

View File

@@ -422,6 +422,36 @@ async function fetchInto(dir,file){
await writeWhole(dir,file.name,r.body);
}
// The machines' hot folders (item 10): 3. Imprimindo/<máquina>/<C1|C2|C3>/.
// The server says what this computer writes now (claimed for it alone, two
// parts at most per machine); a written part gone from its folder was taken
// by FlexiPRINT, and is never written again; a withdrawn one, from a card that
// left Imprimindo, is deleted if Flexi has not taken it. Returns how many
// parts it wrote.
async function syncHot(){
const hot=await api('/queue/hot',{});
if(!hot.write.length&&!hot.watch.length&&!hot.withdraw.length)return 0;
const root=await stageDir(hot.folder);
const dirOf=async path=>{let dir=root;for(const part of path.split('/'))dir=await dir.getDirectoryHandle(part,{create:true});return dir;};
const missing=e=>e.name==='NotFoundError';
for(const p of hot.withdraw){
await (await dirOf(p.folder)).removeEntry(p.name).catch(e=>{if(!missing(e))throw e;});
await api('/queue/hot/'+p.id,{state:'gone'});
}
for(const p of hot.watch){
try{await (await dirOf(p.folder)).getFileHandle(p.name);}
catch(e){if(!missing(e))throw e;await api('/queue/hot/'+p.id,{state:'consumed'});}
}
let written=0;
for(const p of hot.write){
FOLDER.status='Gravando na hot folder '+p.folder+': '+p.name;paintFolder();
try{await fetchInto(await dirOf(p.folder),p);}
catch(e){await api('/queue/hot/'+p.id,{state:'released'}).catch(()=>{});throw e;}
await api('/queue/hot/'+p.id,{state:'written'});written++;
}
return written;
}
// Bring the folders in line with the board: remove the files of orders that
// were cancelled, deleted, sent back for correction or given another file,
// and those kept their days in Finalizado; move each file to its stage's
@@ -441,7 +471,8 @@ async function syncFolder(force=false){
if(stages)await makeStageFolders();
const held=stages?[...new Set([...FOLDER.saved.values()].map(r=>r.order).filter(Boolean))].slice(-1000):[];
const {files,states,receipts=[]}=await api('/queue/folder',{early:stages,held,since:stages?FOLDER.since||await folderSince():null});
const wanted=new Map(files.map(f=>[f.order+':'+f.item,f]));
// By file: an item over 15 m is several parts (item 13), each its own file.
const wanted=new Map(files.map(f=>[f.upload_id,f]));
const where=stages?'“'+FOLDER.handle.name+'”':'a pasta de downloads';
let removed=0, moved=0, saved=0;
const record=async(uid,file,folder)=>{
@@ -451,8 +482,8 @@ async function syncFolder(force=false){
if(stages)for(const [uid,rec] of [...FOLDER.saved]){
if(!rec.order||!rec.folder)continue;
const state=states[rec.order], target=STAGE_FOLDERS[state];
const now=wanted.get(rec.order+':'+rec.item);
const replaced=(state==='rec'||state==='tra')&&(!now||now.upload_id!==uid);
const now=wanted.get(uid);
const replaced=(state==='rec'||state==='tra')&&(!now||now.order!==rec.order);
const kept=rec.folder===STAGE_FOLDERS.fin&&Date.now()-(rec.at||0)>KEEP_FINISHED_DAYS*86400000;
if(!target||replaced||kept){await removeSaved(rec);FOLDER.saved.delete(uid);removed++;await keepSaved();continue;}
if(rec.folder===target)continue;
@@ -461,6 +492,7 @@ async function syncFolder(force=false){
if(now&&now.upload_id===uid){await fetchInto(await stageDir(target),now);await record(uid,now,target);moved++;}
else{FOLDER.saved.delete(uid);await keepSaved();}
}
const hot=stages?await syncHot():0;
if(stages)for(const old of OLD_FOLDERS)
if(![...FOLDER.saved.values()].some(r=>r.folder===old))await FOLDER.handle.removeEntry(old).catch(()=>{});
// New files, each into its stage's folder: the server sends those in Arte
@@ -498,6 +530,7 @@ async function syncFolder(force=false){
FOLDER.lastSig=sig;FOLDER.error='';
FOLDER.status='';
if(saved)say((stages?'Salvos ':'Baixados ')+saved+' arquivo(s) em '+where+'.');
if(hot)say('Gravados '+hot+' arquivo(s) na hot folder da máquina.');
if(printed)say(printed+' recibo(s) de retirada salvos em '+RECEIPTS_FOLDER+'.');
if(moved)say(moved+' arquivo(s) mudaram de pasta com o pedido.');
if(removed)say(removed+' arquivo(s) de pedidos cancelados, excluídos, em correção, trocados ou finalizados há mais de '+KEEP_FINISHED_DAYS+' dias saíram das pastas.');
@@ -666,6 +699,16 @@ const residueBadge=item=>badge('! Resíduo aceito','warn','O cliente aceitou imp
// in is printing, the next is being ripped meanwhile.
const PRINTING={imprimindo:['Imprimindo','live','Já ripou, está rodando'],
ripando:['Ripando','rip','O Flexi está ripando enquanto o anterior roda']};
// A film in parts on its machine (items 10 and 13, Dropstar 2026-10-30):
// "parte 3/7 imprimindo · 4/7 ripando". Flexi rips the part it took last from
// the hot folder while the one before it prints.
function partsStep(order){
const hot=order.hot;if(!hot||hot.parts<2)return null;
const n=hot.parts, t=hot.taken;
if(!t)return ['Parte 1/'+n+' na hot folder','wait'];
if(t===1)return ['Parte 1/'+n+' ripando','rip'];
return ['Parte '+(t-1)+'/'+n+' imprimindo · '+t+'/'+n+' ripando','live'];
}
async function proofOk(order){
await api('/orders/'+order.id+'/proof',{});say('Prova do pedido #'+order.number+' conferida.');await load();
}
@@ -910,7 +953,7 @@ function nextStep(order,place){
if(order.cancelled_at)return ['Cancelado','wait'];
if(order.state==='cor')return ['Esperando o cliente','wait'];
if(order.state==='rev')return ['Conferir a folha','act'];
if(order.state==='imp')return order.printing?PRINTING[order.printing].slice(0,2):['Na máquina','wait'];
if(order.state==='imp')return partsStep(order)||(order.printing?PRINTING[order.printing].slice(0,2):['Na máquina','wait']);
if(order.state==='tra'){
// The operator whose machine prints this product pulls the first one.
const m=(board.machines||[]).find(x=>x.id===myMachine()?.id);