1
+ export default {
2
+ async scheduled ( event , env , ctx ) {
3
+ try {
4
+ const WEBHOOK_URL = env . CIRCLECI_WEBHOOK_URL ;
5
+ const response = await fetch ( WEBHOOK_URL , {
6
+ method : 'POST' ,
7
+ headers : {
8
+ 'Content-Type' : 'application/json' ,
9
+ } ,
10
+ } ) ;
11
+
12
+ const timestamp = new Date ( ) . toISOString ( ) ;
13
+ console . log ( `[${ timestamp } ] Scheduled request executed` ) ;
14
+ console . log ( `Response status: ${ response . status } ` ) ;
15
+
16
+ if ( ! response . ok ) {
17
+ const errorText = await response . text ( ) ;
18
+ console . error ( `HTTP error! status: ${ response . status } , body: ${ errorText } ` ) ;
19
+ } else {
20
+ const result = await response . text ( ) ;
21
+ console . log ( 'Response body:' , result ) ;
22
+ }
23
+
24
+ } catch ( error ) {
25
+ console . error ( 'Scheduled request failed:' , error ) ;
26
+ }
27
+ } ,
28
+
29
+ // async fetch(request, env, ctx) {
30
+ // // Test endpoint
31
+ // if (request.url.includes('/test')) {
32
+ // try {
33
+ // const WEBHOOK_URL = env.CIRCLECI_WEBHOOK_URL;
34
+ // const response = await fetch(WEBHOOK_URL, {
35
+ // method: 'POST',
36
+ // headers: {
37
+ // 'Content-Type': 'application/json',
38
+ // },
39
+ // });
40
+
41
+ // const responseText = await response.text();
42
+
43
+ // return new Response(`Test request completed. Status: ${response.status}\nResponse: ${responseText}`, {
44
+ // status: 200,
45
+ // headers: { 'Content-Type': 'text/plain' }
46
+ // });
47
+ // } catch (error) {
48
+ // return new Response(`Test failed: ${error.message}`, {
49
+ // status: 500,
50
+ // headers: { 'Content-Type': 'text/plain' }
51
+ // });
52
+ // }
53
+ // }
54
+
55
+ // return new Response('CircleCI Scheduler Worker is running', {
56
+ // status: 200,
57
+ // headers: { 'Content-Type': 'text/plain' }
58
+ // });
59
+ // }
60
+ } ;
0 commit comments