@sidequest/engine 1.0.0-next.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -0
- package/dist/engine.cjs +27 -11
- package/dist/engine.cjs.map +1 -1
- package/dist/engine.d.ts +3 -2
- package/dist/engine.js +28 -12
- package/dist/engine.js.map +1 -1
- package/dist/execution/executor-manager.cjs +23 -19
- package/dist/execution/executor-manager.cjs.map +1 -1
- package/dist/execution/executor-manager.d.ts +4 -7
- package/dist/execution/executor-manager.js +24 -20
- package/dist/execution/executor-manager.js.map +1 -1
- package/dist/execution/queue-manager.cjs +5 -2
- package/dist/execution/queue-manager.cjs.map +1 -1
- package/dist/execution/queue-manager.d.ts +4 -1
- package/dist/execution/queue-manager.js +5 -2
- package/dist/execution/queue-manager.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/job/job-builder.cjs +51 -9
- package/dist/job/job-builder.cjs.map +1 -1
- package/dist/job/job-builder.d.ts +22 -2
- package/dist/job/job-builder.js +52 -10
- package/dist/job/job-builder.js.map +1 -1
- package/dist/job/job-transitioner.cjs +1 -1
- package/dist/job/job-transitioner.cjs.map +1 -1
- package/dist/job/job-transitioner.js +1 -1
- package/dist/job/job-transitioner.js.map +1 -1
- package/dist/queue/grant-queue-config.cjs +4 -2
- package/dist/queue/grant-queue-config.cjs.map +1 -1
- package/dist/queue/grant-queue-config.d.ts +3 -1
- package/dist/queue/grant-queue-config.js +4 -2
- package/dist/queue/grant-queue-config.js.map +1 -1
- package/dist/shared-runner/runner-pool.cjs +9 -6
- package/dist/shared-runner/runner-pool.cjs.map +1 -1
- package/dist/shared-runner/runner-pool.d.ts +4 -2
- package/dist/shared-runner/runner-pool.js +9 -6
- package/dist/shared-runner/runner-pool.js.map +1 -1
- package/dist/shared-runner/runner.cjs +30 -2
- package/dist/shared-runner/runner.cjs.map +1 -1
- package/dist/shared-runner/runner.d.ts +20 -3
- package/dist/shared-runner/runner.js +30 -3
- package/dist/shared-runner/runner.js.map +1 -1
- package/dist/utils/import.cjs +13 -0
- package/dist/utils/import.cjs.map +1 -0
- package/dist/utils/import.d.ts +15 -0
- package/dist/utils/import.js +11 -0
- package/dist/utils/import.js.map +1 -0
- package/dist/workers/main.cjs +4 -4
- package/dist/workers/main.cjs.map +1 -1
- package/dist/workers/main.js +4 -4
- package/dist/workers/main.js.map +1 -1
- package/package.json +7 -5
- package/dist/job/job.cjs +0 -250
- package/dist/job/job.cjs.map +0 -1
- package/dist/job/job.d.ts +0 -178
- package/dist/job/job.js +0 -248
- package/dist/job/job.js.map +0 -1
package/dist/job/job.d.ts
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { JobData, JobState, ErrorData, UniquenessConfig, SnoozeResult, RetryResult, FailedResult, CompletedResult, JobResult } from '@sidequest/core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Type for a job class constructor.
|
|
5
|
-
*/
|
|
6
|
-
type JobClassType = (new (...args: any) => Job) & {
|
|
7
|
-
prototype: {
|
|
8
|
-
run: (...args: unknown[]) => unknown;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Abstract base class for Sidequest jobs.
|
|
13
|
-
* Concrete job classes should extend this class and implement the `run` method.
|
|
14
|
-
*
|
|
15
|
-
* There are a few convenience methods that can be used to return early and trigger a transition:
|
|
16
|
-
* - `snooze(delay: number)`: Returns a SnoozeResult to delay the job execution for a specified time.
|
|
17
|
-
* - `retry(reason: string | Error, delay?: number)`: Returns a RetryResult to retry the job with an optional delay.
|
|
18
|
-
* - `fail(reason: string | Error)`: Returns a FailedResult to mark the job as failed with a reason.
|
|
19
|
-
* - `complete(result: unknown)`: Returns a CompletedResult to mark the job as completed with a result.
|
|
20
|
-
*
|
|
21
|
-
* Calling any of these methods without returning its result will do absolutely nothing. Thus, you need to return
|
|
22
|
-
* the result of any of these methods to trigger the job transition.
|
|
23
|
-
*
|
|
24
|
-
* If there is an uncaught error in the `run` method, it will automatically return a RetryResult with the error data.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* class MyJob extends Job {
|
|
29
|
-
* async run(arg1: string, arg2: number): Promise<string> {
|
|
30
|
-
* // Your job logic here
|
|
31
|
-
* if (someCondition) {
|
|
32
|
-
* return this.snooze(1000); // Delay the job for 1 second
|
|
33
|
-
* }
|
|
34
|
-
* if (anotherCondition) {
|
|
35
|
-
* return this.retry(new Error("Retrying due to some condition"), 500); // Retry after 500ms
|
|
36
|
-
* }
|
|
37
|
-
* if (yetAnotherCondition) {
|
|
38
|
-
* return this.fail("Failed due to some reason"); // Mark the job as failed
|
|
39
|
-
* }
|
|
40
|
-
* // If everything is fine, return the result
|
|
41
|
-
* return this.complete("Job completed successfully"); // Mark the job as completed
|
|
42
|
-
* // Alternatively, you can just return a value, which will be treated as the job result:
|
|
43
|
-
* return "Job completed successfully";
|
|
44
|
-
* }
|
|
45
|
-
* }
|
|
46
|
-
*/
|
|
47
|
-
declare abstract class Job implements JobData {
|
|
48
|
-
private scriptResolver;
|
|
49
|
-
readonly id: number;
|
|
50
|
-
readonly script: string;
|
|
51
|
-
readonly queue: string;
|
|
52
|
-
readonly state: JobState;
|
|
53
|
-
readonly class: string;
|
|
54
|
-
readonly args: unknown[];
|
|
55
|
-
readonly constructor_args: unknown[];
|
|
56
|
-
readonly attempt: number;
|
|
57
|
-
readonly max_attempts: number;
|
|
58
|
-
readonly inserted_at: Date;
|
|
59
|
-
readonly available_at: Date;
|
|
60
|
-
readonly timeout: number | null;
|
|
61
|
-
readonly result: Omit<unknown, "undefined"> | null;
|
|
62
|
-
readonly errors: ErrorData[] | null;
|
|
63
|
-
readonly attempted_at: Date | null;
|
|
64
|
-
readonly completed_at: Date | null;
|
|
65
|
-
readonly failed_at: Date | null;
|
|
66
|
-
readonly canceled_at: Date | null;
|
|
67
|
-
readonly claimed_at: Date | null;
|
|
68
|
-
readonly claimed_by: string | null;
|
|
69
|
-
readonly unique_digest: string | null;
|
|
70
|
-
readonly uniqueness_config: UniquenessConfig | null;
|
|
71
|
-
/**
|
|
72
|
-
* Initializes the job and resolves its script path.
|
|
73
|
-
*/
|
|
74
|
-
constructor();
|
|
75
|
-
/**
|
|
76
|
-
* Injects JobData properties into the job instance at runtime.
|
|
77
|
-
* @param jobData The job data to inject into this instance.
|
|
78
|
-
*/
|
|
79
|
-
injectJobData(jobData: JobData): void;
|
|
80
|
-
/**
|
|
81
|
-
* The class name of this job.
|
|
82
|
-
*/
|
|
83
|
-
get className(): string;
|
|
84
|
-
/**
|
|
85
|
-
* Waits until the job is ready (script path resolved).
|
|
86
|
-
* @returns A promise that resolves when ready.
|
|
87
|
-
*/
|
|
88
|
-
ready(): Promise<string>;
|
|
89
|
-
/**
|
|
90
|
-
* Returns a snooze result for this job.
|
|
91
|
-
* This will delay the job execution for the specified time by setting `available_at` to the current
|
|
92
|
-
* time plus the delay.
|
|
93
|
-
*
|
|
94
|
-
* @param delay The delay in milliseconds.
|
|
95
|
-
* @returns A SnoozeResult object.
|
|
96
|
-
*/
|
|
97
|
-
snooze(delay: number): SnoozeResult;
|
|
98
|
-
/**
|
|
99
|
-
* Returns a retry result for this job. It will increase one attempt and set the `attempted_at`
|
|
100
|
-
* to the current time. If the number of attempts is increased to the maximum allowed, the transition
|
|
101
|
-
* will mark the job as failed.
|
|
102
|
-
*
|
|
103
|
-
* @param reason The reason for retrying.
|
|
104
|
-
* @param delay Optional delay in milliseconds.
|
|
105
|
-
* @returns A RetryResult object.
|
|
106
|
-
*/
|
|
107
|
-
retry(reason: string | Error, delay?: number): RetryResult;
|
|
108
|
-
/**
|
|
109
|
-
* Returns a failed result for this job. This method will prevent any retry attempts and will mark the
|
|
110
|
-
* job as failed indefinitely.
|
|
111
|
-
*
|
|
112
|
-
* @param reason The reason for failure.
|
|
113
|
-
* @returns A FailedResult object.
|
|
114
|
-
*/
|
|
115
|
-
fail(reason: string | Error): FailedResult;
|
|
116
|
-
/**
|
|
117
|
-
* Returns a completed result for this job.
|
|
118
|
-
* This method will mark the job as completed.
|
|
119
|
-
*
|
|
120
|
-
* @param result The result value.
|
|
121
|
-
* @returns A CompletedResult object.
|
|
122
|
-
*/
|
|
123
|
-
complete(result: unknown): CompletedResult;
|
|
124
|
-
/**
|
|
125
|
-
* Runs the job and returns a JobResult.
|
|
126
|
-
* This method is intended to be used internally.
|
|
127
|
-
*
|
|
128
|
-
* @param args Arguments to pass to the run method.
|
|
129
|
-
* @returns A promise resolving to the job result.
|
|
130
|
-
*/
|
|
131
|
-
perform<T extends JobClassType>(...args: Parameters<T["prototype"]["run"]>): Promise<JobResult>;
|
|
132
|
-
/**
|
|
133
|
-
* The main logic for the job. Must be implemented by subclasses.
|
|
134
|
-
*
|
|
135
|
-
* Returning anything from this method will be treated as the job result and mark the job for completion.
|
|
136
|
-
*
|
|
137
|
-
* If there is an uncaught error in the `run` method, it will automatically return a RetryResult with
|
|
138
|
-
* the error data, which will trigger a job retry.
|
|
139
|
-
*
|
|
140
|
-
* There are a few convenience methods that can be used inside this method to return early and trigger
|
|
141
|
-
* a job transition:
|
|
142
|
-
* - `snooze(delay: number)`: Returns a SnoozeResult to delay the job execution for a specified time.
|
|
143
|
-
* - `retry(reason: string | Error, delay?: number)`: Returns a RetryResult to retry the job with an
|
|
144
|
-
* optional delay.
|
|
145
|
-
* - `fail(reason: string | Error)`: Returns a FailedResult to mark the job as failed with a reason.
|
|
146
|
-
* - `complete(result: unknown)`: Returns a CompletedResult to mark the job as completed with a result.
|
|
147
|
-
*
|
|
148
|
-
* You must return the result of any of these convenience methods to trigger the job transition. Simply
|
|
149
|
-
* calling them without returning their result will do absolutely nothing.
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* ```typescript
|
|
153
|
-
* async run(arg1: string, arg2: number): Promise<string> {
|
|
154
|
-
* // Your job logic here
|
|
155
|
-
* if (someCondition) {
|
|
156
|
-
* return this.snooze(1000); // Delay the job for 1 second
|
|
157
|
-
* }
|
|
158
|
-
* if (anotherCondition) {
|
|
159
|
-
* return this.retry(new Error("Retrying due to some condition"), 500); // Retry after 500ms
|
|
160
|
-
* }
|
|
161
|
-
* if (yetAnotherCondition) {
|
|
162
|
-
* return this.fail("Failed due to some reason"); // Mark the job as failed
|
|
163
|
-
* }
|
|
164
|
-
* // If everything is fine, return the result
|
|
165
|
-
* return this.complete("Job completed successfully"); // Mark the job as completed
|
|
166
|
-
* // Alternatively, you can just return a value, which will be treated as the job result:
|
|
167
|
-
* return "Job completed successfully";
|
|
168
|
-
* }
|
|
169
|
-
* ```
|
|
170
|
-
*
|
|
171
|
-
* @param args Arguments for the job, if any.
|
|
172
|
-
* @returns The result of the job.
|
|
173
|
-
*/
|
|
174
|
-
abstract run(...args: unknown[]): unknown;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export { Job };
|
|
178
|
-
export type { JobClassType };
|
package/dist/job/job.js
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import { logger, toErrorData, isJobResult } from '@sidequest/core';
|
|
2
|
-
import { access } from 'fs/promises';
|
|
3
|
-
import { pathToFileURL } from 'url';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Abstract base class for Sidequest jobs.
|
|
7
|
-
* Concrete job classes should extend this class and implement the `run` method.
|
|
8
|
-
*
|
|
9
|
-
* There are a few convenience methods that can be used to return early and trigger a transition:
|
|
10
|
-
* - `snooze(delay: number)`: Returns a SnoozeResult to delay the job execution for a specified time.
|
|
11
|
-
* - `retry(reason: string | Error, delay?: number)`: Returns a RetryResult to retry the job with an optional delay.
|
|
12
|
-
* - `fail(reason: string | Error)`: Returns a FailedResult to mark the job as failed with a reason.
|
|
13
|
-
* - `complete(result: unknown)`: Returns a CompletedResult to mark the job as completed with a result.
|
|
14
|
-
*
|
|
15
|
-
* Calling any of these methods without returning its result will do absolutely nothing. Thus, you need to return
|
|
16
|
-
* the result of any of these methods to trigger the job transition.
|
|
17
|
-
*
|
|
18
|
-
* If there is an uncaught error in the `run` method, it will automatically return a RetryResult with the error data.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* class MyJob extends Job {
|
|
23
|
-
* async run(arg1: string, arg2: number): Promise<string> {
|
|
24
|
-
* // Your job logic here
|
|
25
|
-
* if (someCondition) {
|
|
26
|
-
* return this.snooze(1000); // Delay the job for 1 second
|
|
27
|
-
* }
|
|
28
|
-
* if (anotherCondition) {
|
|
29
|
-
* return this.retry(new Error("Retrying due to some condition"), 500); // Retry after 500ms
|
|
30
|
-
* }
|
|
31
|
-
* if (yetAnotherCondition) {
|
|
32
|
-
* return this.fail("Failed due to some reason"); // Mark the job as failed
|
|
33
|
-
* }
|
|
34
|
-
* // If everything is fine, return the result
|
|
35
|
-
* return this.complete("Job completed successfully"); // Mark the job as completed
|
|
36
|
-
* // Alternatively, you can just return a value, which will be treated as the job result:
|
|
37
|
-
* return "Job completed successfully";
|
|
38
|
-
* }
|
|
39
|
-
* }
|
|
40
|
-
*/
|
|
41
|
-
class Job {
|
|
42
|
-
scriptResolver;
|
|
43
|
-
// JobData properties
|
|
44
|
-
id;
|
|
45
|
-
script;
|
|
46
|
-
queue;
|
|
47
|
-
state;
|
|
48
|
-
class;
|
|
49
|
-
args;
|
|
50
|
-
constructor_args;
|
|
51
|
-
attempt;
|
|
52
|
-
max_attempts;
|
|
53
|
-
inserted_at;
|
|
54
|
-
available_at;
|
|
55
|
-
timeout;
|
|
56
|
-
result;
|
|
57
|
-
errors;
|
|
58
|
-
attempted_at;
|
|
59
|
-
completed_at;
|
|
60
|
-
failed_at;
|
|
61
|
-
canceled_at;
|
|
62
|
-
claimed_at;
|
|
63
|
-
claimed_by;
|
|
64
|
-
unique_digest;
|
|
65
|
-
uniqueness_config;
|
|
66
|
-
/**
|
|
67
|
-
* Initializes the job and resolves its script path.
|
|
68
|
-
*/
|
|
69
|
-
constructor() {
|
|
70
|
-
/* IMPORTANT: the build path resolution must be called here.
|
|
71
|
-
* This is important to ensure the path resolution is returning the Job implementation.
|
|
72
|
-
*/
|
|
73
|
-
this.scriptResolver = buildPath(this.constructor.name).then((script) => {
|
|
74
|
-
Object.assign(this, { script });
|
|
75
|
-
logger("Job").debug(`Job script resolved: ${script}`);
|
|
76
|
-
return script;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Injects JobData properties into the job instance at runtime.
|
|
81
|
-
* @param jobData The job data to inject into this instance.
|
|
82
|
-
*/
|
|
83
|
-
injectJobData(jobData) {
|
|
84
|
-
logger("Job").debug(`Injecting job data into ${this.className}:`, jobData);
|
|
85
|
-
Object.assign(this, jobData);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* The class name of this job.
|
|
89
|
-
*/
|
|
90
|
-
get className() {
|
|
91
|
-
return this.constructor.name;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Waits until the job is ready (script path resolved).
|
|
95
|
-
* @returns A promise that resolves when ready.
|
|
96
|
-
*/
|
|
97
|
-
async ready() {
|
|
98
|
-
return await this.scriptResolver;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Returns a snooze result for this job.
|
|
102
|
-
* This will delay the job execution for the specified time by setting `available_at` to the current
|
|
103
|
-
* time plus the delay.
|
|
104
|
-
*
|
|
105
|
-
* @param delay The delay in milliseconds.
|
|
106
|
-
* @returns A SnoozeResult object.
|
|
107
|
-
*/
|
|
108
|
-
snooze(delay) {
|
|
109
|
-
logger("Job").debug(`Job ${this.className} snoozed for ${delay}ms`);
|
|
110
|
-
return { __is_job_transition__: true, type: "snooze", delay: delay };
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Returns a retry result for this job. It will increase one attempt and set the `attempted_at`
|
|
114
|
-
* to the current time. If the number of attempts is increased to the maximum allowed, the transition
|
|
115
|
-
* will mark the job as failed.
|
|
116
|
-
*
|
|
117
|
-
* @param reason The reason for retrying.
|
|
118
|
-
* @param delay Optional delay in milliseconds.
|
|
119
|
-
* @returns A RetryResult object.
|
|
120
|
-
*/
|
|
121
|
-
retry(reason, delay) {
|
|
122
|
-
const error = toErrorData(reason);
|
|
123
|
-
logger("Job").debug(`Job ${this.className} retrying due to: ${error.message}${delay ? ` after ${delay}ms` : ""}`);
|
|
124
|
-
return { __is_job_transition__: true, type: "retry", error, delay };
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Returns a failed result for this job. This method will prevent any retry attempts and will mark the
|
|
128
|
-
* job as failed indefinitely.
|
|
129
|
-
*
|
|
130
|
-
* @param reason The reason for failure.
|
|
131
|
-
* @returns A FailedResult object.
|
|
132
|
-
*/
|
|
133
|
-
fail(reason) {
|
|
134
|
-
const error = toErrorData(reason);
|
|
135
|
-
logger("Job").debug(`Job ${this.className} failed: ${error.message}`);
|
|
136
|
-
return { __is_job_transition__: true, type: "failed", error };
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Returns a completed result for this job.
|
|
140
|
-
* This method will mark the job as completed.
|
|
141
|
-
*
|
|
142
|
-
* @param result The result value.
|
|
143
|
-
* @returns A CompletedResult object.
|
|
144
|
-
*/
|
|
145
|
-
complete(result) {
|
|
146
|
-
logger("Job").debug(`Job ${this.className} completed.`);
|
|
147
|
-
return { __is_job_transition__: true, type: "completed", result };
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Runs the job and returns a JobResult.
|
|
151
|
-
* This method is intended to be used internally.
|
|
152
|
-
*
|
|
153
|
-
* @param args Arguments to pass to the run method.
|
|
154
|
-
* @returns A promise resolving to the job result.
|
|
155
|
-
*/
|
|
156
|
-
async perform(...args) {
|
|
157
|
-
try {
|
|
158
|
-
const result = await this.run(...args);
|
|
159
|
-
if (isJobResult(result)) {
|
|
160
|
-
return result;
|
|
161
|
-
}
|
|
162
|
-
return { __is_job_transition__: true, type: "completed", result };
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
logger("Job").debug(error);
|
|
166
|
-
const errorData = toErrorData(error);
|
|
167
|
-
return { __is_job_transition__: true, type: "retry", error: errorData };
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
// TODO need to test this with unit tests
|
|
172
|
-
/**
|
|
173
|
-
* Attempts to determine the file path where a given class is exported by analyzing the current call stack.
|
|
174
|
-
*
|
|
175
|
-
* This function inspects the stack trace of a newly created error to extract file paths,
|
|
176
|
-
* then checks each file to see if it exports the specified class. If found, returns the file path
|
|
177
|
-
* as a `file://` URI. If not found, returns the first file path in the stack as a fallback.
|
|
178
|
-
* Throws an error if no file paths can be determined.
|
|
179
|
-
*
|
|
180
|
-
* @param className - The name of the class to search for in the stack trace files.
|
|
181
|
-
* @returns A promise that resolves to the `file://` URI of the file exporting the class, or the first file in the stack.
|
|
182
|
-
* @throws If no file paths can be determined from the stack trace.
|
|
183
|
-
*/
|
|
184
|
-
async function buildPath(className) {
|
|
185
|
-
const err = new Error();
|
|
186
|
-
let stackLines = err.stack?.split("\n") ?? [];
|
|
187
|
-
stackLines = stackLines.slice(1);
|
|
188
|
-
logger("Job").debug(`Resolving script file path. Stack lines: ${stackLines.join("\n")}`);
|
|
189
|
-
const filePaths = stackLines
|
|
190
|
-
.map((line) => {
|
|
191
|
-
const match = /(file:\/\/)?(((\/?)(\w:))?([/\\].+)):\d+:\d+/.exec(line);
|
|
192
|
-
if (match) {
|
|
193
|
-
return `${match[5] ?? ""}${match[6].replaceAll("\\", "/")}`;
|
|
194
|
-
}
|
|
195
|
-
return null;
|
|
196
|
-
})
|
|
197
|
-
.filter(Boolean);
|
|
198
|
-
for (const filePath of filePaths) {
|
|
199
|
-
const hasExported = await hasClassExported(filePath, className);
|
|
200
|
-
if (hasExported) {
|
|
201
|
-
logger("Job").debug(`${filePath} exports class ${className}`);
|
|
202
|
-
return `file://${filePath}`;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
if (filePaths.length > 0) {
|
|
206
|
-
logger("Job").debug(`No class ${className} found in stack, returning first file path: ${filePaths[0]}`);
|
|
207
|
-
return `file://${filePaths[0]}`;
|
|
208
|
-
}
|
|
209
|
-
throw new Error("Could not determine the task path");
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Checks if a given file exports a class with the specified name.
|
|
213
|
-
*
|
|
214
|
-
* This function attempts to import the module at the provided file path and
|
|
215
|
-
* determines if it exports a class (either as a named export or as the default export)
|
|
216
|
-
* matching the given class name.
|
|
217
|
-
*
|
|
218
|
-
* @param filePath - The absolute path to the module file to check.
|
|
219
|
-
* @param className - The name of the class to look for in the module's exports.
|
|
220
|
-
* @returns A promise that resolves to `true` if the class is exported, or `false` otherwise.
|
|
221
|
-
*/
|
|
222
|
-
async function hasClassExported(filePath, className) {
|
|
223
|
-
try {
|
|
224
|
-
await access(filePath);
|
|
225
|
-
}
|
|
226
|
-
catch {
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
|
-
try {
|
|
230
|
-
const moduleUrl = pathToFileURL(filePath).href;
|
|
231
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
232
|
-
const mod = await import(moduleUrl);
|
|
233
|
-
if (mod && typeof mod === "object" && className in mod && typeof mod[className] === "function") {
|
|
234
|
-
return true;
|
|
235
|
-
}
|
|
236
|
-
if ("default" in mod && typeof mod.default === "function" && mod.default.name === className) {
|
|
237
|
-
return true;
|
|
238
|
-
}
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
catch (e) {
|
|
242
|
-
logger().debug(e);
|
|
243
|
-
return false;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export { Job };
|
|
248
|
-
//# sourceMappingURL=job.js.map
|
package/dist/job/job.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"job.js","sources":["../../src/job/job.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAuBA;;;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