nuxt-cf-jobs 0.4.2 → 0.4.4
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/dist/module.json
CHANGED
|
@@ -79,6 +79,7 @@ export declare function createCfJobsApp<const Jobs extends readonly AnyJobDefini
|
|
|
79
79
|
getQueue: {
|
|
80
80
|
<const Job extends Jobs[number]>(job: Job): ReturnType<typeof createJobQueue<Job>>;
|
|
81
81
|
<const Job extends Jobs[number]>(source: QueueSource | undefined, job: Job): ReturnType<typeof createJobQueue<Job>>;
|
|
82
|
+
(sourceOrJob: unknown, maybeJob?: unknown): import("./queue.js").JobQueuePublisher<AnyJobDefinition>;
|
|
82
83
|
};
|
|
83
84
|
buildJobPayload: <Name extends JobNameOf<Jobs>>(name: Name, payload: JobPayloadByName<Jobs, Name>) => {
|
|
84
85
|
_task: Name;
|
|
@@ -149,6 +150,7 @@ export declare function createGeneratedCfJobsApp<const Jobs extends readonly Laz
|
|
|
149
150
|
getQueue: {
|
|
150
151
|
<const Job extends AnyJobDefinition>(job: Job): import("./queue.js").JobQueuePublisher<Job>;
|
|
151
152
|
<const Job extends AnyJobDefinition>(source: QueueSource | undefined, job: Job): import("./queue.js").JobQueuePublisher<Job>;
|
|
153
|
+
(sourceOrJob: unknown, maybeJob?: unknown): import("./queue.js").JobQueuePublisher<AnyJobDefinition>;
|
|
152
154
|
};
|
|
153
155
|
buildJobPayload: <Name extends string>(name: Name, payload: JobPayloadByName<readonly AnyJobDefinition[], Name>) => {
|
|
154
156
|
_task: Name;
|
|
@@ -18,6 +18,10 @@ export function createCfJobsApp(jobs, { useRuntimeConfig, defaultQueue }) {
|
|
|
18
18
|
console.warn(`[nuxt-cf-jobs] job definition warnings:
|
|
19
19
|
${jobIssues.map((i) => ` - [job:${i.name}] ${i.reason}`).join("\n")}`);
|
|
20
20
|
}
|
|
21
|
+
function readRuntimeConfig(source) {
|
|
22
|
+
const isH3Event = !!source && typeof source === "object" && "context" in source && !!source.context?.nitro;
|
|
23
|
+
return isH3Event ? useRuntimeConfig(source) : useRuntimeConfig();
|
|
24
|
+
}
|
|
21
25
|
function getQueue(sourceOrJob, maybeJob) {
|
|
22
26
|
const isJobOnly = maybeJob === void 0 && isJobDefinition(sourceOrJob);
|
|
23
27
|
const job = isJobOnly ? sourceOrJob : maybeJob;
|
|
@@ -26,8 +30,7 @@ ${jobIssues.map((i) => ` - [job:${i.name}] ${i.reason}`).join("\n")}`);
|
|
|
26
30
|
const env = resolveNitroTaskEnv();
|
|
27
31
|
return env ? { context: { cloudflare: { env } } } : void 0;
|
|
28
32
|
})();
|
|
29
|
-
const
|
|
30
|
-
const runtimeConfig = isH3Event ? useRuntimeConfig(resolvedSource) : useRuntimeConfig();
|
|
33
|
+
const runtimeConfig = readRuntimeConfig(resolvedSource);
|
|
31
34
|
return createJobQueue(resolvedSource, runtimeConfig.cfJobs.queues, job);
|
|
32
35
|
}
|
|
33
36
|
function buildJobPayload(name, payload) {
|
|
@@ -53,13 +56,13 @@ ${issues.map((i) => ` - ${i}`).join("\n")}`);
|
|
|
53
56
|
const ready = {
|
|
54
57
|
...opts,
|
|
55
58
|
registry: jobRegistry,
|
|
56
|
-
queues: (source) =>
|
|
59
|
+
queues: (source) => readRuntimeConfig(source).cfJobs.queues
|
|
57
60
|
};
|
|
58
61
|
let warned = false;
|
|
59
62
|
nitroApp.hooks.hook("cloudflare:queue", async (payload) => {
|
|
60
63
|
if (!warned) {
|
|
61
64
|
warned = true;
|
|
62
|
-
logQueueWarnings(
|
|
65
|
+
logQueueWarnings(readRuntimeConfig(runtimeConfigSource(payload.env)).cfJobs.queues);
|
|
63
66
|
}
|
|
64
67
|
await processRegisteredQueueBatch(payload, ready);
|
|
65
68
|
});
|
|
@@ -21,5 +21,7 @@ export default defineNitroPlugin((nitroApp) => {
|
|
|
21
21
|
env: existing ? { ...runtime.env, ...existing } : runtime.env
|
|
22
22
|
};
|
|
23
23
|
});
|
|
24
|
+
const taskEnvHost = globalThis;
|
|
25
|
+
taskEnvHost.__env__ = { ...runtime.env, ...taskEnvHost.__env__ ?? {} };
|
|
24
26
|
nitroApp.hooks.hook("close", () => runtime.dispose());
|
|
25
27
|
});
|