@@ -28,65 +28,61 @@ export default class SchedulerUpdate extends AuthenticatedCommand {
2828 let { appId, name, description, schedule, targetUrl, maxRetries, minBackoffDuration, timeout } = flags ;
2929 const { region } = flags ;
3030 const parsedRegion = getRegionFromString ( region ) ;
31- try {
32- if ( ! appId ) appId = await DynamicChoicesService . chooseApp ( ) ;
33- const selectedRegion = await chooseRegionIfNeeded ( parsedRegion , { appId } ) ;
34- if ( ! name ) name = await DynamicChoicesService . chooseSchedulerJob ( appId , selectedRegion ) ;
3531
36- // Get the current job details
37- const jobs = await SchedulerService . listJobs ( appId , selectedRegion ) ;
38- const currentJob = jobs . find ( job => job . name === name ) ;
39- if ( ! currentJob ) {
40- throw new Error ( `Job ${ name } not found` ) ;
41- }
32+ if ( ! appId ) appId = await DynamicChoicesService . chooseApp ( ) ;
33+ const selectedRegion = await chooseRegionIfNeeded ( parsedRegion , { appId } ) ;
34+ if ( ! name ) name = await DynamicChoicesService . chooseSchedulerJob ( appId , selectedRegion ) ;
4235
43- logger . info ( `All parameters are optional, press enter to skip` ) ;
44- // Only prompt for fields that weren't provided in flags
45- if ( ! description ) description = await PromptService . promptInput ( SchedulerMessages . description , false , true ) ;
46- if ( ! schedule ) schedule = await PromptService . promptInput ( SchedulerMessages . schedule , false , true ) ;
47- if ( schedule ) validateCronExpression ( schedule ) ;
48- if ( ! targetUrl ) targetUrl = await PromptService . promptInput ( SchedulerMessages . targetUrl , false , true ) ;
49- targetUrl = addPrefixIfNotExists ( targetUrl , '/' ) ;
50- if ( targetUrl ) validateTargetUrl ( targetUrl ) ;
51- if ( ! maxRetries ) maxRetries = await PromptService . promptInputNumber ( SchedulerMessages . maxRetries , false , true ) ;
52- if ( ! minBackoffDuration )
53- minBackoffDuration = await PromptService . promptInputNumber ( SchedulerMessages . minBackoffDuration , false , true ) ;
54- if ( ! timeout ) timeout = await PromptService . promptInputNumber ( SchedulerMessages . timeout , false , true ) ;
36+ // Get the current job details
37+ const jobs = await SchedulerService . listJobs ( appId , selectedRegion ) ;
38+ const currentJob = jobs . find ( job => job . name === name ) ;
39+ if ( ! currentJob ) {
40+ throw new Error ( `Job ${ name } not found` ) ;
41+ }
42+
43+ logger . info ( `All parameters are optional, press enter to skip` ) ;
44+ // Only prompt for fields that weren't provided in flags
45+ if ( ! description ) description = await PromptService . promptInput ( SchedulerMessages . description , false , true ) ;
46+ if ( ! schedule ) schedule = await PromptService . promptInput ( SchedulerMessages . schedule , false , true ) ;
47+ if ( schedule ) validateCronExpression ( schedule ) ;
48+ if ( ! targetUrl ) targetUrl = await PromptService . promptInput ( SchedulerMessages . targetUrl , false , true ) ;
49+ targetUrl = addPrefixIfNotExists ( targetUrl , '/' ) ;
50+ if ( targetUrl ) validateTargetUrl ( targetUrl ) ;
51+ if ( ! maxRetries ) maxRetries = await PromptService . promptInputNumber ( SchedulerMessages . maxRetries , false , true ) ;
52+ if ( ! minBackoffDuration )
53+ minBackoffDuration = await PromptService . promptInputNumber ( SchedulerMessages . minBackoffDuration , false , true ) ;
54+ if ( ! timeout ) timeout = await PromptService . promptInputNumber ( SchedulerMessages . timeout , false , true ) ;
5555
56- logger . debug ( `Updating scheduler job ${ name } for appId: ${ appId } ` , this . DEBUG_TAG ) ;
57- this . preparePrintCommand ( this , {
58- appId,
59- name,
60- description,
61- schedule,
62- targetUrl,
63- maxRetries,
64- minBackoffDuration,
65- timeout,
66- region : selectedRegion ,
67- } ) ;
56+ logger . debug ( `Updating scheduler job ${ name } for appId: ${ appId } ` , this . DEBUG_TAG ) ;
57+ this . preparePrintCommand ( this , {
58+ appId,
59+ name,
60+ description,
61+ schedule,
62+ targetUrl,
63+ maxRetries,
64+ minBackoffDuration,
65+ timeout,
66+ region : selectedRegion ,
67+ } ) ;
6868
69- // Create update payload with only the fields that were provided
70- const updatePayload : UpdateJobRequest = { } ;
71- if ( isDefinedAndNotEmpty ( description ) ) updatePayload . description = description ;
72- if ( isDefinedAndNotEmpty ( schedule ) ) updatePayload . schedule = schedule ;
73- if ( isDefinedAndNotEmpty ( targetUrl ) ) updatePayload . targetUrl = targetUrl ;
74- if ( isDefined ( maxRetries ) || isDefined ( minBackoffDuration ) ) {
75- updatePayload . retryConfig = { maxRetries, minBackoffDuration } ;
76- }
69+ // Create update payload with only the fields that were provided
70+ const updatePayload : UpdateJobRequest = { } ;
71+ if ( isDefinedAndNotEmpty ( description ) ) updatePayload . description = description ;
72+ if ( isDefinedAndNotEmpty ( schedule ) ) updatePayload . schedule = schedule ;
73+ if ( isDefinedAndNotEmpty ( targetUrl ) ) updatePayload . targetUrl = targetUrl ;
74+ if ( isDefined ( maxRetries ) || isDefined ( minBackoffDuration ) ) {
75+ updatePayload . retryConfig = { maxRetries, minBackoffDuration } ;
76+ }
7777
78- if ( isDefined ( timeout ) ) updatePayload . timeout = timeout ;
78+ if ( isDefined ( timeout ) ) updatePayload . timeout = timeout ;
7979
80- if ( isDefinedAndNotEmpty ( updatePayload ) ) {
81- const job = await SchedulerService . updateJob ( appId , name , updatePayload , selectedRegion ) ;
82- printJobs ( [ job ] ) ;
83- logger . info ( `Successfully updated job: ${ name } ` ) ;
84- } else {
85- logger . info ( `No changes to update for job: ${ name } ` ) ;
86- }
87- } catch ( error : any ) {
88- logger . debug ( error , this . DEBUG_TAG ) ;
89- process . exit ( 1 ) ;
80+ if ( isDefinedAndNotEmpty ( updatePayload ) ) {
81+ const job = await SchedulerService . updateJob ( appId , name , updatePayload , selectedRegion ) ;
82+ printJobs ( [ job ] ) ;
83+ logger . info ( `Successfully updated job: ${ name } ` ) ;
84+ } else {
85+ logger . info ( `No changes to update for job: ${ name } ` ) ;
9086 }
9187 }
9288}
0 commit comments