Skip to content

Commit f80fec9

Browse files
authored
Fix scheduler readme and hints (#130)
* fix scheduler readme and hints * undo -u= * gracefully handle 202 response * refactor the scheduler endpoint input
1 parent 4f65458 commit f80fec9

9 files changed

Lines changed: 39 additions & 16 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,11 @@ DESCRIPTION
596596
Create a new scheduler job for an app
597597
598598
EXAMPLES
599-
$ mapps scheduler:create -a APP_ID -s "0 * * * *" -u "/my-endpoint"
599+
$ mapps scheduler:create -a APP_ID -s "0 * * * *" -u "my-endpoint"
600600
601-
$ mapps scheduler:create -a APP_ID -s "0 * * * *" -u "/my-endpoint" -n "My-special-job" -d "My description"
601+
$ mapps scheduler:create -a APP_ID -s "0 * * * *" -u "my-endpoint" -n "My-special-job" -d "My description"
602602
603-
$ mapps scheduler:create -a APP_ID -s "0 * * * *" -u "/my-endpoint" -r 3 -b 10 -t 60
603+
$ mapps scheduler:create -a APP_ID -s "0 * * * *" -u "my-endpoint" -r 3 -b 10 -t 60
604604
```
605605

606606
_See code: [src/commands/scheduler/create.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/scheduler/create.ts)_
@@ -714,7 +714,7 @@ DESCRIPTION
714714
EXAMPLES
715715
$ mapps scheduler:update -a APP_ID -n "my-job" -s "0 * * * *"
716716
717-
$ mapps scheduler:update -a APP_ID -n "my-job" -u "/my-endpoint"
717+
$ mapps scheduler:update -a APP_ID -n "my-job" -u "my-endpoint"
718718
719719
$ mapps scheduler:update -a APP_ID -n "my-job" -d "My description" -r 3 -b 10 -t 60
720720
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mondaycom/apps-cli",
3-
"version": "4.7.3",
3+
"version": "4.7.4",
44
"description": "A cli tool to manage apps (and monday-code projects) in monday.com",
55
"author": "monday.com Apps Team",
66
"type": "module",

src/commands/scheduler/create.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import { SchedulerService } from 'src/services/scheduler-service';
77
import { printJobs, validateCronExpression, validateTargetUrl } from 'src/services/scheduler-service.utils';
88
import logger from 'src/utils/logger';
99
import { chooseRegionIfNeeded, getRegionFromString } from 'src/utils/region';
10+
import { addPrefixIfNotExists } from 'src/utils/urls-builder';
1011
import { isDefined } from 'src/utils/validations';
1112

1213
export default class SchedulerCreate extends AuthenticatedCommand {
1314
static description = 'Create a new scheduler job for an app';
1415
static examples = [
15-
'<%= config.bin %> <%= command.id %> -a APP_ID -s "0 * * * *" -u "/my-endpoint"',
16-
'<%= config.bin %> <%= command.id %> -a APP_ID -s "0 * * * *" -u "/my-endpoint" -n "My-special-job" -d "My description"',
17-
'<%= config.bin %> <%= command.id %> -a APP_ID -s "0 * * * *" -u "/my-endpoint" -r 3 -b 10 -t 60',
16+
'<%= config.bin %> <%= command.id %> -a APP_ID -s "0 * * * *" -u "my-endpoint"',
17+
'<%= config.bin %> <%= command.id %> -a APP_ID -s "0 * * * *" -u "my-endpoint" -n "My-special-job" -d "My description"',
18+
'<%= config.bin %> <%= command.id %> -a APP_ID -s "0 * * * *" -u "my-endpoint" -r 3 -b 10 -t 60',
1819
];
1920

2021
static flags = SchedulerCreate.serializeFlags(SchedulerFlags);
@@ -33,6 +34,7 @@ export default class SchedulerCreate extends AuthenticatedCommand {
3334
if (!schedule) schedule = await PromptService.promptInput(SchedulerMessages.schedule, true);
3435
validateCronExpression(schedule);
3536
if (!targetUrl) targetUrl = await PromptService.promptInput(SchedulerMessages.targetUrl, true);
37+
targetUrl = addPrefixIfNotExists(targetUrl, '/');
3638
validateTargetUrl(targetUrl);
3739
if (!description) description = await PromptService.promptInput(SchedulerMessages.description, false, true);
3840
if (!maxRetries) maxRetries = await PromptService.promptInputNumber(SchedulerMessages.maxRetries, false, true);

src/commands/scheduler/update.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import { printJobs, validateCronExpression, validateTargetUrl } from 'src/servic
88
import { UpdateJobRequest } from 'src/types/services/scheduler-service';
99
import logger from 'src/utils/logger';
1010
import { chooseRegionIfNeeded, getRegionFromString } from 'src/utils/region';
11+
import { addPrefixIfNotExists } from 'src/utils/urls-builder';
1112
import { isDefined, isDefinedAndNotEmpty } from 'src/utils/validations';
1213

1314
export default class SchedulerUpdate extends AuthenticatedCommand {
1415
static description = 'Update a scheduler job for an app';
1516
static examples = [
1617
'<%= config.bin %> <%= command.id %> -a APP_ID -n "my-job" -s "0 * * * *"',
17-
'<%= config.bin %> <%= command.id %> -a APP_ID -n "my-job" -u "/my-endpoint"',
18+
'<%= config.bin %> <%= command.id %> -a APP_ID -n "my-job" -u "my-endpoint"',
1819
'<%= config.bin %> <%= command.id %> -a APP_ID -n "my-job" -d "My description" -r 3 -b 10 -t 60',
1920
];
2021

@@ -45,6 +46,7 @@ export default class SchedulerUpdate extends AuthenticatedCommand {
4546
if (!schedule) schedule = await PromptService.promptInput(SchedulerMessages.schedule, false, true);
4647
if (schedule) validateCronExpression(schedule);
4748
if (!targetUrl) targetUrl = await PromptService.promptInput(SchedulerMessages.targetUrl, false, true);
49+
targetUrl = addPrefixIfNotExists(targetUrl, '/');
4850
if (targetUrl) validateTargetUrl(targetUrl);
4951
if (!maxRetries) maxRetries = await PromptService.promptInputNumber(SchedulerMessages.maxRetries, false, true);
5052
if (!minBackoffDuration)

src/commands/storage/remove-data.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const MESSAGES = {
1616
force: 'Skip the confirmation step',
1717
operationAborted: 'Operation aborted',
1818
removingData: 'Removing data...',
19+
operationAccepted: 'We got your request, it will take a few minutes to complete',
20+
operationSuccess: 'Operation completed successfully',
1921
};
2022

2123
export default class RemoveData extends AuthenticatedCommand {
@@ -61,7 +63,13 @@ export default class RemoveData extends AuthenticatedCommand {
6163
}
6264

6365
logger.log(MESSAGES.removingData);
64-
await removeAppStorageDataForAccount(appId, clientAccountId);
66+
const response = await removeAppStorageDataForAccount(appId, clientAccountId);
67+
68+
if (response.statusCode === 202) {
69+
logger.log(MESSAGES.operationAccepted);
70+
} else {
71+
logger.log(MESSAGES.operationSuccess);
72+
}
6573

6674
this.preparePrintCommand(this, { appId, clientAccountId, force });
6775
} catch (error: unknown) {

src/consts/scheduler/messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const SchedulerMessages = {
55
name: 'Scheduled job name (no whitespace)',
66
description: 'Scheduled job description (optional)',
77
schedule: 'Cron expression for the job schedule (relative to UTC)',
8-
targetUrl: 'Target URL path for the job (must start with /, will be relative to /mndy-cronjob)',
8+
targetUrl: 'Target URL path for the job endpoint (will be relative to /mndy-cronjob/<YOUR_ENDPOINT>)',
99
maxRetries: 'Maximum number of retries for failed jobs (optional)',
1010
minBackoffDuration: 'Minimum backoff duration in seconds between retries (optional)',
1111
timeout: 'Job execution timeout in seconds (optional)',

src/services/api-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export async function execute<T extends BaseResponseHttpMetaData>(
9999
});
100100

101101
logger.debug({ res: response }, DEBUG_TAG);
102-
const result = { ...response.data, statusCode: 200, headers: response.headers };
102+
const result = { ...response.data, statusCode: response?.status || 200, headers: response.headers };
103103
const validatedResult = validateResponseIfError(result, schemaValidator);
104104
return (validatedResult as T) || result;
105105
} catch (error: any | Error | AxiosError) {

src/services/apps-service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { getTunnelingDomain } from 'services/tunnel-service';
1212
import { AppCreateCommandTasksContext } from 'types/commands/app-create';
1313
import { HttpError } from 'types/errors';
1414
import { AccountId, AppId } from 'types/general';
15-
import { HttpMethodTypes } from 'types/services/api-service';
15+
import { BaseResponseHttpMetaData, HttpMethodTypes } from 'types/services/api-service';
1616
import { App, CreateAppResponse, ListAppResponse } from 'types/services/apps-service';
1717
import { appsUrlBuilder } from 'utils/urls-builder';
1818

@@ -107,11 +107,14 @@ export const checkIfAppSupportMultiRegion = async (appId: number): Promise<boole
107107
return Boolean(app.mondayCodeConfig?.isMultiRegion);
108108
};
109109

110-
export const removeAppStorageDataForAccount = async (appId: AppId, targetAccountId: AccountId): Promise<void> => {
110+
export const removeAppStorageDataForAccount = async <T extends BaseResponseHttpMetaData>(
111+
appId: AppId,
112+
targetAccountId: AccountId,
113+
): Promise<T> => {
111114
try {
112115
const path = removeAppStorageDataForAccountUrl(appId, targetAccountId);
113116
const url = appsUrlBuilder(path);
114-
await execute(
117+
return await execute<T>(
115118
{
116119
url,
117120
headers: { Accept: 'application/json' },

src/utils/urls-builder.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,12 @@ const getLastParam = (url: string): string => {
1010
return url.split('/').pop() || url;
1111
};
1212

13-
export { appsUrlBuilder, getLastParam };
13+
const addPrefixIfNotExists = (url: string, prefix: string): string => {
14+
if (url.startsWith(prefix)) {
15+
return url;
16+
}
17+
18+
return `${prefix}${url}`;
19+
};
20+
21+
export { addPrefixIfNotExists, appsUrlBuilder, getLastParam };

0 commit comments

Comments
 (0)