@@ -30,42 +30,47 @@ export class CronJobService {
30
30
const batchApi = this . clusterService . makeBatchV1Api ( region )
31
31
const name = `cron-${ trigger . id } `
32
32
const command = await this . getTriggerCommand ( trigger )
33
- const res = await batchApi . createNamespacedCronJob ( ns , {
34
- metadata : {
35
- name,
36
- labels : {
37
- appid,
38
- id : trigger . id ,
33
+ const res = await batchApi
34
+ . createNamespacedCronJob ( ns , {
35
+ metadata : {
36
+ name,
37
+ labels : {
38
+ appid,
39
+ id : trigger . id ,
40
+ } ,
39
41
} ,
40
- } ,
41
- spec : {
42
- schedule : trigger . cron ,
43
- successfulJobsHistoryLimit : 1 ,
44
- failedJobsHistoryLimit : 1 ,
45
- concurrencyPolicy : 'Allow' ,
46
- startingDeadlineSeconds : 60 ,
47
- jobTemplate : {
48
- spec : {
49
- activeDeadlineSeconds : 60 ,
50
- template : {
51
- spec : {
52
- restartPolicy : 'Never' ,
53
- terminationGracePeriodSeconds : 30 ,
54
- automountServiceAccountToken : false ,
55
- containers : [
56
- {
57
- name : name ,
58
- image : 'curlimages/curl:7.87.0' ,
59
- command : [ 'sh' , '-c' , command ] ,
60
- imagePullPolicy : 'IfNotPresent' ,
61
- } ,
62
- ] ,
42
+ spec : {
43
+ schedule : trigger . cron ,
44
+ successfulJobsHistoryLimit : 1 ,
45
+ failedJobsHistoryLimit : 1 ,
46
+ concurrencyPolicy : 'Allow' ,
47
+ startingDeadlineSeconds : 60 ,
48
+ jobTemplate : {
49
+ spec : {
50
+ activeDeadlineSeconds : 60 ,
51
+ template : {
52
+ spec : {
53
+ restartPolicy : 'Never' ,
54
+ terminationGracePeriodSeconds : 30 ,
55
+ automountServiceAccountToken : false ,
56
+ containers : [
57
+ {
58
+ name : name ,
59
+ image : 'curlimages/curl:7.87.0' ,
60
+ command : [ 'sh' , '-c' , command ] ,
61
+ imagePullPolicy : 'IfNotPresent' ,
62
+ } ,
63
+ ] ,
64
+ } ,
63
65
} ,
64
66
} ,
65
67
} ,
66
68
} ,
67
- } ,
68
- } )
69
+ } )
70
+ . catch ( ( err ) => {
71
+ this . logger . error ( `create cronjob ${ name } failed:` , err )
72
+ return null
73
+ } )
69
74
70
75
this . logger . debug ( `create cronjob ${ name } success` )
71
76
return res . body
@@ -77,7 +82,10 @@ export class CronJobService {
77
82
const region = await this . regionService . findByAppId ( appid )
78
83
const batchApi = this . clusterService . makeBatchV1Api ( region )
79
84
const name = `cron-${ trigger . id } `
80
- const res = await batchApi . readNamespacedCronJob ( name , ns )
85
+ const res = await batchApi . readNamespacedCronJob ( name , ns ) . catch ( ( err ) => {
86
+ this . logger . error ( `read cronjob ${ name } failed:` , err )
87
+ return null
88
+ } )
81
89
return res . body
82
90
}
83
91
@@ -87,7 +95,12 @@ export class CronJobService {
87
95
const region = await this . regionService . findByAppId ( appid )
88
96
const batchApi = this . clusterService . makeBatchV1Api ( region )
89
97
const name = `cron-${ trigger . id } `
90
- const res = await batchApi . deleteNamespacedCronJob ( name , ns )
98
+ const res = await batchApi
99
+ . deleteNamespacedCronJob ( name , ns )
100
+ . catch ( ( err ) => {
101
+ this . logger . error ( `delete cronjob ${ name } failed:` , err )
102
+ return null
103
+ } )
91
104
return res . body
92
105
}
93
106
0 commit comments