-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathrm.ts
71 lines (56 loc) · 1.75 KB
/
rm.ts
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
import { ACTOR_JOB_STATUSES } from '@apify/consts';
import { Args } from '@oclif/core';
import type { ApifyApiError } from 'apify-client';
import { ApifyCommand } from '../../lib/apify_command.js';
import { confirmAction } from '../../lib/commands/confirm.js';
import { error, info, success } from '../../lib/outputs.js';
import { getLoggedClientOrThrow } from '../../lib/utils.js';
const deletableStatuses = [
ACTOR_JOB_STATUSES.SUCCEEDED,
ACTOR_JOB_STATUSES.FAILED,
ACTOR_JOB_STATUSES.ABORTED,
ACTOR_JOB_STATUSES.TIMED_OUT,
];
export class RunsRmCommand extends ApifyCommand<typeof RunsRmCommand> {
static override description = 'Deletes an Actor Run.';
static override args = {
runId: Args.string({
description: 'The run ID to delete.',
required: true,
}),
};
async run() {
const { runId } = this.args;
const apifyClient = await getLoggedClientOrThrow();
const run = await apifyClient.run(runId).get();
if (!run) {
error({ message: `Run with ID "${runId}" was not found on your account.` });
return;
}
if (!deletableStatuses.includes(run.status as never)) {
error({
message: `Run with ID "${runId}" cannot be deleted, as it is still running or in the process of aborting.`,
});
return;
}
const confirmedDelete = await confirmAction({
type: 'Actor Run',
failureMessage: `Your provided value does not match the run ID.`,
});
if (!confirmedDelete) {
info({
message: `Deletion of run "${runId}" was canceled.`,
});
return;
}
try {
await apifyClient.run(runId).delete();
success({
message: `Run with ID "${runId}" was deleted.`,
});
} catch (err) {
const casted = err as ApifyApiError;
error({ message: `Failed to delete run "${runId}".\n ${casted.message || casted}` });
}
}
}