-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomplete-workflow.ts
More file actions
82 lines (69 loc) · 2.32 KB
/
complete-workflow.ts
File metadata and controls
82 lines (69 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* Complete Workflow Example
* Demonstrates a real-world use case combining multiple features:
* - Data extraction with pagination
* - Scheduling
* - Webhooks
*/
import 'dotenv/config';
import { Extract } from 'maxun-sdk';
async function completeWorkflowExample() {
console.log('=== Complete Workflow Example ===\n');
const extractor = new Extract({
apiKey: process.env.MAXUN_API_KEY!,
baseUrl: process.env.MAXUN_BASE_URL
});
try {
console.log('Creating full extraction robot...');
const robot = await extractor
.create('Trending Books Daily')
.navigate('https://openlibrary.org/trending/daily')
.captureList({
selector: 'li.searchResultItem.sri--w-main',
pagination: {
type: 'clickNext',
selector: 'a[data-ol-link-track="Pager|Next"]'
},
maxItems: 25
});
console.log(`✓ Robot created: ${robot.id}\n`);
console.log('Setting up webhook for notifications...');
await robot.addWebhook({
url: 'https://your-webhook-endpoint.com/notifications',
events: ['run.completed', 'run.failed']
});
console.log('✓ Webhook configured\n');
console.log('Scheduling robot to run every 10 minutes...');
await robot.schedule({
runEvery: 1,
runEveryUnit: 'DAYS',
timezone: 'UTC'
});
console.log('✓ Robot scheduled\n');
console.log('Robot Configuration Summary:');
console.log(` Name: ${robot.name}`);
console.log(` ID: ${robot.id}`);
const schedule = robot.getSchedule();
console.log(` Schedule: Every ${schedule?.runEvery} ${schedule?.runEveryUnit}`);
const webhooks = robot.getWebhooks();
console.log(` Webhooks: ${webhooks?.length || 0} configured`);
console.log();
console.log('Fetching execution history...');
const runs = await robot.getRuns();
console.log(`✓ Found ${runs.length} runs:`);
runs.slice(0, 5).forEach((run, i) => {
console.log(` ${i + 1}. ${run.runId} - ${run.status} - ${run.startedAt}`);
});
} catch (error: any) {
console.error('Error:', error.message);
if (error.details) {
console.error('Details:', error.details);
}
}
}
// Run the example
if (!process.env.MAXUN_API_KEY) {
console.error('Please set MAXUN_API_KEY environment variable');
process.exit(1);
}
completeWorkflowExample();