@arela/uploader 1.1.4 ā 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/worktrees/agent-multi-profile/.env.template +224 -0
- package/.claude/worktrees/agent-multi-profile/.prettierrc +13 -0
- package/.claude/worktrees/agent-multi-profile/README.md +405 -0
- package/.claude/worktrees/agent-multi-profile/package-lock.json +7096 -0
- package/.claude/worktrees/agent-multi-profile/package.json +78 -0
- package/.claude/worktrees/agent-multi-profile/scripts/cleanup-ds-store.js +109 -0
- package/.claude/worktrees/agent-multi-profile/scripts/cleanup-system-files.js +69 -0
- package/.claude/worktrees/agent-multi-profile/scripts/scoring-compare.js +243 -0
- package/.claude/worktrees/agent-multi-profile/scripts/scoring-phase4-check.js +96 -0
- package/.claude/worktrees/agent-multi-profile/scripts/tests/phase-7-features.test.js +415 -0
- package/.claude/worktrees/agent-multi-profile/scripts/tests/signal-handling.test.js +275 -0
- package/.claude/worktrees/agent-multi-profile/scripts/tests/smart-watch-integration.test.js +554 -0
- package/.claude/worktrees/agent-multi-profile/scripts/tests/watch-service-integration.test.js +584 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/AgentCommand.js +229 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/AgentInitCommand.js +316 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/DatastageCommand.js +164 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/GDriveSyncCommand.js +475 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/IdentifyCommand.js +708 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/PollWorkerCommand.js +169 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/PropagateCommand.js +636 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/PushCommand.js +743 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/ScanCommand.js +722 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/UploadCommand.js +587 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/WatchCommand.js +1342 -0
- package/.claude/worktrees/agent-multi-profile/src/commands/WorkerCommand.js +337 -0
- package/.claude/worktrees/agent-multi-profile/src/config/config.js +862 -0
- package/.claude/worktrees/agent-multi-profile/src/document-type-shared.js +131 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/_pedimento-shared-extractors.js +348 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/doda-pdf.js +121 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/doda-xml.js +118 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/factura-inter-agencia.js +186 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/facturas-comerciales.js +233 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/pedimento-completo-xml.js +372 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/pedimento-completo.js +108 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/pedimento-simplificado.js +76 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/proforma.js +29 -0
- package/.claude/worktrees/agent-multi-profile/src/document-types/support-document.js +200 -0
- package/.claude/worktrees/agent-multi-profile/src/errors/ErrorHandler.js +278 -0
- package/.claude/worktrees/agent-multi-profile/src/errors/ErrorTypes.js +104 -0
- package/.claude/worktrees/agent-multi-profile/src/file-detection.js +338 -0
- package/.claude/worktrees/agent-multi-profile/src/index.js +890 -0
- package/.claude/worktrees/agent-multi-profile/src/scoring/db-matcher-adapter.js +98 -0
- package/.claude/worktrees/agent-multi-profile/src/scoring/matchers-seed.js +386 -0
- package/.claude/worktrees/agent-multi-profile/src/scoring/scoring-engine.js +251 -0
- package/.claude/worktrees/agent-multi-profile/src/services/AdvancedFilterService.js +505 -0
- package/.claude/worktrees/agent-multi-profile/src/services/AutoProcessingService.js +749 -0
- package/.claude/worktrees/agent-multi-profile/src/services/BenchmarkingService.js +381 -0
- package/.claude/worktrees/agent-multi-profile/src/services/DatabaseService.js +2173 -0
- package/.claude/worktrees/agent-multi-profile/src/services/DatastageApiService.js +240 -0
- package/.claude/worktrees/agent-multi-profile/src/services/ErrorMonitor.js +275 -0
- package/.claude/worktrees/agent-multi-profile/src/services/GoogleDriveService.js +217 -0
- package/.claude/worktrees/agent-multi-profile/src/services/LoggingService.js +649 -0
- package/.claude/worktrees/agent-multi-profile/src/services/MonitoringService.js +401 -0
- package/.claude/worktrees/agent-multi-profile/src/services/PerformanceOptimizer.js +511 -0
- package/.claude/worktrees/agent-multi-profile/src/services/PipelineApiService.js +274 -0
- package/.claude/worktrees/agent-multi-profile/src/services/PipelineJobRunner.js +389 -0
- package/.claude/worktrees/agent-multi-profile/src/services/ProfileManager.js +164 -0
- package/.claude/worktrees/agent-multi-profile/src/services/ReportingService.js +511 -0
- package/.claude/worktrees/agent-multi-profile/src/services/ScanApiService.js +775 -0
- package/.claude/worktrees/agent-multi-profile/src/services/SignalHandler.js +255 -0
- package/.claude/worktrees/agent-multi-profile/src/services/SmartWatchDatabaseService.js +527 -0
- package/.claude/worktrees/agent-multi-profile/src/services/WatchService.js +783 -0
- package/.claude/worktrees/agent-multi-profile/src/services/upload/ApiUploadService.js +676 -0
- package/.claude/worktrees/agent-multi-profile/src/services/upload/BaseUploadService.js +36 -0
- package/.claude/worktrees/agent-multi-profile/src/services/upload/MultiApiUploadService.js +233 -0
- package/.claude/worktrees/agent-multi-profile/src/services/upload/SupabaseUploadService.js +148 -0
- package/.claude/worktrees/agent-multi-profile/src/services/upload/UploadServiceFactory.js +100 -0
- package/.claude/worktrees/agent-multi-profile/src/utils/CleanupManager.js +262 -0
- package/.claude/worktrees/agent-multi-profile/src/utils/FileOperations.js +192 -0
- package/.claude/worktrees/agent-multi-profile/src/utils/FileSanitizer.js +99 -0
- package/.claude/worktrees/agent-multi-profile/src/utils/PathDetector.js +198 -0
- package/.claude/worktrees/agent-multi-profile/src/utils/PathNormalizer.js +274 -0
- package/.claude/worktrees/agent-multi-profile/src/utils/WatchEventHandler.js +522 -0
- package/.claude/worktrees/agent-multi-profile/supabase/migrations/001_create_initial_schema.sql +366 -0
- package/.claude/worktrees/agent-multi-profile/supabase/migrations/002_align_with_arela_api_schema.sql +145 -0
- package/.claude/worktrees/agent-multi-profile/tests/commands/IdentifyCommand.test.js +570 -0
- package/.claude/worktrees/agent-multi-profile/tests/commands/PropagateCommand.test.js +568 -0
- package/.claude/worktrees/agent-multi-profile/tests/commands/PushCommand.test.js +754 -0
- package/.claude/worktrees/agent-multi-profile/tests/commands/ScanCommand.test.js +382 -0
- package/.claude/worktrees/agent-multi-profile/tests/unit/PathAndTableNameGeneration.test.js +1211 -0
- package/.claude/worktrees/agent-multi-profile/tests/unit/factura-inter-agencia.test.js +218 -0
- package/.claude/worktrees/agent-multi-profile/tests/unit/pedimento-completo-xml-matcher.test.js +271 -0
- package/.claude/worktrees/agent-multi-profile/tests/unit/pedimento-simplificado-matcher.test.js +185 -0
- package/.claude/worktrees/agent-multi-profile/tests/unit/scoring-engine.test.js +221 -0
- package/README.md +65 -0
- package/package.json +1 -1
- package/src/commands/AgentCommand.js +210 -0
- package/src/commands/AgentInitCommand.js +316 -0
- package/src/commands/PollWorkerCommand.js +11 -322
- package/src/config/config.js +44 -6
- package/src/index.js +55 -0
- package/src/services/LoggingService.js +35 -0
- package/src/services/PipelineApiService.js +7 -1
- package/src/services/PipelineJobRunner.js +389 -0
- package/src/services/ProfileManager.js +164 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import logger from '../services/LoggingService.js';
|
|
2
|
+
import { PipelineApiService } from '../services/PipelineApiService.js';
|
|
3
|
+
import { PipelineJobRunner } from '../services/PipelineJobRunner.js';
|
|
4
|
+
|
|
5
|
+
import appConfig from '../config/config.js';
|
|
6
|
+
import ErrorHandler from '../errors/ErrorHandler.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Poll Worker Command Handler
|
|
10
|
+
* Runs arela-uploader as an HTTP-polling worker, fetching jobs from the API.
|
|
11
|
+
* Alternative to BullMQ/Redis-based worker for environments without Redis access.
|
|
12
|
+
* Job execution lives in PipelineJobRunner (shared with `arela agent`).
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* arela worker --poll
|
|
16
|
+
* arela worker --poll --interval 10000
|
|
17
|
+
*
|
|
18
|
+
* Environment variables:
|
|
19
|
+
* WORKER_POLL_INTERVAL - Polling interval in ms (default: 5000)
|
|
20
|
+
* WORKER_POLL_API_TARGET - API target for polling (default: 'agencia')
|
|
21
|
+
* ARELA_SERVER_ID - Server identifier for job assignment
|
|
22
|
+
*/
|
|
23
|
+
export class PollWorkerCommand {
|
|
24
|
+
constructor() {
|
|
25
|
+
this.errorHandler = new ErrorHandler(logger);
|
|
26
|
+
this.isShuttingDown = false;
|
|
27
|
+
this.currentJob = null;
|
|
28
|
+
this.pipelineApi = null;
|
|
29
|
+
this.jobRunner = null;
|
|
30
|
+
this.pollTimer = null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Execute the poll worker command
|
|
35
|
+
* @param {Object} options - Command options
|
|
36
|
+
* @param {number} options.interval - Polling interval in milliseconds
|
|
37
|
+
* @param {string} options.api - API target for polling
|
|
38
|
+
*/
|
|
39
|
+
async execute(options = {}) {
|
|
40
|
+
try {
|
|
41
|
+
const workerConfig = appConfig.getWorkerConfig();
|
|
42
|
+
const pollConfig = workerConfig.poll;
|
|
43
|
+
|
|
44
|
+
// Get configuration
|
|
45
|
+
const interval = parseInt(options.interval) || pollConfig.interval;
|
|
46
|
+
const apiTarget = options.api || pollConfig.apiTarget;
|
|
47
|
+
const serverId = appConfig.getServerId();
|
|
48
|
+
|
|
49
|
+
if (!serverId) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
'ARELA_SERVER_ID is required for poll mode. Set it in your .env file.',
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.serverId = serverId;
|
|
56
|
+
|
|
57
|
+
// Initialize Pipeline API service and the shared job runner
|
|
58
|
+
this.pipelineApi = new PipelineApiService(apiTarget);
|
|
59
|
+
this.jobRunner = new PipelineJobRunner(this.pipelineApi, serverId);
|
|
60
|
+
|
|
61
|
+
console.log('\nš§ Starting Arela Poll Worker');
|
|
62
|
+
console.log(`š” API Target: ${apiTarget}`);
|
|
63
|
+
console.log(`š„ļø Server ID: ${serverId}`);
|
|
64
|
+
console.log(`ā±ļø Poll Interval: ${interval}ms`);
|
|
65
|
+
|
|
66
|
+
logger.info('š§ Starting Arela Poll Worker');
|
|
67
|
+
logger.info(`š” API Target: ${apiTarget}`);
|
|
68
|
+
logger.info(`š„ļø Server ID: ${serverId}`);
|
|
69
|
+
logger.info(`ā±ļø Poll Interval: ${interval}ms`);
|
|
70
|
+
|
|
71
|
+
// Setup graceful shutdown handlers
|
|
72
|
+
this.#setupShutdownHandlers();
|
|
73
|
+
|
|
74
|
+
// Start polling loop
|
|
75
|
+
await this.#startPolling(serverId, interval);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
logger.error('ā Poll Worker failed to start:', error.message);
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Start the polling loop
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
async #startPolling(serverId, interval) {
|
|
87
|
+
console.log('\nā
Poll Worker is running. Press Ctrl+C to stop.\n');
|
|
88
|
+
logger.success('Poll Worker is running');
|
|
89
|
+
|
|
90
|
+
while (!this.isShuttingDown) {
|
|
91
|
+
try {
|
|
92
|
+
// Check for next job
|
|
93
|
+
const job = await this.pipelineApi.getNextJob(serverId);
|
|
94
|
+
|
|
95
|
+
if (job && job.id) {
|
|
96
|
+
console.log(`š„ Got job: ${job.type} for RFC ${job.rfc}`);
|
|
97
|
+
logger.info(`š„ Got job: ${job.id} - ${job.type} for RFC ${job.rfc}`);
|
|
98
|
+
this.currentJob = job;
|
|
99
|
+
try {
|
|
100
|
+
await this.jobRunner.processJob(job);
|
|
101
|
+
} finally {
|
|
102
|
+
this.currentJob = null;
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
// Only log to file, not console (too noisy)
|
|
106
|
+
logger.debug('š No jobs available, waiting...');
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error(`ā Polling error: ${error.message}`);
|
|
110
|
+
logger.error(`ā Polling error: ${error.message}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Wait for next poll (unless shutting down)
|
|
114
|
+
if (!this.isShuttingDown) {
|
|
115
|
+
await this.#sleep(interval);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Sleep for specified milliseconds
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
#sleep(ms) {
|
|
125
|
+
return new Promise((resolve) => {
|
|
126
|
+
this.pollTimer = setTimeout(resolve, ms);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Setup graceful shutdown handlers
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
134
|
+
#setupShutdownHandlers() {
|
|
135
|
+
const shutdown = async (signal) => {
|
|
136
|
+
if (this.isShuttingDown) return;
|
|
137
|
+
this.isShuttingDown = true;
|
|
138
|
+
|
|
139
|
+
logger.info(`\nš Received ${signal}. Shutting down poll worker...`);
|
|
140
|
+
|
|
141
|
+
// Clear poll timer
|
|
142
|
+
if (this.pollTimer) {
|
|
143
|
+
clearTimeout(this.pollTimer);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Wait for current job to finish if any
|
|
147
|
+
if (this.currentJob) {
|
|
148
|
+
logger.info(
|
|
149
|
+
` ā³ Waiting for current job to finish: ${this.currentJob.id}`,
|
|
150
|
+
);
|
|
151
|
+
// Give it a moment to complete
|
|
152
|
+
await this.#sleep(2000);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Cleanup
|
|
156
|
+
if (this.pipelineApi) {
|
|
157
|
+
this.pipelineApi.destroy();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
logger.info('ā
Poll worker stopped gracefully');
|
|
161
|
+
process.exit(0);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
165
|
+
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export default new PollWorkerCommand();
|