Compare commits

...

10 Commits

Author SHA1 Message Date
Kelly
3f958fbff3 fix(ci): Fix buildx cache_from syntax for array format
Plugin was splitting comma-separated values incorrectly.
Use array format with quoted strings instead.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-11 21:10:26 -07:00
Kelly
c84ef0396b feat(tasks): Add proxy_test task handler and discovery run tracking
- Add proxy_test task handler that fetches IP via proxy to verify connectivity
- Add discovery_runs migration (083) for tracking store discovery progress
- Register proxy_test in task service and worker

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-11 21:07:58 -07:00
Kelly
6cd1f55119 fix(workers): Preserve fantasy names on pod restart
- Re-registration no longer overwrites pod_name with K8s name
- New workers get fantasy name (Aethelgard, Xylos, etc.) as pod_name
- Document worker naming convention in CLAUDE.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-11 20:35:25 -07:00
Kelly
e918234928 feat(ci): Add npm cache volume for faster typechecks
- Create PVC for shared npm cache across CI jobs
- Configure Woodpecker agent to allow npm-cache volume mount
- Update typecheck steps to use shared cache directory
- First run populates cache, subsequent runs are ~3-4x faster

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-11 19:27:32 -07:00
Kelly
888a608485 feat(cannaiq): Add clickable logo, favicon, and remove state selector
- Make CannaIQ logo clickable to return to dashboard (sidebar + mobile header)
- Add custom favicon matching the logo design
- Remove state selector dropdown from sidebar navigation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-11 19:24:21 -07:00
kelly
b5c3b05246 Merge pull request 'fix(workers): Fix false memory backoff and add backing-off color coding' (#44) from fix/worker-memory-backoff into master 2025-12-12 02:13:51 +00:00
Kelly
fdce5e0302 fix(workers): Fix false memory backoff and add backing-off color coding
- Fix memory calculation to use max-old-space-size (1500MB) instead of
  V8's dynamic heapTotal. This prevents false 95%+ readings when idle.
- Add yellow color for backing-off workers in pod visualization
- Update legend and tooltips with backing-off status
- Remove pool toggle from TasksDashboard (moved to Workers page)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-11 19:11:42 -07:00
Kelly
4679b245de perf(ci): Enable Docker layer caching for faster builds
Add cache_from and cache_to settings to all docker-buildx steps.
Uses registry-based caching to avoid rebuilding npm install layer
when package.json hasn't changed.

Expected improvement: 14min backend build → ~3-4min on cache hit.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-11 18:43:43 -07:00
kelly
a837070f54 Merge pull request 'refactor(admin): Consolidate JobQueue into TasksDashboard + CI worker resilience' (#43) from fix/ci-worker-resilience into master 2025-12-12 01:21:28 +00:00
kelly
52b0fad410 Merge pull request 'ci: Add worker resilience check to deploy step' (#42) from fix/ci-worker-resilience into master
Reviewed-on: https://code.cannabrands.app/Creationshop/dispensary-scraper/pulls/42
2025-12-12 00:09:48 +00:00
16 changed files with 260 additions and 97 deletions

View File

@@ -86,6 +86,10 @@ steps:
from_secret: registry_password from_secret: registry_password
platforms: linux/amd64 platforms: linux/amd64
provenance: false provenance: false
cache_from:
- "type=registry,ref=code.cannabrands.app/creationshop/dispensary-scraper:cache"
cache_to:
- "type=registry,ref=code.cannabrands.app/creationshop/dispensary-scraper:cache,mode=max"
build_args: build_args:
APP_BUILD_VERSION: ${CI_COMMIT_SHA:0:8} APP_BUILD_VERSION: ${CI_COMMIT_SHA:0:8}
APP_GIT_SHA: ${CI_COMMIT_SHA} APP_GIT_SHA: ${CI_COMMIT_SHA}
@@ -112,6 +116,10 @@ steps:
from_secret: registry_password from_secret: registry_password
platforms: linux/amd64 platforms: linux/amd64
provenance: false provenance: false
cache_from:
- "type=registry,ref=code.cannabrands.app/creationshop/cannaiq-frontend:cache"
cache_to:
- "type=registry,ref=code.cannabrands.app/creationshop/cannaiq-frontend:cache,mode=max"
depends_on: [] depends_on: []
when: when:
branch: master branch: master
@@ -133,6 +141,10 @@ steps:
from_secret: registry_password from_secret: registry_password
platforms: linux/amd64 platforms: linux/amd64
provenance: false provenance: false
cache_from:
- "type=registry,ref=code.cannabrands.app/creationshop/findadispo-frontend:cache"
cache_to:
- "type=registry,ref=code.cannabrands.app/creationshop/findadispo-frontend:cache,mode=max"
depends_on: [] depends_on: []
when: when:
branch: master branch: master
@@ -154,6 +166,10 @@ steps:
from_secret: registry_password from_secret: registry_password
platforms: linux/amd64 platforms: linux/amd64
provenance: false provenance: false
cache_from:
- "type=registry,ref=code.cannabrands.app/creationshop/findagram-frontend:cache"
cache_to:
- "type=registry,ref=code.cannabrands.app/creationshop/findagram-frontend:cache,mode=max"
depends_on: [] depends_on: []
when: when:
branch: master branch: master

View File

@@ -1,46 +1,38 @@
steps: steps:
# =========================================== # ===========================================
# PR VALIDATION: Parallel type checks (PRs only) # PR VALIDATION: Only typecheck changed projects
# =========================================== # ===========================================
typecheck-backend: typecheck-backend:
image: code.cannabrands.app/creationshop/node:20 image: code.cannabrands.app/creationshop/node:20
commands: commands:
- npm config set cache /npm-cache/backend --global
- cd backend - cd backend
- npm ci --prefer-offline - npm ci --prefer-offline
- npx tsc --noEmit - npx tsc --noEmit
volumes:
- npm-cache:/npm-cache
depends_on: [] depends_on: []
when: when:
event: pull_request event: pull_request
path:
include: ['backend/**']
typecheck-cannaiq: typecheck-cannaiq:
image: code.cannabrands.app/creationshop/node:20 image: code.cannabrands.app/creationshop/node:20
commands: commands:
- npm config set cache /npm-cache/cannaiq --global
- cd cannaiq - cd cannaiq
- npm ci --prefer-offline - npm ci --prefer-offline
- npx tsc --noEmit - npx tsc --noEmit
volumes:
- npm-cache:/npm-cache
depends_on: [] depends_on: []
when: when:
event: pull_request event: pull_request
path:
include: ['cannaiq/**']
typecheck-findadispo: # findadispo/findagram typechecks skipped - they have || true anyway
image: code.cannabrands.app/creationshop/node:20
commands:
- cd findadispo/frontend
- npm ci --prefer-offline
- npx tsc --noEmit 2>/dev/null || true
depends_on: []
when:
event: pull_request
typecheck-findagram:
image: code.cannabrands.app/creationshop/node:20
commands:
- cd findagram/frontend
- npm ci --prefer-offline
- npx tsc --noEmit 2>/dev/null || true
depends_on: []
when:
event: pull_request
# =========================================== # ===========================================
# AUTO-MERGE: Merge PR after all checks pass # AUTO-MERGE: Merge PR after all checks pass
@@ -62,8 +54,6 @@ steps:
depends_on: depends_on:
- typecheck-backend - typecheck-backend
- typecheck-cannaiq - typecheck-cannaiq
- typecheck-findadispo
- typecheck-findagram
when: when:
event: pull_request event: pull_request
@@ -86,6 +76,8 @@ steps:
from_secret: registry_password from_secret: registry_password
platforms: linux/amd64 platforms: linux/amd64
provenance: false provenance: false
cache_from: type=registry,ref=code.cannabrands.app/creationshop/dispensary-scraper:cache
cache_to: type=registry,ref=code.cannabrands.app/creationshop/dispensary-scraper:cache,mode=max
build_args: build_args:
APP_BUILD_VERSION: ${CI_COMMIT_SHA:0:8} APP_BUILD_VERSION: ${CI_COMMIT_SHA:0:8}
APP_GIT_SHA: ${CI_COMMIT_SHA} APP_GIT_SHA: ${CI_COMMIT_SHA}
@@ -112,6 +104,8 @@ steps:
from_secret: registry_password from_secret: registry_password
platforms: linux/amd64 platforms: linux/amd64
provenance: false provenance: false
cache_from: type=registry,ref=code.cannabrands.app/creationshop/cannaiq-frontend:cache
cache_to: type=registry,ref=code.cannabrands.app/creationshop/cannaiq-frontend:cache,mode=max
depends_on: [] depends_on: []
when: when:
branch: master branch: master
@@ -133,6 +127,8 @@ steps:
from_secret: registry_password from_secret: registry_password
platforms: linux/amd64 platforms: linux/amd64
provenance: false provenance: false
cache_from: type=registry,ref=code.cannabrands.app/creationshop/findadispo-frontend:cache
cache_to: type=registry,ref=code.cannabrands.app/creationshop/findadispo-frontend:cache,mode=max
depends_on: [] depends_on: []
when: when:
branch: master branch: master
@@ -154,6 +150,8 @@ steps:
from_secret: registry_password from_secret: registry_password
platforms: linux/amd64 platforms: linux/amd64
provenance: false provenance: false
cache_from: type=registry,ref=code.cannabrands.app/creationshop/findagram-frontend:cache
cache_to: type=registry,ref=code.cannabrands.app/creationshop/findagram-frontend:cache,mode=max
depends_on: [] depends_on: []
when: when:
branch: master branch: master

View File

@@ -939,7 +939,8 @@ export default defineConfig({
20) **Crawler Architecture** 20) **Crawler Architecture**
- **Scraper pod (1 replica)**: Runs the Express API server + scheduler. - **Scraper pod (1 replica)**: Runs the Express API server + scheduler.
- **Scraper-worker pods (5 replicas)**: Each worker runs `dist/dutchie-az/services/worker.js`, polling the job queue. - **Scraper-worker pods (25 replicas)**: Each runs `dist/tasks/task-worker.js`, polling the job queue.
- **Worker naming**: Pods use fantasy names (Aethelgard, Xylos, Kryll, Coriolis, etc.) - see `k8s/scraper-worker.yaml` ConfigMap. Worker IDs: `{PodName}-worker-{n}`
- **Job types**: `menu_detection`, `menu_detection_single`, `dutchie_product_crawl` - **Job types**: `menu_detection`, `menu_detection_single`, `dutchie_product_crawl`
- **Job schedules** (managed in `job_schedules` table): - **Job schedules** (managed in `job_schedules` table):
- `dutchie_az_menu_detection`: Runs daily with 60-min jitter - `dutchie_az_menu_detection`: Runs daily with 60-min jitter

View File

@@ -0,0 +1,88 @@
-- Migration 083: Discovery Run Tracking
-- Tracks progress of store discovery runs step-by-step
-- Main discovery runs table
CREATE TABLE IF NOT EXISTS discovery_runs (
id SERIAL PRIMARY KEY,
platform VARCHAR(50) NOT NULL DEFAULT 'dutchie',
status VARCHAR(20) NOT NULL DEFAULT 'running', -- running, completed, failed
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
finished_at TIMESTAMPTZ,
task_id INTEGER REFERENCES worker_task_queue(id),
-- Totals
states_total INTEGER DEFAULT 0,
states_completed INTEGER DEFAULT 0,
locations_discovered INTEGER DEFAULT 0,
locations_promoted INTEGER DEFAULT 0,
new_store_ids INTEGER[] DEFAULT '{}',
-- Error info
error_message TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- Per-state progress within a run
CREATE TABLE IF NOT EXISTS discovery_run_states (
id SERIAL PRIMARY KEY,
run_id INTEGER NOT NULL REFERENCES discovery_runs(id) ON DELETE CASCADE,
state_code VARCHAR(2) NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'pending', -- pending, running, completed, failed
started_at TIMESTAMPTZ,
finished_at TIMESTAMPTZ,
-- Results
cities_found INTEGER DEFAULT 0,
locations_found INTEGER DEFAULT 0,
locations_upserted INTEGER DEFAULT 0,
new_dispensary_ids INTEGER[] DEFAULT '{}',
-- Error info
error_message TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE(run_id, state_code)
);
-- Step-by-step log for detailed progress tracking
CREATE TABLE IF NOT EXISTS discovery_run_steps (
id SERIAL PRIMARY KEY,
run_id INTEGER NOT NULL REFERENCES discovery_runs(id) ON DELETE CASCADE,
state_code VARCHAR(2),
step_name VARCHAR(100) NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'started', -- started, completed, failed
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
finished_at TIMESTAMPTZ,
-- Details (JSON for flexibility)
details JSONB DEFAULT '{}',
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- Indexes for querying
CREATE INDEX IF NOT EXISTS idx_discovery_runs_status ON discovery_runs(status);
CREATE INDEX IF NOT EXISTS idx_discovery_runs_platform ON discovery_runs(platform);
CREATE INDEX IF NOT EXISTS idx_discovery_runs_started_at ON discovery_runs(started_at DESC);
CREATE INDEX IF NOT EXISTS idx_discovery_run_states_run_id ON discovery_run_states(run_id);
CREATE INDEX IF NOT EXISTS idx_discovery_run_steps_run_id ON discovery_run_steps(run_id);
-- View for latest run status per platform
CREATE OR REPLACE VIEW v_latest_discovery_runs AS
SELECT DISTINCT ON (platform)
id,
platform,
status,
started_at,
finished_at,
states_total,
states_completed,
locations_discovered,
locations_promoted,
array_length(new_store_ids, 1) as new_stores_count,
error_message,
EXTRACT(EPOCH FROM (COALESCE(finished_at, NOW()) - started_at)) as duration_seconds
FROM discovery_runs
ORDER BY platform, started_at DESC;

View File

@@ -70,21 +70,20 @@ router.post('/register', async (req: Request, res: Response) => {
); );
if (existing.rows.length > 0) { if (existing.rows.length > 0) {
// Re-activate existing worker // Re-activate existing worker - keep existing pod_name (fantasy name), don't overwrite with K8s name
const { rows } = await pool.query(` const { rows } = await pool.query(`
UPDATE worker_registry UPDATE worker_registry
SET status = 'active', SET status = 'active',
role = $1, role = $1,
pod_name = $2, hostname = $2,
hostname = $3, ip_address = $3,
ip_address = $4,
last_heartbeat_at = NOW(), last_heartbeat_at = NOW(),
started_at = NOW(), started_at = NOW(),
metadata = $5, metadata = $4,
updated_at = NOW() updated_at = NOW()
WHERE worker_id = $6 WHERE worker_id = $5
RETURNING id, worker_id, friendly_name, role RETURNING id, worker_id, friendly_name, pod_name, role
`, [role, pod_name, finalHostname, clientIp, metadata, finalWorkerId]); `, [role, finalHostname, clientIp, metadata, finalWorkerId]);
const worker = rows[0]; const worker = rows[0];
const roleMsg = role ? `for ${role}` : 'as role-agnostic'; const roleMsg = role ? `for ${role}` : 'as role-agnostic';
@@ -105,13 +104,13 @@ router.post('/register', async (req: Request, res: Response) => {
const nameResult = await pool.query('SELECT assign_worker_name($1) as name', [finalWorkerId]); const nameResult = await pool.query('SELECT assign_worker_name($1) as name', [finalWorkerId]);
const friendlyName = nameResult.rows[0].name; const friendlyName = nameResult.rows[0].name;
// Register the worker // Register the worker - use friendlyName as pod_name (not K8s name)
const { rows } = await pool.query(` const { rows } = await pool.query(`
INSERT INTO worker_registry ( INSERT INTO worker_registry (
worker_id, friendly_name, role, pod_name, hostname, ip_address, status, metadata worker_id, friendly_name, role, pod_name, hostname, ip_address, status, metadata
) VALUES ($1, $2, $3, $4, $5, $6, 'active', $7) ) VALUES ($1, $2, $3, $4, $5, $6, 'active', $7)
RETURNING id, worker_id, friendly_name, role RETURNING id, worker_id, friendly_name, pod_name, role
`, [finalWorkerId, friendlyName, role, pod_name, finalHostname, clientIp, metadata]); `, [finalWorkerId, friendlyName, role, friendlyName, finalHostname, clientIp, metadata]);
const worker = rows[0]; const worker = rows[0];
const roleMsg = role ? `for ${role}` : 'as role-agnostic'; const roleMsg = role ? `for ${role}` : 'as role-agnostic';

View File

@@ -9,3 +9,4 @@ export { handleProductDiscovery } from './product-discovery';
export { handleStoreDiscovery } from './store-discovery'; export { handleStoreDiscovery } from './store-discovery';
export { handleEntryPointDiscovery } from './entry-point-discovery'; export { handleEntryPointDiscovery } from './entry-point-discovery';
export { handleAnalyticsRefresh } from './analytics-refresh'; export { handleAnalyticsRefresh } from './analytics-refresh';
export { handleProxyTest } from './proxy-test';

View File

@@ -0,0 +1,51 @@
/**
* Proxy Test Handler
* Tests proxy connectivity by fetching public IP via ipify
*/
import { TaskContext, TaskResult } from '../task-worker';
import { execSync } from 'child_process';
export async function handleProxyTest(ctx: TaskContext): Promise<TaskResult> {
const { pool } = ctx;
console.log('[ProxyTest] Testing proxy connection...');
try {
// Get active proxy from DB
const proxyResult = await pool.query(`
SELECT host, port, username, password
FROM proxies
WHERE is_active = true
LIMIT 1
`);
if (proxyResult.rows.length === 0) {
return { success: false, error: 'No active proxy configured' };
}
const p = proxyResult.rows[0];
const proxyUrl = p.username
? `http://${p.username}:${p.password}@${p.host}:${p.port}`
: `http://${p.host}:${p.port}`;
console.log(`[ProxyTest] Using proxy: ${p.host}:${p.port}`);
// Fetch IP via proxy
const cmd = `curl -s --proxy '${proxyUrl}' 'https://api.ipify.org?format=json'`;
const output = execSync(cmd, { timeout: 30000 }).toString().trim();
const data = JSON.parse(output);
console.log(`[ProxyTest] Proxy IP: ${data.ip}`);
return {
success: true,
proxyIp: data.ip,
proxyHost: p.host,
proxyPort: p.port,
};
} catch (error: any) {
console.error('[ProxyTest] Error:', error.message);
return { success: false, error: error.message };
}
}

View File

@@ -31,7 +31,8 @@ export type TaskRole =
| 'product_discovery' | 'product_discovery'
| 'payload_fetch' // NEW: Fetches from API, saves to disk | 'payload_fetch' // NEW: Fetches from API, saves to disk
| 'product_refresh' // CHANGED: Now reads from local payload | 'product_refresh' // CHANGED: Now reads from local payload
| 'analytics_refresh'; | 'analytics_refresh'
| 'proxy_test'; // Tests proxy connectivity via ipify
export type TaskStatus = export type TaskStatus =
| 'pending' | 'pending'

View File

@@ -59,6 +59,7 @@ import { handleProductDiscovery } from './handlers/product-discovery';
import { handleStoreDiscovery } from './handlers/store-discovery'; import { handleStoreDiscovery } from './handlers/store-discovery';
import { handleEntryPointDiscovery } from './handlers/entry-point-discovery'; import { handleEntryPointDiscovery } from './handlers/entry-point-discovery';
import { handleAnalyticsRefresh } from './handlers/analytics-refresh'; import { handleAnalyticsRefresh } from './handlers/analytics-refresh';
import { handleProxyTest } from './handlers/proxy-test';
const POLL_INTERVAL_MS = parseInt(process.env.POLL_INTERVAL_MS || '5000'); const POLL_INTERVAL_MS = parseInt(process.env.POLL_INTERVAL_MS || '5000');
const HEARTBEAT_INTERVAL_MS = parseInt(process.env.HEARTBEAT_INTERVAL_MS || '30000'); const HEARTBEAT_INTERVAL_MS = parseInt(process.env.HEARTBEAT_INTERVAL_MS || '30000');
@@ -84,6 +85,20 @@ const MAX_CONCURRENT_TASKS = parseInt(process.env.MAX_CONCURRENT_TASKS || '3');
// Default 85% - gives headroom before OOM // Default 85% - gives headroom before OOM
const MEMORY_BACKOFF_THRESHOLD = parseFloat(process.env.MEMORY_BACKOFF_THRESHOLD || '0.85'); const MEMORY_BACKOFF_THRESHOLD = parseFloat(process.env.MEMORY_BACKOFF_THRESHOLD || '0.85');
// Parse max heap size from NODE_OPTIONS (--max-old-space-size=1500)
// This is used as the denominator for memory percentage calculation
// V8's heapTotal is dynamic and stays small when idle, causing false high percentages
function getMaxHeapSizeMb(): number {
const nodeOptions = process.env.NODE_OPTIONS || '';
const match = nodeOptions.match(/--max-old-space-size=(\d+)/);
if (match) {
return parseInt(match[1], 10);
}
// Fallback: use 512MB if not specified
return 512;
}
const MAX_HEAP_SIZE_MB = getMaxHeapSizeMb();
// When CPU usage exceeds this threshold (as decimal 0.0-1.0), stop claiming new tasks // When CPU usage exceeds this threshold (as decimal 0.0-1.0), stop claiming new tasks
// Default 90% - allows some burst capacity // Default 90% - allows some burst capacity
const CPU_BACKOFF_THRESHOLD = parseFloat(process.env.CPU_BACKOFF_THRESHOLD || '0.90'); const CPU_BACKOFF_THRESHOLD = parseFloat(process.env.CPU_BACKOFF_THRESHOLD || '0.90');
@@ -119,6 +134,7 @@ const TASK_HANDLERS: Record<TaskRole, TaskHandler> = {
store_discovery: handleStoreDiscovery, store_discovery: handleStoreDiscovery,
entry_point_discovery: handleEntryPointDiscovery, entry_point_discovery: handleEntryPointDiscovery,
analytics_refresh: handleAnalyticsRefresh, analytics_refresh: handleAnalyticsRefresh,
proxy_test: handleProxyTest, // Tests proxy via ipify
}; };
/** /**
@@ -186,12 +202,16 @@ export class TaskWorker {
/** /**
* Get current resource usage * Get current resource usage
* Memory percentage is calculated against MAX_HEAP_SIZE_MB (from --max-old-space-size)
* NOT against V8's dynamic heapTotal which stays small when idle
*/ */
private getResourceStats(): ResourceStats { private getResourceStats(): ResourceStats {
const memUsage = process.memoryUsage(); const memUsage = process.memoryUsage();
const heapUsedMb = memUsage.heapUsed / 1024 / 1024; const heapUsedMb = memUsage.heapUsed / 1024 / 1024;
const heapTotalMb = memUsage.heapTotal / 1024 / 1024; // Use MAX_HEAP_SIZE_MB as ceiling, not dynamic heapTotal
const memoryPercent = heapUsedMb / heapTotalMb; // V8's heapTotal stays small when idle (e.g., 36MB) causing false 95%+ readings
// With --max-old-space-size=1500, we should calculate against 1500MB
const memoryPercent = heapUsedMb / MAX_HEAP_SIZE_MB;
// Calculate CPU usage since last check // Calculate CPU usage since last check
const cpuUsage = process.cpuUsage(); const cpuUsage = process.cpuUsage();
@@ -212,7 +232,7 @@ export class TaskWorker {
return { return {
memoryPercent, memoryPercent,
memoryMb: Math.round(heapUsedMb), memoryMb: Math.round(heapUsedMb),
memoryTotalMb: Math.round(heapTotalMb), memoryTotalMb: MAX_HEAP_SIZE_MB, // Use max-old-space-size, not dynamic heapTotal
cpuPercent: Math.min(100, cpuPercent), // Cap at 100% cpuPercent: Math.min(100, cpuPercent), // Cap at 100%
isBackingOff: this.isBackingOff, isBackingOff: this.isBackingOff,
backoffReason: this.backoffReason, backoffReason: this.backoffReason,

View File

@@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CannaIQ - Cannabis Menu Intelligence Platform</title> <title>CannaIQ - Cannabis Menu Intelligence Platform</title>
<meta name="description" content="CannaIQ provides real-time cannabis dispensary menu data, product tracking, and analytics for dispensaries across Arizona." /> <meta name="description" content="CannaIQ provides real-time cannabis dispensary menu data, product tracking, and analytics for dispensaries across Arizona." />

View File

@@ -0,0 +1,5 @@
<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
<rect width="32" height="32" rx="6" fill="#059669"/>
<path d="M16 6C12.5 6 9.5 7.5 7.5 10L16 16L24.5 10C22.5 7.5 19.5 6 16 6Z" fill="white"/>
<path d="M7.5 10C6 12 5 14.5 5 17C5 22.5 10 26 16 26C22 26 27 22.5 27 17C27 14.5 26 12 24.5 10L16 16L7.5 10Z" fill="white" fill-opacity="0.7"/>
</svg>

After

Width:  |  Height:  |  Size: 360 B

View File

@@ -2,7 +2,6 @@ import { ReactNode, useEffect, useState, useRef } from 'react';
import { useNavigate, useLocation, Link } from 'react-router-dom'; import { useNavigate, useLocation, Link } from 'react-router-dom';
import { useAuthStore } from '../store/authStore'; import { useAuthStore } from '../store/authStore';
import { api } from '../lib/api'; import { api } from '../lib/api';
import { StateSelector } from './StateSelector';
import { import {
LayoutDashboard, LayoutDashboard,
Building2, Building2,
@@ -140,7 +139,7 @@ export function Layout({ children }: LayoutProps) {
<> <>
{/* Logo/Brand */} {/* Logo/Brand */}
<div className="px-6 py-5 border-b border-gray-200"> <div className="px-6 py-5 border-b border-gray-200">
<div className="flex items-center gap-3"> <Link to="/dashboard" className="flex items-center gap-3 hover:opacity-80 transition-opacity">
<div className="w-8 h-8 bg-emerald-600 rounded-lg flex items-center justify-center"> <div className="w-8 h-8 bg-emerald-600 rounded-lg flex items-center justify-center">
<svg viewBox="0 0 24 24" className="w-5 h-5 text-white" fill="currentColor"> <svg viewBox="0 0 24 24" className="w-5 h-5 text-white" fill="currentColor">
<path d="M12 2C8.5 2 5.5 3.5 3.5 6L12 12L20.5 6C18.5 3.5 15.5 2 12 2Z" /> <path d="M12 2C8.5 2 5.5 3.5 3.5 6L12 12L20.5 6C18.5 3.5 15.5 2 12 2Z" />
@@ -155,14 +154,10 @@ export function Layout({ children }: LayoutProps) {
</p> </p>
)} )}
</div> </div>
</div> </Link>
<p className="text-xs text-gray-500 mt-2 truncate">{user?.email}</p> <p className="text-xs text-gray-500 mt-2 truncate">{user?.email}</p>
</div> </div>
{/* State Selector */}
<div className="px-4 py-3 border-b border-gray-200 bg-gray-50">
<StateSelector showLabel={false} />
</div>
{/* Navigation */} {/* Navigation */}
<nav ref={navRef} className="flex-1 px-3 py-4 space-y-6 overflow-y-auto"> <nav ref={navRef} className="flex-1 px-3 py-4 space-y-6 overflow-y-auto">
@@ -233,7 +228,7 @@ export function Layout({ children }: LayoutProps) {
<button onClick={() => setSidebarOpen(true)} className="p-2 -ml-2 rounded-lg hover:bg-gray-100"> <button onClick={() => setSidebarOpen(true)} className="p-2 -ml-2 rounded-lg hover:bg-gray-100">
<Menu className="w-5 h-5 text-gray-600" /> <Menu className="w-5 h-5 text-gray-600" />
</button> </button>
<div className="flex items-center gap-2"> <Link to="/dashboard" className="flex items-center gap-2 hover:opacity-80 transition-opacity">
<div className="w-6 h-6 bg-emerald-600 rounded flex items-center justify-center"> <div className="w-6 h-6 bg-emerald-600 rounded flex items-center justify-center">
<svg viewBox="0 0 24 24" className="w-4 h-4 text-white" fill="currentColor"> <svg viewBox="0 0 24 24" className="w-4 h-4 text-white" fill="currentColor">
<path d="M12 2C8.5 2 5.5 3.5 3.5 6L12 12L20.5 6C18.5 3.5 15.5 2 12 2Z" /> <path d="M12 2C8.5 2 5.5 3.5 3.5 6L12 12L20.5 6C18.5 3.5 15.5 2 12 2Z" />
@@ -241,7 +236,7 @@ export function Layout({ children }: LayoutProps) {
</svg> </svg>
</div> </div>
<span className="font-semibold text-gray-900">CannaIQ</span> <span className="font-semibold text-gray-900">CannaIQ</span>
</div> </Link>
</div> </div>
{/* Page content */} {/* Page content */}

View File

@@ -16,7 +16,6 @@ import {
ChevronRight, ChevronRight,
Gauge, Gauge,
Users, Users,
Play,
Square, Square,
Plus, Plus,
X, X,
@@ -451,7 +450,6 @@ export default function TasksDashboard() {
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [poolPaused, setPoolPaused] = useState(false); const [poolPaused, setPoolPaused] = useState(false);
const [poolLoading, setPoolLoading] = useState(false);
const [showCreateModal, setShowCreateModal] = useState(false); const [showCreateModal, setShowCreateModal] = useState(false);
// Pagination // Pagination
@@ -490,23 +488,6 @@ export default function TasksDashboard() {
} }
}; };
const togglePool = async () => {
setPoolLoading(true);
try {
if (poolPaused) {
await api.resumeTaskPool();
setPoolPaused(false);
} else {
await api.pauseTaskPool();
setPoolPaused(true);
}
} catch (err: any) {
setError(err.message || 'Failed to toggle pool');
} finally {
setPoolLoading(false);
}
};
const handleDeleteTask = async (taskId: number) => { const handleDeleteTask = async (taskId: number) => {
if (!confirm('Delete this task?')) return; if (!confirm('Delete this task?')) return;
try { try {
@@ -579,28 +560,13 @@ export default function TasksDashboard() {
<Plus className="w-4 h-4" /> <Plus className="w-4 h-4" />
Create Task Create Task
</button> </button>
{/* Pool Toggle */} {/* Pool status indicator */}
<button {poolPaused && (
onClick={togglePool} <span className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-sm font-medium bg-yellow-100 text-yellow-800">
disabled={poolLoading} <Square className="w-4 h-4" />
className={`flex items-center gap-2 px-4 py-2 rounded-lg font-medium transition-colors ${ Pool Paused
poolPaused </span>
? 'bg-emerald-100 text-emerald-700 hover:bg-emerald-200'
: 'bg-red-100 text-red-700 hover:bg-red-200'
}`}
>
{poolPaused ? (
<>
<Play className={`w-5 h-5 ${poolLoading ? 'animate-pulse' : ''}`} />
Resume Pool
</>
) : (
<>
<Square className={`w-5 h-5 ${poolLoading ? 'animate-pulse' : ''}`} />
Pause Pool
</>
)} )}
</button>
<span className="text-sm text-gray-400">Auto-refreshes every 15s</span> <span className="text-sm text-gray-400">Auto-refreshes every 15s</span>
</div> </div>
</div> </div>

View File

@@ -369,8 +369,10 @@ function PodVisualization({
const isBusy = worker.current_task_id !== null; const isBusy = worker.current_task_id !== null;
const isDecommissioning = worker.decommission_requested; const isDecommissioning = worker.decommission_requested;
const workerColor = isDecommissioning ? 'bg-orange-500' : isBusy ? 'bg-blue-500' : 'bg-emerald-500'; const isBackingOff = worker.metadata?.is_backing_off;
const workerBorder = isDecommissioning ? 'border-orange-300' : isBusy ? 'border-blue-300' : 'border-emerald-300'; // Color priority: decommissioning > backing off > busy > idle
const workerColor = isDecommissioning ? 'bg-orange-500' : isBackingOff ? 'bg-yellow-500' : isBusy ? 'bg-blue-500' : 'bg-emerald-500';
const workerBorder = isDecommissioning ? 'border-orange-300' : isBackingOff ? 'border-yellow-300' : isBusy ? 'border-blue-300' : 'border-emerald-300';
// Line from center to worker // Line from center to worker
const lineLength = radius - 10; const lineLength = radius - 10;
@@ -381,7 +383,7 @@ function PodVisualization({
<div key={worker.id}> <div key={worker.id}>
{/* Connection line */} {/* Connection line */}
<div <div
className={`absolute w-0.5 ${isDecommissioning ? 'bg-orange-300' : isBusy ? 'bg-blue-300' : 'bg-emerald-300'}`} className={`absolute w-0.5 ${isDecommissioning ? 'bg-orange-300' : isBackingOff ? 'bg-yellow-300' : isBusy ? 'bg-blue-300' : 'bg-emerald-300'}`}
style={{ style={{
height: `${lineLength}px`, height: `${lineLength}px`,
left: '50%', left: '50%',
@@ -398,7 +400,7 @@ function PodVisualization({
top: '50%', top: '50%',
transform: `translate(-50%, -50%) translate(${x}px, ${y}px)`, transform: `translate(-50%, -50%) translate(${x}px, ${y}px)`,
}} }}
title={`${worker.friendly_name}\nStatus: ${isDecommissioning ? 'Stopping after current task' : isBusy ? `Working on task #${worker.current_task_id}` : 'Idle - waiting for tasks'}\nMemory: ${worker.metadata?.memory_mb || 0} MB\nCPU: ${formatCpuTime(worker.metadata?.cpu_user_ms || 0)} user, ${formatCpuTime(worker.metadata?.cpu_system_ms || 0)} sys\nCompleted: ${worker.tasks_completed} | Failed: ${worker.tasks_failed}\nLast heartbeat: ${new Date(worker.last_heartbeat_at).toLocaleTimeString()}`} title={`${worker.friendly_name}\nStatus: ${isDecommissioning ? 'Stopping after current task' : isBackingOff ? `Backing off: ${worker.metadata?.backoff_reason || 'resource pressure'}` : isBusy ? `Working on task #${worker.current_task_id}` : 'Ready - waiting for tasks'}\nMemory: ${worker.metadata?.memory_mb || 0} MB (${worker.metadata?.memory_percent || 0}%)\nCPU: ${formatCpuTime(worker.metadata?.cpu_user_ms || 0)} user, ${formatCpuTime(worker.metadata?.cpu_system_ms || 0)} sys\nCompleted: ${worker.tasks_completed} | Failed: ${worker.tasks_failed}\nLast heartbeat: ${new Date(worker.last_heartbeat_at).toLocaleTimeString()}`}
> >
{index + 1} {index + 1}
</div> </div>
@@ -700,11 +702,11 @@ export function WorkersDashboard() {
Worker Pods ({Array.from(groupWorkersByPod(workers)).length} pods, {activeWorkers.length} workers) Worker Pods ({Array.from(groupWorkersByPod(workers)).length} pods, {activeWorkers.length} workers)
</h3> </h3>
<p className="text-xs text-gray-500 mt-0.5"> <p className="text-xs text-gray-500 mt-0.5">
<span className="inline-flex items-center gap-1"><span className="w-2 h-2 rounded-full bg-emerald-500"></span> idle</span> <span className="inline-flex items-center gap-1"><span className="w-2 h-2 rounded-full bg-emerald-500"></span> ready</span>
<span className="mx-2">|</span> <span className="mx-2">|</span>
<span className="inline-flex items-center gap-1"><span className="w-2 h-2 rounded-full bg-blue-500"></span> busy</span> <span className="inline-flex items-center gap-1"><span className="w-2 h-2 rounded-full bg-blue-500"></span> busy</span>
<span className="mx-2">|</span> <span className="mx-2">|</span>
<span className="inline-flex items-center gap-1"><span className="w-2 h-2 rounded-full bg-yellow-500"></span> mixed</span> <span className="inline-flex items-center gap-1"><span className="w-2 h-2 rounded-full bg-yellow-500"></span> backing off</span>
<span className="mx-2">|</span> <span className="mx-2">|</span>
<span className="inline-flex items-center gap-1"><span className="w-2 h-2 rounded-full bg-orange-500"></span> stopping</span> <span className="inline-flex items-center gap-1"><span className="w-2 h-2 rounded-full bg-orange-500"></span> stopping</span>
</p> </p>

View File

@@ -40,12 +40,16 @@ spec:
valueFrom: valueFrom:
fieldRef: fieldRef:
fieldPath: metadata.name fieldPath: metadata.name
- name: API_BASE_URL
value: "http://scraper"
- name: NODE_OPTIONS
value: "--max-old-space-size=1500"
resources: resources:
requests: requests:
memory: "256Mi" memory: "1Gi"
cpu: "100m" cpu: "100m"
limits: limits:
memory: "512Mi" memory: "2Gi"
cpu: "500m" cpu: "500m"
livenessProbe: livenessProbe:
exec: exec:

View File

@@ -6,6 +6,19 @@ kind: Namespace
metadata: metadata:
name: woodpecker name: woodpecker
--- ---
# PVC for npm cache - shared across CI jobs
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: npm-cache
namespace: woodpecker
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
---
apiVersion: v1 apiVersion: v1
kind: Secret kind: Secret
metadata: metadata:
@@ -52,6 +65,9 @@ spec:
value: "woodpecker" value: "woodpecker"
- name: WOODPECKER_BACKEND_K8S_VOLUME_SIZE - name: WOODPECKER_BACKEND_K8S_VOLUME_SIZE
value: "10G" value: "10G"
# Allow CI steps to mount the npm-cache PVC
- name: WOODPECKER_BACKEND_K8S_VOLUMES
value: "npm-cache:/npm-cache"
resources: resources:
limits: limits:
memory: "512Mi" memory: "512Mi"