Job 1788378627533

Command: python -c "from pathlib import Path;s=Path(r'C:\Users\ash\ChatGPTMasterBridge\Code.gs').read_text(encoding='utf-8');a=s.index('function poll_');b=s.index('function result_',a);print(s[a:b])"
Directory: projects
Status: SUCCESS
Exit code: 0

Cancel Job Rerun Command Refresh

function poll_(bridge, target) {
  const lock = LockService.getScriptLock();
  if (!lock.tryLock(5000)) {
    return json_({ ok: true, target: target, command: null, busy: true });
  }
  try {
    const sheet = sheetById_(bridge.spreadsheet_id, COMMANDS_SHEET);
    const values = sheet.getDataRange().getValues();
    const headers = values[0] || [];
    const col = headerMap_(headers);
    for (let r = 1; r < values.length; r++) {
      const row = values[r];
      const status = String(row[col.status] || '').toLowerCase();
      const confirm = String(row[col.confirm] || '').toLowerCase();
      if (status === 'pending' && confirm === 'yes') {
        const liveStatus = String(sheet.getRange(r + 1, col.status + 1).getValue() || '').toLowerCase();
        const liveConfirm = String(sheet.getRange(r + 1, col.confirm + 1).getValue() || '').toLowerCase();
        if (liveStatus !== 'pending' || liveConfirm !== 'yes') continue;
        const attempts = Number(sheet.getRange(r + 1, col.attempts + 1).getValue() || 0) + 1;
        sheet.getRange(r + 1, col.status + 1).setValue('running');
        sheet.getRange(r + 1, col.claimed_at + 1).setValue(nowIso_());
        sheet.getRange(r + 1, col.attempts + 1).setValue(attempts);
        SpreadsheetApp.flush();
        return json_({
          ok: true,
          target: target,
          command: {
            row: r + 1,
            id: String(row[col.id] || ''),
            action: String(row[col.action] || ''),
            payload_json: String(row[col.payload_json] || '{}'),
            attempts: attempts
          }
        });
      }
    }
    return json_({ ok: true, target: target, command: null });
  } finally {
    lock.releaseLock();
  }
}