alepha 0.20.5 → 0.20.7
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/AGENTS.md +0 -1
- package/CLAUDE.md +0 -1
- package/assets/agents-template.md +0 -1
- package/dist/api/audits/index.browser.js +1 -0
- package/dist/api/audits/index.browser.js.map +1 -1
- package/dist/api/audits/index.d.ts +701 -654
- package/dist/api/audits/index.d.ts.map +1 -1
- package/dist/api/audits/index.js +24 -1
- package/dist/api/audits/index.js.map +1 -1
- package/dist/api/files/index.browser.js +1 -0
- package/dist/api/files/index.browser.js.map +1 -1
- package/dist/api/files/index.d.ts +193 -166
- package/dist/api/files/index.d.ts.map +1 -1
- package/dist/api/files/index.js +52 -0
- package/dist/api/files/index.js.map +1 -1
- package/dist/api/jobs/index.browser.js +40 -14
- package/dist/api/jobs/index.browser.js.map +1 -1
- package/dist/api/jobs/index.d.ts +639 -333
- package/dist/api/jobs/index.d.ts.map +1 -1
- package/dist/api/jobs/index.js +495 -162
- package/dist/api/jobs/index.js.map +1 -1
- package/dist/api/keys/index.d.ts +222 -188
- package/dist/api/keys/index.d.ts.map +1 -1
- package/dist/api/keys/index.js +54 -0
- package/dist/api/keys/index.js.map +1 -1
- package/dist/api/notifications/index.d.ts +265 -236
- package/dist/api/notifications/index.d.ts.map +1 -1
- package/dist/api/notifications/index.js +55 -13
- package/dist/api/notifications/index.js.map +1 -1
- package/dist/api/organizations/index.d.ts +100 -97
- package/dist/api/organizations/index.d.ts.map +1 -1
- package/dist/api/organizations/index.js.map +1 -1
- package/dist/api/parameters/index.d.ts +332 -314
- package/dist/api/parameters/index.d.ts.map +1 -1
- package/dist/api/parameters/index.js +37 -0
- package/dist/api/parameters/index.js.map +1 -1
- package/dist/api/payments/index.d.ts +431 -376
- package/dist/api/payments/index.d.ts.map +1 -1
- package/dist/api/payments/index.js +202 -87
- package/dist/api/payments/index.js.map +1 -1
- package/dist/api/subscriptions/index.d.ts +1695 -0
- package/dist/api/subscriptions/index.d.ts.map +1 -0
- package/dist/api/subscriptions/index.js +1919 -0
- package/dist/api/subscriptions/index.js.map +1 -0
- package/dist/api/users/index.d.ts +1001 -844
- package/dist/api/users/index.d.ts.map +1 -1
- package/dist/api/users/index.js +237 -28
- package/dist/api/users/index.js.map +1 -1
- package/dist/api/verifications/index.d.ts +123 -122
- package/dist/api/verifications/index.d.ts.map +1 -1
- package/dist/api/verifications/index.js.map +1 -1
- package/dist/batch/index.js.map +1 -1
- package/dist/bucket/index.d.ts +21 -2
- package/dist/bucket/index.d.ts.map +1 -1
- package/dist/bucket/index.js +47 -0
- package/dist/bucket/index.js.map +1 -1
- package/dist/bucket/index.workerd.js +24 -0
- package/dist/bucket/index.workerd.js.map +1 -1
- package/dist/cache/core/index.d.ts +134 -7
- package/dist/cache/core/index.d.ts.map +1 -1
- package/dist/cache/core/index.js +181 -15
- package/dist/cache/core/index.js.map +1 -1
- package/dist/cache/core/index.workerd.js +181 -15
- package/dist/cache/core/index.workerd.js.map +1 -1
- package/dist/cache/database/index.d.ts +156 -0
- package/dist/cache/database/index.d.ts.map +1 -0
- package/dist/cache/database/index.js +266 -0
- package/dist/cache/database/index.js.map +1 -0
- package/dist/cache/redis/index.d.ts +3 -2
- package/dist/cache/redis/index.d.ts.map +1 -1
- package/dist/cache/redis/index.js.map +1 -1
- package/dist/captcha/index.js.map +1 -1
- package/dist/cli/config/index.js.map +1 -1
- package/dist/cli/core/index.d.ts +142 -128
- package/dist/cli/core/index.d.ts.map +1 -1
- package/dist/cli/core/index.js +160 -13
- package/dist/cli/core/index.js.map +1 -1
- package/dist/cli/devtools/index.d.ts +3 -2
- package/dist/cli/devtools/index.d.ts.map +1 -1
- package/dist/cli/devtools/index.js.map +1 -1
- package/dist/cli/platform/index.d.ts +346 -290
- package/dist/cli/platform/index.d.ts.map +1 -1
- package/dist/cli/platform/index.js +106 -7
- package/dist/cli/platform/index.js.map +1 -1
- package/dist/cli/vendor/index.d.ts +12 -11
- package/dist/cli/vendor/index.d.ts.map +1 -1
- package/dist/cli/vendor/index.js.map +1 -1
- package/dist/command/index.d.ts +6 -5
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js.map +1 -1
- package/dist/core/index.browser.js +1 -1
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +119 -118
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +1 -1
- package/dist/core/index.native.js.map +1 -1
- package/dist/core/index.workerd.js +1 -1
- package/dist/core/index.workerd.js.map +1 -1
- package/dist/crypto/index.browser.js.map +1 -1
- package/dist/crypto/index.d.ts +3 -2
- package/dist/crypto/index.d.ts.map +1 -1
- package/dist/crypto/index.js.map +1 -1
- package/dist/datetime/index.js.map +1 -1
- package/dist/email/brevo/index.js.map +1 -1
- package/dist/email/core/index.d.ts +3 -2
- package/dist/email/core/index.d.ts.map +1 -1
- package/dist/email/core/index.js.map +1 -1
- package/dist/email/core/index.workerd.js.map +1 -1
- package/dist/email/smtp/index.d.ts +7 -6
- package/dist/email/smtp/index.d.ts.map +1 -1
- package/dist/email/smtp/index.js.map +1 -1
- package/dist/fake/index.js.map +1 -1
- package/dist/lock/core/index.d.ts +5 -4
- package/dist/lock/core/index.d.ts.map +1 -1
- package/dist/lock/core/index.js.map +1 -1
- package/dist/lock/redis/index.js.map +1 -1
- package/dist/logger/index.d.ts +10 -9
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js.map +1 -1
- package/dist/mcp/index.d.ts +9 -8
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/orm/core/index.browser.js +9 -3
- package/dist/orm/core/index.browser.js.map +1 -1
- package/dist/orm/core/index.bun.js +31 -10
- package/dist/orm/core/index.bun.js.map +1 -1
- package/dist/orm/core/index.d.ts +33 -14
- package/dist/orm/core/index.d.ts.map +1 -1
- package/dist/orm/core/index.js +31 -10
- package/dist/orm/core/index.js.map +1 -1
- package/dist/orm/postgres/index.bun.js.map +1 -1
- package/dist/orm/postgres/index.d.ts +6 -5
- package/dist/orm/postgres/index.d.ts.map +1 -1
- package/dist/orm/postgres/index.js.map +1 -1
- package/dist/queue/core/index.d.ts +5 -4
- package/dist/queue/core/index.d.ts.map +1 -1
- package/dist/queue/core/index.js.map +1 -1
- package/dist/queue/core/index.workerd.js.map +1 -1
- package/dist/queue/redis/index.d.ts +3 -2
- package/dist/queue/redis/index.d.ts.map +1 -1
- package/dist/queue/redis/index.js.map +1 -1
- package/dist/react/auth/index.browser.js.map +1 -1
- package/dist/react/auth/index.js.map +1 -1
- package/dist/react/core/index.js.map +1 -1
- package/dist/react/form/index.d.ts +5 -0
- package/dist/react/form/index.d.ts.map +1 -1
- package/dist/react/form/index.js +8 -4
- package/dist/react/form/index.js.map +1 -1
- package/dist/react/head/index.browser.js.map +1 -1
- package/dist/react/head/index.js.map +1 -1
- package/dist/react/i18n/index.d.ts +2 -1
- package/dist/react/i18n/index.d.ts.map +1 -1
- package/dist/react/i18n/index.js.map +1 -1
- package/dist/react/intro/index.js.map +1 -1
- package/dist/react/router/index.browser.js.map +1 -1
- package/dist/react/router/index.d.ts +206 -205
- package/dist/react/router/index.d.ts.map +1 -1
- package/dist/react/router/index.js.map +1 -1
- package/dist/react/testing/index.js.map +1 -1
- package/dist/react/ui/index.d.ts +11 -11
- package/dist/react/ui/index.d.ts.map +1 -1
- package/dist/react/ui/index.js.map +1 -1
- package/dist/redis/index.bun.js.map +1 -1
- package/dist/redis/index.js.map +1 -1
- package/dist/retry/index.js.map +1 -1
- package/dist/router/index.js.map +1 -1
- package/dist/scheduler/index.d.ts +25 -2
- package/dist/scheduler/index.d.ts.map +1 -1
- package/dist/scheduler/index.js +12 -0
- package/dist/scheduler/index.js.map +1 -1
- package/dist/scheduler/index.workerd.js +12 -0
- package/dist/scheduler/index.workerd.js.map +1 -1
- package/dist/security/index.browser.js +29 -1
- package/dist/security/index.browser.js.map +1 -1
- package/dist/security/index.d.ts +82 -35
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +56 -3
- package/dist/security/index.js.map +1 -1
- package/dist/server/auth/index.d.ts +163 -158
- package/dist/server/auth/index.d.ts.map +1 -1
- package/dist/server/auth/index.js +16 -4
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/cookies/index.browser.js.map +1 -1
- package/dist/server/cookies/index.js.map +1 -1
- package/dist/server/core/index.browser.js.map +1 -1
- package/dist/server/core/index.d.ts +35 -34
- package/dist/server/core/index.d.ts.map +1 -1
- package/dist/server/core/index.js.map +1 -1
- package/dist/server/cors/index.d.ts +7 -6
- package/dist/server/cors/index.d.ts.map +1 -1
- package/dist/server/cors/index.js.map +1 -1
- package/dist/server/etag/index.js.map +1 -1
- package/dist/server/health/index.d.ts +16 -15
- package/dist/server/health/index.d.ts.map +1 -1
- package/dist/server/health/index.js.map +1 -1
- package/dist/server/links/index.browser.js.map +1 -1
- package/dist/server/links/index.d.ts +51 -50
- package/dist/server/links/index.d.ts.map +1 -1
- package/dist/server/links/index.js.map +1 -1
- package/dist/server/metrics/index.js.map +1 -1
- package/dist/server/proxy/index.js.map +1 -1
- package/dist/server/rate-limit/index.d.ts +6 -5
- package/dist/server/rate-limit/index.d.ts.map +1 -1
- package/dist/server/rate-limit/index.js.map +1 -1
- package/dist/server/static/index.js.map +1 -1
- package/dist/server/swagger/index.d.ts +2 -1
- package/dist/server/swagger/index.d.ts.map +1 -1
- package/dist/server/swagger/index.js.map +1 -1
- package/dist/sms/index.js.map +1 -1
- package/dist/system/index.browser.js.map +1 -1
- package/dist/system/index.js.map +1 -1
- package/dist/system/index.workerd.js.map +1 -1
- package/dist/topic/core/index.js.map +1 -1
- package/dist/topic/redis/index.d.ts +3 -2
- package/dist/topic/redis/index.d.ts.map +1 -1
- package/dist/topic/redis/index.js.map +1 -1
- package/package.json +33 -39
- package/src/api/audits/controllers/AdminAuditController.ts +29 -0
- package/src/api/audits/entities/audits.ts +1 -0
- package/src/api/files/controllers/FileController.ts +24 -0
- package/src/api/files/entities/files.ts +1 -0
- package/src/api/files/services/FileService.ts +41 -0
- package/src/api/jobs/__tests__/$job.spec.ts +501 -24
- package/src/api/jobs/entities/jobExecutionEntity.ts +4 -3
- package/src/api/jobs/index.ts +47 -10
- package/src/api/jobs/primitives/$job.ts +22 -9
- package/src/api/jobs/providers/DirectJobDispatcher.ts +71 -0
- package/src/api/jobs/providers/JobDispatcher.ts +49 -0
- package/src/api/jobs/providers/JobProvider.ts +385 -147
- package/src/api/jobs/providers/JobQueueProvider.ts +43 -18
- package/src/api/jobs/schemas/jobConfigAtom.ts +9 -3
- package/src/api/jobs/schemas/jobExecutionResourceSchema.ts +11 -0
- package/src/api/jobs/schemas/jobRegistrationSchema.ts +4 -2
- package/src/api/jobs/services/JobService.ts +21 -11
- package/src/api/keys/controllers/AdminApiKeyController.ts +23 -0
- package/src/api/keys/entities/apiKeyEntity.ts +1 -0
- package/src/api/keys/services/ApiKeyService.ts +42 -0
- package/src/api/notifications/__tests__/AlephaApiNotifications.spec.ts +63 -0
- package/src/api/notifications/controllers/AdminNotificationController.ts +48 -1
- package/src/api/notifications/index.ts +13 -3
- package/src/api/notifications/jobs/NotificationJobs.ts +0 -6
- package/src/api/parameters/controllers/AdminParameterController.ts +26 -0
- package/src/api/parameters/services/ParameterProvider.ts +18 -0
- package/src/api/payments/controllers/MockCheckoutController.ts +146 -0
- package/src/api/payments/index.ts +3 -0
- package/src/api/payments/providers/MemoryPaymentProvider.ts +9 -4
- package/src/api/payments/providers/PaymentProvider.ts +25 -9
- package/src/api/payments/services/PaymentService.ts +3 -0
- package/src/api/subscriptions/__tests__/BillingService.spec.ts +218 -0
- package/src/api/subscriptions/__tests__/SubscriptionService.spec.ts +278 -0
- package/src/api/subscriptions/controllers/AdminSubscriptionController.ts +212 -0
- package/src/api/subscriptions/controllers/SubscriptionController.ts +189 -0
- package/src/api/subscriptions/entities/subscriptionEvents.ts +54 -0
- package/src/api/subscriptions/entities/subscriptions.ts +68 -0
- package/src/api/subscriptions/index.ts +133 -0
- package/src/api/subscriptions/jobs/SubscriptionJobs.ts +382 -0
- package/src/api/subscriptions/middleware/$requireLimit.ts +50 -0
- package/src/api/subscriptions/middleware/$requirePlan.ts +49 -0
- package/src/api/subscriptions/notifications/SubscriptionNotifications.ts +110 -0
- package/src/api/subscriptions/schemas/cancelSubscriptionSchema.ts +8 -0
- package/src/api/subscriptions/schemas/changePlanSchema.ts +9 -0
- package/src/api/subscriptions/schemas/createSubscriptionSchema.ts +11 -0
- package/src/api/subscriptions/schemas/entitlementsSchema.ts +21 -0
- package/src/api/subscriptions/schemas/mrrSchema.ts +13 -0
- package/src/api/subscriptions/schemas/planDefinitionSchema.ts +71 -0
- package/src/api/subscriptions/schemas/planResourceSchema.ts +25 -0
- package/src/api/subscriptions/schemas/subscriptionEventResourceSchema.ts +8 -0
- package/src/api/subscriptions/schemas/subscriptionQuerySchema.ts +19 -0
- package/src/api/subscriptions/schemas/subscriptionResourceSchema.ts +6 -0
- package/src/api/subscriptions/schemas/subscriptionSettingsSchema.ts +32 -0
- package/src/api/subscriptions/schemas/subscriptionStatsSchema.ts +23 -0
- package/src/api/subscriptions/services/BillingService.ts +437 -0
- package/src/api/subscriptions/services/SubscriptionConfig.ts +56 -0
- package/src/api/subscriptions/services/SubscriptionService.ts +867 -0
- package/src/api/subscriptions/services/UsageService.ts +118 -0
- package/src/api/users/__tests__/Registration-emailMode.spec.ts +203 -0
- package/src/api/users/__tests__/UsernameSlugger.spec.ts +138 -0
- package/src/api/users/atoms/realmAuthSettingsAtom.ts +41 -3
- package/src/api/users/controllers/AdminSessionController.ts +29 -0
- package/src/api/users/controllers/AdminUserController.ts +32 -0
- package/src/api/users/index.ts +3 -0
- package/src/api/users/services/CredentialService.ts +5 -0
- package/src/api/users/services/RegistrationService.ts +49 -1
- package/src/api/users/services/SessionCrudService.ts +16 -0
- package/src/api/users/services/SessionService.ts +17 -59
- package/src/api/users/services/UsernameSlugger.ts +195 -0
- package/src/bucket/primitives/$bucket.ts +21 -0
- package/src/bucket/providers/CloudflareR2Provider.ts +15 -0
- package/src/bucket/providers/FileStorageProvider.ts +9 -0
- package/src/bucket/providers/LocalFileStorageProvider.ts +14 -0
- package/src/bucket/providers/MemoryFileStorageProvider.ts +9 -0
- package/src/bucket/providers/NodeS3BucketProvider.ts +35 -0
- package/src/cache/core/__tests__/$cache.memory.spec.ts +450 -0
- package/src/cache/core/__tests__/$cache.swr.spec.ts +394 -0
- package/src/cache/core/index.ts +16 -0
- package/src/cache/core/primitives/$cache.ts +367 -24
- package/src/cache/database/__tests__/DatabaseCacheProvider.behavior.spec.ts +203 -0
- package/src/cache/database/__tests__/DatabaseCacheProvider.spec.ts +110 -0
- package/src/cache/database/entities/cacheEntries.ts +55 -0
- package/src/cache/database/index.ts +36 -0
- package/src/cache/database/providers/DatabaseCacheProvider.ts +348 -0
- package/src/cli/core/services/ProjectScaffolder.ts +0 -2
- package/src/cli/core/tasks/BuildCloudflareTask.ts +33 -3
- package/src/cli/core/tasks/BuildSitemapTask.ts +7 -0
- package/src/cli/core/tasks/BuildVercelTask.ts +82 -3
- package/src/cli/core/templates/agentMd.ts +39 -4
- package/src/cli/core/templates/biomeJson.ts +25 -1
- package/src/cli/core/templates/saasAdminLayoutTsx.ts +2 -2
- package/src/cli/platform/__tests__/CloudflareAdapter.spec.ts +117 -0
- package/src/cli/platform/__tests__/detectResources.spec.ts +96 -0
- package/src/cli/platform/adapters/CloudflareAdapter.ts +104 -7
- package/src/cli/platform/atoms/platformOptions.ts +13 -0
- package/src/cli/platform/commands/platform.ts +7 -1
- package/src/cli/platform/schemas/platform.ts +1 -0
- package/src/cli/platform/services/CloudflareApi.ts +61 -0
- package/src/cli/platform/services/PlatformOrchestrator.ts +9 -4
- package/src/core/__tests__/$module.spec.ts +2 -2
- package/src/core/primitives/$module.ts +4 -4
- package/src/mcp/providers/McpServerProvider.ts +1 -1
- package/src/orm/core/providers/DatabaseTypeProvider.ts +9 -3
- package/src/orm/core/providers/drivers/DatabaseProvider.ts +1 -1
- package/src/orm/core/schemas/insertSchema.ts +10 -2
- package/src/orm/core/services/Repository.ts +27 -7
- package/src/react/form/hooks/useFormState.ts +8 -1
- package/src/react/form/index.ts +10 -1
- package/src/react/form/services/FormModel.ts +9 -3
- package/src/scheduler/index.ts +14 -0
- package/src/scheduler/providers/CronProvider.ts +13 -0
- package/src/security/atoms/currentTenantAtom.ts +34 -0
- package/src/security/index.browser.ts +1 -0
- package/src/security/index.ts +12 -1
- package/src/security/primitives/$issuer.ts +17 -1
- package/src/security/providers/SecurityProvider.ts +37 -0
- package/src/server/auth/__tests__/validateRedirectUri.spec.ts +78 -0
- package/src/server/auth/providers/ServerAuthProvider.ts +21 -5
- package/tsconfig.base.json +2 -1
- package/dist/react/websocket/index.d.ts +0 -117
- package/dist/react/websocket/index.d.ts.map +0 -1
- package/dist/react/websocket/index.js +0 -108
- package/dist/react/websocket/index.js.map +0 -1
- package/dist/websocket/index.browser.js +0 -844
- package/dist/websocket/index.browser.js.map +0 -1
- package/dist/websocket/index.d.ts +0 -876
- package/dist/websocket/index.d.ts.map +0 -1
- package/dist/websocket/index.js +0 -1175
- package/dist/websocket/index.js.map +0 -1
- package/src/react/websocket/hooks/useRoom.tsx +0 -251
- package/src/react/websocket/index.ts +0 -7
- package/src/websocket/__tests__/$channel.spec.ts +0 -30
- package/src/websocket/__tests__/$websocket-new.spec.ts +0 -195
- package/src/websocket/__tests__/RoomManager.spec.ts +0 -146
- package/src/websocket/__tests__/websocket-integration.spec.ts +0 -951
- package/src/websocket/errors/WebSocketError.ts +0 -34
- package/src/websocket/index.browser.ts +0 -25
- package/src/websocket/index.shared.ts +0 -8
- package/src/websocket/index.ts +0 -85
- package/src/websocket/interfaces/WebSocketInterfaces.ts +0 -252
- package/src/websocket/primitives/$channel.ts +0 -131
- package/src/websocket/primitives/$websocket.ts +0 -107
- package/src/websocket/providers/NodeWebSocketServerProvider.ts +0 -617
- package/src/websocket/providers/WebSocketServerProvider.ts +0 -56
- package/src/websocket/services/RoomManager.ts +0 -160
- package/src/websocket/services/WebSocketClient.ts +0 -642
- package/src/websocket/services/WebSocketTopicService.ts +0 -108
package/dist/api/jobs/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _$alepha from "alepha";
|
|
2
2
|
import { Alepha, AlephaError, Async, KIND, PipelinePrimitive, PipelinePrimitiveOptions, Static, TNull, TObject, TOptional, TSchema, TUnion } from "alepha";
|
|
3
|
+
import { LockProvider } from "alepha/lock";
|
|
3
4
|
import * as _$alepha_queue0 from "alepha/queue";
|
|
4
5
|
import { CronProvider } from "alepha/scheduler";
|
|
5
6
|
import * as _$alepha_server0 from "alepha/server";
|
|
@@ -7,6 +8,7 @@ import * as _$alepha_logger0 from "alepha/logger";
|
|
|
7
8
|
import { LogEntry } from "alepha/logger";
|
|
8
9
|
import * as _$alepha_orm0 from "alepha/orm";
|
|
9
10
|
import { DateTime, DateTimeProvider, DurationLike } from "alepha/datetime";
|
|
11
|
+
import * as _$typebox from "typebox";
|
|
10
12
|
import { BuildExtraConfigColumns, SQL } from "drizzle-orm";
|
|
11
13
|
import { PgColumnBuilderBase, PgSequenceOptions, PgTableExtraConfigValue, UpdateDeleteAction } from "drizzle-orm/pg-core";
|
|
12
14
|
//#region ../../src/orm/core/schemas/insertSchema.d.ts
|
|
@@ -23,6 +25,8 @@ type TObjectInsert<T extends TObject> = TObject<{ [K in keyof T["properties"] as
|
|
|
23
25
|
[PG_GENERATED]: any;
|
|
24
26
|
} ? never : K]: T["properties"][K] extends {
|
|
25
27
|
[PG_DEFAULT]: any;
|
|
28
|
+
} | {
|
|
29
|
+
[PG_ORGANIZATION]: any;
|
|
26
30
|
} | {
|
|
27
31
|
"~optional": true;
|
|
28
32
|
} ? TOptional<T["properties"][K]> : T["properties"][K] }>;
|
|
@@ -298,8 +302,8 @@ type PgAttr<T extends TSchema, TAttr extends PgSymbolKeys> = T & { [K in TAttr]:
|
|
|
298
302
|
* - `d1://BINDING_NAME` — Cloudflare D1
|
|
299
303
|
* - `hyperdrive://BINDING_NAME` — Cloudflare Hyperdrive
|
|
300
304
|
*/
|
|
301
|
-
declare const databaseEnvSchema: _$
|
|
302
|
-
DATABASE_URL: _$
|
|
305
|
+
declare const databaseEnvSchema: _$typebox.TObject<{
|
|
306
|
+
DATABASE_URL: _$typebox.TOptional<_$typebox.TString>;
|
|
303
307
|
/**
|
|
304
308
|
* Enable or disable push-based schema synchronization (drizzle-kit push).
|
|
305
309
|
*
|
|
@@ -307,12 +311,63 @@ declare const databaseEnvSchema: _$alepha.TObject<{
|
|
|
307
311
|
* Set to `false` in development to skip automatic schema sync
|
|
308
312
|
* (e.g. when managing migrations manually).
|
|
309
313
|
*/
|
|
310
|
-
DATABASE_SYNC: _$
|
|
314
|
+
DATABASE_SYNC: _$typebox.TOptional<_$typebox.TBoolean>;
|
|
311
315
|
}>;
|
|
312
316
|
declare module "alepha" {
|
|
313
317
|
interface Env extends Partial<Static<typeof databaseEnvSchema>> {}
|
|
314
318
|
} //# sourceMappingURL=databaseEnvSchema.d.ts.map
|
|
315
319
|
//#endregion
|
|
320
|
+
//#region ../../src/api/jobs/entities/jobExecutionEntity.d.ts
|
|
321
|
+
/**
|
|
322
|
+
* Job execution record.
|
|
323
|
+
*
|
|
324
|
+
* Stores durable state for queue-mode jobs (outbox pattern) and error records
|
|
325
|
+
* for cron-mode jobs. Successful executions are trimmed by the sweep to keep
|
|
326
|
+
* the last N rows per job (configurable via `jobConfig.keepLastSuccess`).
|
|
327
|
+
*
|
|
328
|
+
* Status transitions:
|
|
329
|
+
* - queue push → pending (or `scheduled` if `delay`/`scheduledAt` was given)
|
|
330
|
+
* - worker claim → running
|
|
331
|
+
* - success → ok (or row deleted, depending on `record` and `keepLastSuccess`)
|
|
332
|
+
* - terminal failure → error
|
|
333
|
+
* - retryable failure → scheduled (with scheduledAt = now; sweep picks it up)
|
|
334
|
+
* - delay → scheduled (with scheduledAt = now + delay)
|
|
335
|
+
* - sweep picks due ones → pending
|
|
336
|
+
* - cancel → cancelled
|
|
337
|
+
*/
|
|
338
|
+
declare const jobExecutionEntity: _$alepha_orm0.EntityPrimitive<_$typebox.TObject<{
|
|
339
|
+
id: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_PRIMARY_KEY>, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
340
|
+
createdAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_CREATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
341
|
+
updatedAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_UPDATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
342
|
+
jobName: _$typebox.TString;
|
|
343
|
+
key: _$typebox.TOptional<_$typebox.TUnion<[_$typebox.TNull, _$typebox.TString]>>;
|
|
344
|
+
status: _$alepha_orm0.PgAttr<_$typebox.TUnsafe<"pending" | "running" | "scheduled" | "ok" | "error" | "cancelled">, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
345
|
+
priority: _$alepha_orm0.PgAttr<_$typebox.TInteger, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
346
|
+
attempt: _$alepha_orm0.PgAttr<_$typebox.TInteger, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
347
|
+
maxAttempts: _$alepha_orm0.PgAttr<_$typebox.TInteger, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
348
|
+
payload: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
|
|
349
|
+
scheduledAt: _$typebox.TOptional<_$typebox.TString>;
|
|
350
|
+
startedAt: _$typebox.TOptional<_$typebox.TString>;
|
|
351
|
+
completedAt: _$typebox.TOptional<_$typebox.TString>;
|
|
352
|
+
error: _$typebox.TOptional<_$typebox.TString>;
|
|
353
|
+
logs: _$typebox.TOptional<_$typebox.TArray<_$typebox.TObject<{
|
|
354
|
+
level: _$typebox.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
|
|
355
|
+
message: _$typebox.TString;
|
|
356
|
+
service: _$typebox.TString;
|
|
357
|
+
module: _$typebox.TString;
|
|
358
|
+
context: _$typebox.TOptional<_$typebox.TString>;
|
|
359
|
+
app: _$typebox.TOptional<_$typebox.TString>;
|
|
360
|
+
data: _$typebox.TOptional<_$typebox.TAny>;
|
|
361
|
+
timestamp: _$typebox.TNumber;
|
|
362
|
+
}>>>;
|
|
363
|
+
triggeredBy: _$typebox.TOptional<_$typebox.TString>;
|
|
364
|
+
triggeredByName: _$typebox.TOptional<_$typebox.TString>;
|
|
365
|
+
cancelledBy: _$typebox.TOptional<_$typebox.TString>;
|
|
366
|
+
cancelledByName: _$typebox.TOptional<_$typebox.TString>;
|
|
367
|
+
}>>;
|
|
368
|
+
type JobExecutionEntity = Static<typeof jobExecutionEntity.schema>;
|
|
369
|
+
type JobStatus = "pending" | "running" | "scheduled" | "ok" | "error" | "cancelled";
|
|
370
|
+
//#endregion
|
|
316
371
|
//#region ../../src/api/jobs/primitives/$job.d.ts
|
|
317
372
|
/**
|
|
318
373
|
* Job primitive for defining scheduled (cron) or queued (push) tasks.
|
|
@@ -333,15 +388,8 @@ interface JobHandlerArgs<T extends TSchema = TSchema> {
|
|
|
333
388
|
signal: AbortSignal;
|
|
334
389
|
executionId: string;
|
|
335
390
|
}
|
|
336
|
-
interface JobRetryBackoff {
|
|
337
|
-
initial: DurationLike;
|
|
338
|
-
factor?: number;
|
|
339
|
-
max?: DurationLike;
|
|
340
|
-
jitter?: boolean;
|
|
341
|
-
}
|
|
342
391
|
interface JobRetryOptions {
|
|
343
392
|
retries: number;
|
|
344
|
-
backoff?: DurationLike | JobRetryBackoff;
|
|
345
393
|
when?: (error: Error) => boolean;
|
|
346
394
|
}
|
|
347
395
|
type JobPriority = "critical" | "high" | "normal" | "low";
|
|
@@ -366,10 +414,30 @@ interface JobPrimitiveOptions<T extends TSchema = TSchema> extends PipelinePrimi
|
|
|
366
414
|
*/
|
|
367
415
|
cron?: string;
|
|
368
416
|
/**
|
|
369
|
-
* Retry policy for queue-mode jobs.
|
|
417
|
+
* Retry policy for queue-mode and direct-mode jobs.
|
|
370
418
|
* Cron-mode jobs do not retry — the next tick re-runs.
|
|
419
|
+
*
|
|
420
|
+
* Retries are picked up by the reconciliation sweep, so retry granularity
|
|
421
|
+
* is bounded by `sweepCron` (default 5 minutes). The first retry may run
|
|
422
|
+
* earlier than 5 minutes if the sweep tick happens sooner.
|
|
371
423
|
*/
|
|
372
424
|
retry?: JobRetryOptions;
|
|
425
|
+
/**
|
|
426
|
+
* **Cron-mode only.** Whether to acquire a distributed lock around the
|
|
427
|
+
* cron tick so that only one instance of a multi-replica deployment runs
|
|
428
|
+
* the handler per tick.
|
|
429
|
+
*
|
|
430
|
+
* Has **no effect** on queue-mode and direct-mode jobs — those rely on
|
|
431
|
+
* the outbox `claim()` UPDATE-guard to serialize work instead, which is
|
|
432
|
+
* always on.
|
|
433
|
+
*
|
|
434
|
+
* To get cross-instance coordination on Docker / Node deployments,
|
|
435
|
+
* register a real `LockProvider` (e.g. `alepha/lock/redis`). The default
|
|
436
|
+
* `MemoryLockProvider` is per-process only.
|
|
437
|
+
*
|
|
438
|
+
* @default true
|
|
439
|
+
*/
|
|
440
|
+
lock?: boolean;
|
|
373
441
|
/**
|
|
374
442
|
* Max execution time per attempt. Handler receives an `AbortSignal`.
|
|
375
443
|
*/
|
|
@@ -433,6 +501,52 @@ declare class JobPrimitive<T extends TSchema = TSchema> extends PipelinePrimitiv
|
|
|
433
501
|
trigger(context?: JobTriggerContext<T>): Promise<void>;
|
|
434
502
|
}
|
|
435
503
|
//#endregion
|
|
504
|
+
//#region ../../src/api/jobs/providers/JobDispatcher.d.ts
|
|
505
|
+
/**
|
|
506
|
+
* Abstract dispatcher for queued/direct job executions.
|
|
507
|
+
*
|
|
508
|
+
* The default implementation, {@link DirectJobDispatcher}, runs the handler
|
|
509
|
+
* in-process after the caller's `push()` returns — fast and dependency-free.
|
|
510
|
+
*
|
|
511
|
+
* `AlephaApiJobsQueue` substitutes this with `JobQueueProvider`, which
|
|
512
|
+
* publishes the executionId to `AlephaQueue` so a worker pool can consume
|
|
513
|
+
* the work asynchronously.
|
|
514
|
+
*
|
|
515
|
+
* Substitute via DI:
|
|
516
|
+
* ```ts
|
|
517
|
+
* Alepha.create()
|
|
518
|
+
* .with({ provide: JobDispatcher, use: MyCustomDispatcher })
|
|
519
|
+
* .with(AlephaApiJobs);
|
|
520
|
+
* ```
|
|
521
|
+
*
|
|
522
|
+
* The `kind` getter is read by the `JobProvider.effectiveMode` accessor
|
|
523
|
+
* and by the admin UI so users can see which dispatcher is currently active.
|
|
524
|
+
*/
|
|
525
|
+
declare abstract class JobDispatcher {
|
|
526
|
+
/**
|
|
527
|
+
* Identifier for this dispatcher's effective mode. Reported to the admin
|
|
528
|
+
* UI so operators can see whether `$job` is running in `queue` or
|
|
529
|
+
* `direct` mode.
|
|
530
|
+
*/
|
|
531
|
+
abstract readonly kind: "queue" | "direct";
|
|
532
|
+
/**
|
|
533
|
+
* Hand off a single execution. The caller's `push()` awaits this so the
|
|
534
|
+
* caller can be sure the dispatch has at least been initiated. Long-running
|
|
535
|
+
* work must NOT be awaited here (use background scheduling instead) — this
|
|
536
|
+
* call should return as quickly as possible.
|
|
537
|
+
*/
|
|
538
|
+
abstract dispatch(jobName: string, executionId: string): Promise<void>;
|
|
539
|
+
/**
|
|
540
|
+
* Optional batch dispatch. The default implementation loops, but
|
|
541
|
+
* dispatchers backed by a real queue should override this to use the
|
|
542
|
+
* provider's batch send (e.g. Cloudflare Queues `sendBatch`).
|
|
543
|
+
*/
|
|
544
|
+
dispatchMany(items: Array<{
|
|
545
|
+
jobName: string;
|
|
546
|
+
executionId: string;
|
|
547
|
+
}>): Promise<void>;
|
|
548
|
+
}
|
|
549
|
+
//#endregion
|
|
436
550
|
//#region ../../src/api/jobs/providers/JobProvider.d.ts
|
|
437
551
|
declare const PRIORITY_MAP: Record<JobPriority, number>;
|
|
438
552
|
declare const PRIORITY_REVERSE: Record<number, JobPriority>;
|
|
@@ -460,34 +574,59 @@ interface CancelContext {
|
|
|
460
574
|
cancelledBy?: string;
|
|
461
575
|
cancelledByName?: string;
|
|
462
576
|
}
|
|
577
|
+
/**
|
|
578
|
+
* The declared shape of the job (set at registration time).
|
|
579
|
+
*
|
|
580
|
+
* **Important** — this `kind` is the *declared* form. The *effective*
|
|
581
|
+
* runtime mode (cron / queue / direct) is exposed by
|
|
582
|
+
* `JobProvider.effectiveMode(name)` and the `JobRegistration.type` field on
|
|
583
|
+
* the admin schema. Don't conflate the two: a `queue` kind can run as
|
|
584
|
+
* `direct` at runtime when no queue dispatcher is loaded.
|
|
585
|
+
*/
|
|
463
586
|
interface JobRuntimeRegistration {
|
|
464
587
|
name: string;
|
|
465
588
|
options: JobPrimitiveOptions;
|
|
466
|
-
|
|
589
|
+
kind: "cron" | "queue";
|
|
467
590
|
}
|
|
591
|
+
type JobEffectiveMode = "cron" | "queue" | "direct";
|
|
468
592
|
/**
|
|
469
|
-
* Coordinates cron
|
|
470
|
-
*
|
|
593
|
+
* Coordinates cron and push jobs with a durable outbox table and a single
|
|
594
|
+
* reconciliation sweep. The actual delivery channel (queue / direct) is
|
|
595
|
+
* abstracted behind {@link JobDispatcher}, substituted by DI:
|
|
596
|
+
*
|
|
597
|
+
* - **DirectJobDispatcher** (default, registered by `AlephaApiJobs`) —
|
|
598
|
+
* runs the handler in-process right after `push()` returns.
|
|
599
|
+
* - **QueueJobDispatcher** (registered by `AlephaApiJobsQueue`) — sends
|
|
600
|
+
* the executionId through `AlephaQueue` so a pool of workers can pick
|
|
601
|
+
* it up.
|
|
471
602
|
*
|
|
472
|
-
*
|
|
473
|
-
* push() → INSERT row (pending)
|
|
474
|
-
* worker →
|
|
603
|
+
* Push flow:
|
|
604
|
+
* push() → INSERT row (pending) → dispatcher.dispatch(jobName, id)
|
|
605
|
+
* worker → claim → UPDATE running → handler → DELETE/UPDATE on success
|
|
606
|
+
* → UPDATE error / scheduled (retry) on failure
|
|
475
607
|
*
|
|
476
|
-
* Cron
|
|
477
|
-
* scheduler tick →
|
|
608
|
+
* Cron flow:
|
|
609
|
+
* scheduler tick → acquire lock → executeInline (no retry)
|
|
610
|
+
* → enqueue + dispatch (retry declared)
|
|
478
611
|
*
|
|
479
|
-
* Sweep responsibilities (every `
|
|
612
|
+
* Sweep responsibilities (every `sweepCron`):
|
|
480
613
|
* - re-enqueue pending rows older than `staleThreshold`
|
|
481
|
-
* -
|
|
482
|
-
* - move `scheduled` rows with `scheduledAt <= now` to pending +
|
|
483
|
-
*
|
|
614
|
+
* - mark crashed running rows as failed and apply retry policy
|
|
615
|
+
* - move `scheduled` rows with `scheduledAt <= now` to pending + dispatch
|
|
616
|
+
*
|
|
617
|
+
* Trim runs on its own cron (`trimCron`, default hourly):
|
|
618
|
+
* - per-job history trimmed beyond `keepLastSuccess` / `keepLastError`
|
|
619
|
+
* - decoupled from sweep because trim cost scales with job count, not
|
|
620
|
+
* retry latency — running it every sweep is wasted work for most apps.
|
|
484
621
|
*/
|
|
485
622
|
declare class JobProvider {
|
|
486
623
|
protected readonly alepha: Alepha;
|
|
487
624
|
protected readonly dt: DateTimeProvider;
|
|
488
625
|
protected readonly cronProvider: CronProvider;
|
|
626
|
+
protected readonly lockProvider: LockProvider;
|
|
489
627
|
protected readonly config: Readonly<{
|
|
490
|
-
|
|
628
|
+
sweepCron: string;
|
|
629
|
+
trimCron: string;
|
|
491
630
|
staleThreshold: number;
|
|
492
631
|
runTimeout: number;
|
|
493
632
|
keepLastSuccess: number;
|
|
@@ -495,36 +634,45 @@ declare class JobProvider {
|
|
|
495
634
|
logMaxEntries: number;
|
|
496
635
|
drainTimeout: number;
|
|
497
636
|
}>;
|
|
637
|
+
/**
|
|
638
|
+
* Resolved at first use (after the container is fully wired) — picks
|
|
639
|
+
* the queue dispatcher when `AlephaApiJobsQueue` was loaded, otherwise
|
|
640
|
+
* the direct dispatcher. Lazy because both dispatchers inject
|
|
641
|
+
* `JobProvider` themselves; resolving them at field-init time would
|
|
642
|
+
* create a circular construction.
|
|
643
|
+
*/
|
|
644
|
+
protected dispatcherRef?: JobDispatcher;
|
|
645
|
+
get dispatcher(): JobDispatcher;
|
|
498
646
|
protected readonly log: _$alepha_logger0.Logger;
|
|
499
|
-
protected readonly executions: _$alepha_orm0.Repository<_$
|
|
500
|
-
id: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$
|
|
501
|
-
createdAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$
|
|
502
|
-
updatedAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$
|
|
503
|
-
jobName: _$
|
|
504
|
-
key: _$
|
|
505
|
-
status: _$alepha_orm0.PgAttr<_$
|
|
506
|
-
priority: _$alepha_orm0.PgAttr<_$
|
|
507
|
-
attempt: _$alepha_orm0.PgAttr<_$
|
|
508
|
-
maxAttempts: _$alepha_orm0.PgAttr<_$
|
|
509
|
-
payload: _$
|
|
510
|
-
scheduledAt: _$
|
|
511
|
-
startedAt: _$
|
|
512
|
-
completedAt: _$
|
|
513
|
-
error: _$
|
|
514
|
-
logs: _$
|
|
515
|
-
level: _$
|
|
516
|
-
message: _$
|
|
517
|
-
service: _$
|
|
518
|
-
module: _$
|
|
519
|
-
context: _$
|
|
520
|
-
app: _$
|
|
521
|
-
data: _$
|
|
522
|
-
timestamp: _$
|
|
647
|
+
protected readonly executions: _$alepha_orm0.Repository<_$typebox.TObject<{
|
|
648
|
+
id: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_PRIMARY_KEY>, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
649
|
+
createdAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_CREATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
650
|
+
updatedAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_UPDATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
651
|
+
jobName: _$typebox.TString;
|
|
652
|
+
key: _$typebox.TOptional<_$typebox.TUnion<[_$typebox.TNull, _$typebox.TString]>>;
|
|
653
|
+
status: _$alepha_orm0.PgAttr<_$typebox.TUnsafe<"pending" | "running" | "scheduled" | "ok" | "error" | "cancelled">, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
654
|
+
priority: _$alepha_orm0.PgAttr<_$typebox.TInteger, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
655
|
+
attempt: _$alepha_orm0.PgAttr<_$typebox.TInteger, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
656
|
+
maxAttempts: _$alepha_orm0.PgAttr<_$typebox.TInteger, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
657
|
+
payload: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
|
|
658
|
+
scheduledAt: _$typebox.TOptional<_$typebox.TString>;
|
|
659
|
+
startedAt: _$typebox.TOptional<_$typebox.TString>;
|
|
660
|
+
completedAt: _$typebox.TOptional<_$typebox.TString>;
|
|
661
|
+
error: _$typebox.TOptional<_$typebox.TString>;
|
|
662
|
+
logs: _$typebox.TOptional<_$typebox.TArray<_$typebox.TObject<{
|
|
663
|
+
level: _$typebox.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
|
|
664
|
+
message: _$typebox.TString;
|
|
665
|
+
service: _$typebox.TString;
|
|
666
|
+
module: _$typebox.TString;
|
|
667
|
+
context: _$typebox.TOptional<_$typebox.TString>;
|
|
668
|
+
app: _$typebox.TOptional<_$typebox.TString>;
|
|
669
|
+
data: _$typebox.TOptional<_$typebox.TAny>;
|
|
670
|
+
timestamp: _$typebox.TNumber;
|
|
523
671
|
}>>>;
|
|
524
|
-
triggeredBy: _$
|
|
525
|
-
triggeredByName: _$
|
|
526
|
-
cancelledBy: _$
|
|
527
|
-
cancelledByName: _$
|
|
672
|
+
triggeredBy: _$typebox.TOptional<_$typebox.TString>;
|
|
673
|
+
triggeredByName: _$typebox.TOptional<_$typebox.TString>;
|
|
674
|
+
cancelledBy: _$typebox.TOptional<_$typebox.TString>;
|
|
675
|
+
cancelledByName: _$typebox.TOptional<_$typebox.TString>;
|
|
528
676
|
}>>;
|
|
529
677
|
protected readonly jobs: Map<string, JobRuntimeRegistration>;
|
|
530
678
|
protected readonly inFlight: Set<Promise<void>>;
|
|
@@ -540,14 +688,75 @@ declare class JobProvider {
|
|
|
540
688
|
timestamp: number;
|
|
541
689
|
}[]>;
|
|
542
690
|
protected stopping: boolean;
|
|
543
|
-
/**
|
|
544
|
-
* Set by `JobQueueProvider` when `AlephaApiJobsQueue` is loaded.
|
|
545
|
-
* When null, queue-mode jobs cannot be pushed.
|
|
546
|
-
*/
|
|
547
|
-
queueDispatch: ((jobName: string, executionId: string) => Promise<void>) | null;
|
|
548
691
|
registerJob(name: string, options: JobPrimitiveOptions): void;
|
|
549
692
|
getRegisteredJobs(): Map<string, JobRuntimeRegistration>;
|
|
693
|
+
/**
|
|
694
|
+
* Resolves what *actually* runs at dispatch time. Cron jobs are always
|
|
695
|
+
* "cron"; non-cron jobs delegate to the active `JobDispatcher` (queue
|
|
696
|
+
* vs. direct), which is determined by which modules the app loaded.
|
|
697
|
+
*/
|
|
698
|
+
effectiveMode(name: string): JobEffectiveMode;
|
|
550
699
|
protected runCron(name: string): Promise<void>;
|
|
700
|
+
/**
|
|
701
|
+
* Cron-mode runner that respects the per-job distributed lock.
|
|
702
|
+
* Used by both the scheduled tick and manual `trigger()` calls so that an
|
|
703
|
+
* admin-triggered run on one instance can't race a scheduled run on another.
|
|
704
|
+
*
|
|
705
|
+
* **Two paths depending on `retry`:**
|
|
706
|
+
*
|
|
707
|
+
* - **No `retry`** — runs the handler inline. No DB row on success;
|
|
708
|
+
* error row only on failure. The "next tick" is the implicit retry.
|
|
709
|
+
* - **`retry` declared** — enqueues a synthetic execution row and hands
|
|
710
|
+
* it to the dispatcher. The handler then runs through the same path
|
|
711
|
+
* as a queue/direct push (claim, retry-on-fail, sweep recovery). Use
|
|
712
|
+
* this when a single failed tick must not block work for the whole
|
|
713
|
+
* `cron` interval (e.g. once-daily jobs).
|
|
714
|
+
*/
|
|
715
|
+
protected runCronLocked(registration: JobRuntimeRegistration, ctx: {
|
|
716
|
+
triggeredBy?: string;
|
|
717
|
+
triggeredByName?: string;
|
|
718
|
+
}): Promise<void>;
|
|
719
|
+
/**
|
|
720
|
+
* Materialize a cron tick into the outbox so it goes through the normal
|
|
721
|
+
* retry/sweep path. Used when the user opts into `retry` on a cron job —
|
|
722
|
+
* a transient failure no longer means "wait for the next cron tick", it
|
|
723
|
+
* means "the sweep will retry within `sweepCron`".
|
|
724
|
+
*/
|
|
725
|
+
protected enqueueCronExecution(registration: JobRuntimeRegistration, ctx: {
|
|
726
|
+
triggeredBy?: string;
|
|
727
|
+
triggeredByName?: string;
|
|
728
|
+
}): Promise<void>;
|
|
729
|
+
/**
|
|
730
|
+
* Acquire a per-job NX lock keyed by `cron-job:<name>` so that a single
|
|
731
|
+
* tick across all replicas runs exactly one execution. Auto-expires after
|
|
732
|
+
* `2 * timeout` (or 5 minutes if no per-job timeout) so a crashed worker
|
|
733
|
+
* cannot permanently block the cron from firing.
|
|
734
|
+
*
|
|
735
|
+
* **Caveat — same-process double-fire is not prevented.** The lock value
|
|
736
|
+
* is a per-process holder id, so two concurrent ticks on the same process
|
|
737
|
+
* (e.g. a scheduled tick overlapping an admin `trigger()` call) will both
|
|
738
|
+
* see "we own it". This is acceptable for the multi-replica use case the
|
|
739
|
+
* lock targets; a process that overlaps its own cron handler should set a
|
|
740
|
+
* smaller `timeout` or use idempotent handler logic. A future fix can add
|
|
741
|
+
* a per-process Set guard before reaching the LockProvider.
|
|
742
|
+
*/
|
|
743
|
+
protected acquireCronLock(registration: JobRuntimeRegistration): Promise<boolean>;
|
|
744
|
+
/**
|
|
745
|
+
* Update only when the row is still in one of the expected statuses.
|
|
746
|
+
* Logs and returns silently when the guard rejects — this happens when a
|
|
747
|
+
* concurrent operation (most often `cancel()`) has already moved the row
|
|
748
|
+
* into a terminal state. We must not overwrite that.
|
|
749
|
+
*/
|
|
750
|
+
protected guardedUpdate(executionId: string, expectedStatuses: JobStatus[], patch: Parameters<typeof this.executions.updateById>[1], label: string): Promise<void>;
|
|
751
|
+
protected releaseCronLock(registration: JobRuntimeRegistration): Promise<void>;
|
|
752
|
+
protected cronLockKey(jobName: string): string;
|
|
753
|
+
/**
|
|
754
|
+
* Stable per-process id used as the lock value — survives multiple ticks.
|
|
755
|
+
* Lazy so that Cloudflare Workers (which forbid random in global scope)
|
|
756
|
+
* stay happy.
|
|
757
|
+
*/
|
|
758
|
+
protected lockHolderIdValue?: string;
|
|
759
|
+
protected get lockHolderId(): string;
|
|
551
760
|
/**
|
|
552
761
|
* Execute a cron handler inline. Records a row only on error (or always,
|
|
553
762
|
* when `record: 'all'`). No DB writes on the happy path by default.
|
|
@@ -576,17 +785,65 @@ declare class JobProvider {
|
|
|
576
785
|
*/
|
|
577
786
|
protected scheduleOptimisticDispatch(jobName: string, executionId: string, scheduledAt: string): void;
|
|
578
787
|
pushMany(name: string, items: Array<PushManyItem>): Promise<string[]>;
|
|
579
|
-
|
|
788
|
+
/**
|
|
789
|
+
* Hand a single execution to the active `JobDispatcher`. Whether that
|
|
790
|
+
* results in a queue send or in-process execution depends on which
|
|
791
|
+
* dispatcher is wired (see {@link JobDispatcher}).
|
|
792
|
+
*/
|
|
793
|
+
protected dispatch(jobName: string, executionId: string): Promise<void>;
|
|
794
|
+
/**
|
|
795
|
+
* Batched variant. Used by `pushMany` so a backing queue can do a single
|
|
796
|
+
* batch network call (e.g. Cloudflare Queues `sendBatch`).
|
|
797
|
+
*/
|
|
798
|
+
protected dispatchMany(items: Array<{
|
|
799
|
+
jobName: string;
|
|
800
|
+
executionId: string;
|
|
801
|
+
}>): Promise<void>;
|
|
580
802
|
trigger(name: string, context?: JobTriggerContext): Promise<void>;
|
|
581
803
|
cancel(executionId: string, context?: CancelContext): Promise<void>;
|
|
582
804
|
processExecution(jobName: string, executionId: string): Promise<void>;
|
|
583
805
|
protected processQueueExecution(registration: JobRuntimeRegistration, executionId: string): Promise<void>;
|
|
584
|
-
|
|
806
|
+
/**
|
|
807
|
+
* Transition pending → running and return the post-update row.
|
|
808
|
+
* Two round-trips: read current attempt, then guarded UPDATE … RETURNING.
|
|
809
|
+
* Returns null when the row is gone or already claimed by another worker.
|
|
810
|
+
* The returned row replaces a separate post-claim findById, so the dispatch
|
|
811
|
+
* path is 2 queries instead of 3.
|
|
812
|
+
*/
|
|
813
|
+
protected claim(executionId: string): Promise<{
|
|
814
|
+
key?: string | null | undefined;
|
|
815
|
+
error?: string | undefined;
|
|
816
|
+
payload?: Record<string, any> | undefined;
|
|
817
|
+
scheduledAt?: string | undefined;
|
|
818
|
+
startedAt?: string | undefined;
|
|
819
|
+
completedAt?: string | undefined;
|
|
820
|
+
logs?: {
|
|
821
|
+
context?: string | undefined;
|
|
822
|
+
app?: string | undefined;
|
|
823
|
+
data?: any;
|
|
824
|
+
level: "SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
825
|
+
message: string;
|
|
826
|
+
service: string;
|
|
827
|
+
module: string;
|
|
828
|
+
timestamp: number;
|
|
829
|
+
}[] | undefined;
|
|
830
|
+
triggeredBy?: string | undefined;
|
|
831
|
+
triggeredByName?: string | undefined;
|
|
832
|
+
cancelledBy?: string | undefined;
|
|
833
|
+
cancelledByName?: string | undefined;
|
|
834
|
+
jobName: string;
|
|
835
|
+
id: string;
|
|
836
|
+
createdAt: string;
|
|
837
|
+
updatedAt: string;
|
|
838
|
+
status: "pending" | "running" | "scheduled" | "ok" | "error" | "cancelled";
|
|
839
|
+
priority: number;
|
|
840
|
+
attempt: number;
|
|
841
|
+
maxAttempts: number;
|
|
842
|
+
} | null>;
|
|
585
843
|
protected handleFailure(executionId: string, registration: JobRuntimeRegistration, currentAttempt: number, error: Error, contextId: string): Promise<void>;
|
|
586
|
-
protected computeBackoff(retry: JobRetryOptions, attempt: number): string;
|
|
587
844
|
protected snapshotLogs(contextId: string): LogEntry[] | undefined;
|
|
588
845
|
protected sweep(): Promise<void>;
|
|
589
|
-
protected
|
|
846
|
+
protected dispatchSafe(jobName: string, executionId: string): Promise<void>;
|
|
590
847
|
/**
|
|
591
848
|
* Move a row from `scheduled` → `pending` and dispatch it.
|
|
592
849
|
* Used by the optimistic retry/delay timer. If the sweep has already moved
|
|
@@ -601,28 +858,74 @@ declare class JobProvider {
|
|
|
601
858
|
}
|
|
602
859
|
//#endregion
|
|
603
860
|
//#region ../../src/api/jobs/schemas/jobExecutionQuerySchema.d.ts
|
|
604
|
-
declare const jobExecutionQuerySchema: _$
|
|
605
|
-
status: _$
|
|
606
|
-
limit: _$
|
|
861
|
+
declare const jobExecutionQuerySchema: _$typebox.TObject<{
|
|
862
|
+
status: _$typebox.TOptional<_$typebox.TUnsafe<"pending" | "running" | "scheduled" | "ok" | "error" | "cancelled">>;
|
|
863
|
+
limit: _$typebox.TOptional<_$typebox.TInteger>;
|
|
607
864
|
}>;
|
|
608
865
|
type JobExecutionQuery = Static<typeof jobExecutionQuerySchema>;
|
|
609
866
|
//#endregion
|
|
867
|
+
//#region ../../src/api/jobs/schemas/jobExecutionResourceSchema.d.ts
|
|
868
|
+
/**
|
|
869
|
+
* Public-facing schema for a job execution row.
|
|
870
|
+
*
|
|
871
|
+
* Diverges from the raw entity in two places, both for API ergonomics:
|
|
872
|
+
*
|
|
873
|
+
* - `priority` is exposed as the **string enum** (`critical`/`high`/...)
|
|
874
|
+
* instead of the numeric value used internally for SQL ordering. The
|
|
875
|
+
* `JobService` is responsible for the int → string transform.
|
|
876
|
+
* - `can` derives the available admin actions from the row's status.
|
|
877
|
+
*/
|
|
878
|
+
declare const jobExecutionResourceSchema: _$typebox.TObject<{
|
|
879
|
+
id: PgAttr<PgAttr<_$typebox.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
|
|
880
|
+
createdAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
|
|
881
|
+
updatedAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
|
|
882
|
+
jobName: _$typebox.TString;
|
|
883
|
+
key: _$typebox.TOptional<_$typebox.TUnion<[_$typebox.TNull, _$typebox.TString]>>;
|
|
884
|
+
status: PgAttr<_$typebox.TUnsafe<"pending" | "running" | "scheduled" | "ok" | "error" | "cancelled">, typeof PG_DEFAULT>;
|
|
885
|
+
priority: PgAttr<_$typebox.TInteger, typeof PG_DEFAULT>;
|
|
886
|
+
attempt: PgAttr<_$typebox.TInteger, typeof PG_DEFAULT>;
|
|
887
|
+
maxAttempts: PgAttr<_$typebox.TInteger, typeof PG_DEFAULT>;
|
|
888
|
+
payload: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
|
|
889
|
+
scheduledAt: _$typebox.TOptional<_$typebox.TString>;
|
|
890
|
+
startedAt: _$typebox.TOptional<_$typebox.TString>;
|
|
891
|
+
completedAt: _$typebox.TOptional<_$typebox.TString>;
|
|
892
|
+
error: _$typebox.TOptional<_$typebox.TString>;
|
|
893
|
+
logs: _$typebox.TOptional<_$typebox.TArray<_$typebox.TObject<{
|
|
894
|
+
level: _$typebox.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
|
|
895
|
+
message: _$typebox.TString;
|
|
896
|
+
service: _$typebox.TString;
|
|
897
|
+
module: _$typebox.TString;
|
|
898
|
+
context: _$typebox.TOptional<_$typebox.TString>;
|
|
899
|
+
app: _$typebox.TOptional<_$typebox.TString>;
|
|
900
|
+
data: _$typebox.TOptional<_$typebox.TAny>;
|
|
901
|
+
timestamp: _$typebox.TNumber;
|
|
902
|
+
}>>>;
|
|
903
|
+
triggeredBy: _$typebox.TOptional<_$typebox.TString>;
|
|
904
|
+
triggeredByName: _$typebox.TOptional<_$typebox.TString>;
|
|
905
|
+
cancelledBy: _$typebox.TOptional<_$typebox.TString>;
|
|
906
|
+
cancelledByName: _$typebox.TOptional<_$typebox.TString>;
|
|
907
|
+
can: _$typebox.TObject<{
|
|
908
|
+
retry: _$typebox.TBoolean;
|
|
909
|
+
cancel: _$typebox.TBoolean;
|
|
910
|
+
}>;
|
|
911
|
+
}>;
|
|
912
|
+
type JobExecutionResource = Static<typeof jobExecutionResourceSchema>;
|
|
913
|
+
//#endregion
|
|
610
914
|
//#region ../../src/api/jobs/schemas/jobRegistrationSchema.d.ts
|
|
611
|
-
declare const jobRegistrationSchema: _$
|
|
612
|
-
name: _$
|
|
613
|
-
description: _$
|
|
614
|
-
type: _$
|
|
615
|
-
priority: _$
|
|
616
|
-
cron: _$
|
|
617
|
-
timeout: _$
|
|
618
|
-
retry: _$
|
|
619
|
-
retries: _$
|
|
620
|
-
hasBackoff: _$alepha.TBoolean;
|
|
915
|
+
declare const jobRegistrationSchema: _$typebox.TObject<{
|
|
916
|
+
name: _$typebox.TString;
|
|
917
|
+
description: _$typebox.TOptional<_$typebox.TString>;
|
|
918
|
+
type: _$typebox.TUnsafe<"queue" | "direct" | "cron">;
|
|
919
|
+
priority: _$typebox.TUnsafe<"critical" | "high" | "normal" | "low">;
|
|
920
|
+
cron: _$typebox.TOptional<_$typebox.TString>;
|
|
921
|
+
timeout: _$typebox.TOptional<_$typebox.TString>;
|
|
922
|
+
retry: _$typebox.TOptional<_$typebox.TObject<{
|
|
923
|
+
retries: _$typebox.TInteger;
|
|
621
924
|
}>>;
|
|
622
|
-
recent: _$
|
|
623
|
-
ok: _$
|
|
624
|
-
error: _$
|
|
625
|
-
lastRun: _$
|
|
925
|
+
recent: _$typebox.TObject<{
|
|
926
|
+
ok: _$typebox.TInteger;
|
|
927
|
+
error: _$typebox.TInteger;
|
|
928
|
+
lastRun: _$typebox.TOptional<_$typebox.TString>;
|
|
626
929
|
}>;
|
|
627
930
|
}>;
|
|
628
931
|
type JobRegistration = Static<typeof jobRegistrationSchema>;
|
|
@@ -640,40 +943,50 @@ declare class JobService {
|
|
|
640
943
|
protected readonly alepha: Alepha;
|
|
641
944
|
protected readonly log: _$alepha_logger0.Logger;
|
|
642
945
|
protected readonly jobProvider: JobProvider;
|
|
643
|
-
protected readonly executions: _$alepha_orm0.Repository<_$
|
|
644
|
-
id: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$
|
|
645
|
-
createdAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$
|
|
646
|
-
updatedAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$
|
|
647
|
-
jobName: _$
|
|
648
|
-
key: _$
|
|
649
|
-
status: _$alepha_orm0.PgAttr<_$
|
|
650
|
-
priority: _$alepha_orm0.PgAttr<_$
|
|
651
|
-
attempt: _$alepha_orm0.PgAttr<_$
|
|
652
|
-
maxAttempts: _$alepha_orm0.PgAttr<_$
|
|
653
|
-
payload: _$
|
|
654
|
-
scheduledAt: _$
|
|
655
|
-
startedAt: _$
|
|
656
|
-
completedAt: _$
|
|
657
|
-
error: _$
|
|
658
|
-
logs: _$
|
|
659
|
-
level: _$
|
|
660
|
-
message: _$
|
|
661
|
-
service: _$
|
|
662
|
-
module: _$
|
|
663
|
-
context: _$
|
|
664
|
-
app: _$
|
|
665
|
-
data: _$
|
|
666
|
-
timestamp: _$
|
|
946
|
+
protected readonly executions: _$alepha_orm0.Repository<_$typebox.TObject<{
|
|
947
|
+
id: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_PRIMARY_KEY>, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
948
|
+
createdAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_CREATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
949
|
+
updatedAt: _$alepha_orm0.PgAttr<_$alepha_orm0.PgAttr<_$typebox.TString, typeof _$alepha_orm0.PG_UPDATED_AT>, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
950
|
+
jobName: _$typebox.TString;
|
|
951
|
+
key: _$typebox.TOptional<_$typebox.TUnion<[_$typebox.TNull, _$typebox.TString]>>;
|
|
952
|
+
status: _$alepha_orm0.PgAttr<_$typebox.TUnsafe<"pending" | "running" | "scheduled" | "ok" | "error" | "cancelled">, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
953
|
+
priority: _$alepha_orm0.PgAttr<_$typebox.TInteger, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
954
|
+
attempt: _$alepha_orm0.PgAttr<_$typebox.TInteger, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
955
|
+
maxAttempts: _$alepha_orm0.PgAttr<_$typebox.TInteger, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
956
|
+
payload: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
|
|
957
|
+
scheduledAt: _$typebox.TOptional<_$typebox.TString>;
|
|
958
|
+
startedAt: _$typebox.TOptional<_$typebox.TString>;
|
|
959
|
+
completedAt: _$typebox.TOptional<_$typebox.TString>;
|
|
960
|
+
error: _$typebox.TOptional<_$typebox.TString>;
|
|
961
|
+
logs: _$typebox.TOptional<_$typebox.TArray<_$typebox.TObject<{
|
|
962
|
+
level: _$typebox.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
|
|
963
|
+
message: _$typebox.TString;
|
|
964
|
+
service: _$typebox.TString;
|
|
965
|
+
module: _$typebox.TString;
|
|
966
|
+
context: _$typebox.TOptional<_$typebox.TString>;
|
|
967
|
+
app: _$typebox.TOptional<_$typebox.TString>;
|
|
968
|
+
data: _$typebox.TOptional<_$typebox.TAny>;
|
|
969
|
+
timestamp: _$typebox.TNumber;
|
|
667
970
|
}>>>;
|
|
668
|
-
triggeredBy: _$
|
|
669
|
-
triggeredByName: _$
|
|
670
|
-
cancelledBy: _$
|
|
671
|
-
cancelledByName: _$
|
|
971
|
+
triggeredBy: _$typebox.TOptional<_$typebox.TString>;
|
|
972
|
+
triggeredByName: _$typebox.TOptional<_$typebox.TString>;
|
|
973
|
+
cancelledBy: _$typebox.TOptional<_$typebox.TString>;
|
|
974
|
+
cancelledByName: _$typebox.TOptional<_$typebox.TString>;
|
|
672
975
|
}>>;
|
|
673
976
|
protected computeCan(status: string): {
|
|
674
977
|
retry: boolean;
|
|
675
978
|
cancel: boolean;
|
|
676
979
|
};
|
|
980
|
+
/**
|
|
981
|
+
* Convert the int-priority storage column into the public enum string.
|
|
982
|
+
* The cast through `unknown` skips TypeScript's structural check between
|
|
983
|
+
* the entity-level row (`priority: number`) and the resource schema
|
|
984
|
+
* (`priority: enum`); the runtime values are correct.
|
|
985
|
+
*/
|
|
986
|
+
protected toResource<T extends {
|
|
987
|
+
priority: number;
|
|
988
|
+
status: string;
|
|
989
|
+
}>(row: T): JobExecutionResource;
|
|
677
990
|
/**
|
|
678
991
|
* List every registered job with recent ok/error counts and lastRun.
|
|
679
992
|
* One aggregate query covers all jobs.
|
|
@@ -683,10 +996,6 @@ declare class JobService {
|
|
|
683
996
|
* Recent executions for a single job, ORDER BY startedAt DESC.
|
|
684
997
|
*/
|
|
685
998
|
getExecutions(jobName: string, query?: JobExecutionQuery): Promise<{
|
|
686
|
-
can: {
|
|
687
|
-
retry: boolean;
|
|
688
|
-
cancel: boolean;
|
|
689
|
-
};
|
|
690
999
|
key?: string | null | undefined;
|
|
691
1000
|
error?: string | undefined;
|
|
692
1001
|
payload?: Record<string, any> | undefined;
|
|
@@ -707,23 +1016,23 @@ declare class JobService {
|
|
|
707
1016
|
triggeredByName?: string | undefined;
|
|
708
1017
|
cancelledBy?: string | undefined;
|
|
709
1018
|
cancelledByName?: string | undefined;
|
|
1019
|
+
jobName: string;
|
|
710
1020
|
id: string;
|
|
711
1021
|
createdAt: string;
|
|
712
1022
|
updatedAt: string;
|
|
713
|
-
jobName: string;
|
|
714
1023
|
status: "pending" | "running" | "scheduled" | "ok" | "error" | "cancelled";
|
|
715
1024
|
priority: number;
|
|
716
1025
|
attempt: number;
|
|
717
1026
|
maxAttempts: number;
|
|
1027
|
+
can: {
|
|
1028
|
+
retry: boolean;
|
|
1029
|
+
cancel: boolean;
|
|
1030
|
+
};
|
|
718
1031
|
}[]>;
|
|
719
1032
|
/**
|
|
720
1033
|
* Full execution detail (includes captured logs).
|
|
721
1034
|
*/
|
|
722
1035
|
getExecution(id: string): Promise<{
|
|
723
|
-
can: {
|
|
724
|
-
retry: boolean;
|
|
725
|
-
cancel: boolean;
|
|
726
|
-
};
|
|
727
1036
|
key?: string | null | undefined;
|
|
728
1037
|
error?: string | undefined;
|
|
729
1038
|
payload?: Record<string, any> | undefined;
|
|
@@ -744,14 +1053,18 @@ declare class JobService {
|
|
|
744
1053
|
triggeredByName?: string | undefined;
|
|
745
1054
|
cancelledBy?: string | undefined;
|
|
746
1055
|
cancelledByName?: string | undefined;
|
|
1056
|
+
jobName: string;
|
|
747
1057
|
id: string;
|
|
748
1058
|
createdAt: string;
|
|
749
1059
|
updatedAt: string;
|
|
750
|
-
jobName: string;
|
|
751
1060
|
status: "pending" | "running" | "scheduled" | "ok" | "error" | "cancelled";
|
|
752
1061
|
priority: number;
|
|
753
1062
|
attempt: number;
|
|
754
1063
|
maxAttempts: number;
|
|
1064
|
+
can: {
|
|
1065
|
+
retry: boolean;
|
|
1066
|
+
cancel: boolean;
|
|
1067
|
+
};
|
|
755
1068
|
}>;
|
|
756
1069
|
/**
|
|
757
1070
|
* Manual trigger (cron jobs) or push-with-payload (queue jobs).
|
|
@@ -785,220 +1098,218 @@ declare class AdminJobController {
|
|
|
785
1098
|
protected readonly group: string;
|
|
786
1099
|
protected readonly jobService: JobService;
|
|
787
1100
|
readonly listJobs: _$alepha_server0.ActionPrimitiveFn<{
|
|
788
|
-
response: _$
|
|
789
|
-
name: _$
|
|
790
|
-
description: _$
|
|
791
|
-
type: _$
|
|
792
|
-
priority: _$
|
|
793
|
-
cron: _$
|
|
794
|
-
timeout: _$
|
|
795
|
-
retry: _$
|
|
796
|
-
retries: _$
|
|
797
|
-
hasBackoff: _$alepha.TBoolean;
|
|
1101
|
+
response: _$typebox.TArray<_$typebox.TObject<{
|
|
1102
|
+
name: _$typebox.TString;
|
|
1103
|
+
description: _$typebox.TOptional<_$typebox.TString>;
|
|
1104
|
+
type: _$typebox.TUnsafe<"queue" | "direct" | "cron">;
|
|
1105
|
+
priority: _$typebox.TUnsafe<"critical" | "high" | "normal" | "low">;
|
|
1106
|
+
cron: _$typebox.TOptional<_$typebox.TString>;
|
|
1107
|
+
timeout: _$typebox.TOptional<_$typebox.TString>;
|
|
1108
|
+
retry: _$typebox.TOptional<_$typebox.TObject<{
|
|
1109
|
+
retries: _$typebox.TInteger;
|
|
798
1110
|
}>>;
|
|
799
|
-
recent: _$
|
|
800
|
-
ok: _$
|
|
801
|
-
error: _$
|
|
802
|
-
lastRun: _$
|
|
1111
|
+
recent: _$typebox.TObject<{
|
|
1112
|
+
ok: _$typebox.TInteger;
|
|
1113
|
+
error: _$typebox.TInteger;
|
|
1114
|
+
lastRun: _$typebox.TOptional<_$typebox.TString>;
|
|
803
1115
|
}>;
|
|
804
1116
|
}>>;
|
|
805
1117
|
}>;
|
|
806
1118
|
readonly listExecutions: _$alepha_server0.ActionPrimitiveFn<{
|
|
807
|
-
params: _$
|
|
808
|
-
name: _$
|
|
1119
|
+
params: _$typebox.TObject<{
|
|
1120
|
+
name: _$typebox.TString;
|
|
809
1121
|
}>;
|
|
810
|
-
query: _$
|
|
811
|
-
status: _$
|
|
812
|
-
limit: _$
|
|
1122
|
+
query: _$typebox.TObject<{
|
|
1123
|
+
status: _$typebox.TOptional<_$typebox.TUnsafe<"pending" | "running" | "scheduled" | "ok" | "error" | "cancelled">>;
|
|
1124
|
+
limit: _$typebox.TOptional<_$typebox.TInteger>;
|
|
813
1125
|
}>;
|
|
814
|
-
response: _$
|
|
815
|
-
id: PgAttr<PgAttr<_$
|
|
816
|
-
createdAt: PgAttr<PgAttr<_$
|
|
817
|
-
updatedAt: PgAttr<PgAttr<_$
|
|
818
|
-
jobName: _$
|
|
819
|
-
key: _$
|
|
820
|
-
status: PgAttr<_$
|
|
821
|
-
priority: PgAttr<_$
|
|
822
|
-
attempt: PgAttr<_$
|
|
823
|
-
maxAttempts: PgAttr<_$
|
|
824
|
-
payload: _$
|
|
825
|
-
scheduledAt: _$
|
|
826
|
-
startedAt: _$
|
|
827
|
-
completedAt: _$
|
|
828
|
-
error: _$
|
|
829
|
-
logs: _$
|
|
830
|
-
level: _$
|
|
831
|
-
message: _$
|
|
832
|
-
service: _$
|
|
833
|
-
module: _$
|
|
834
|
-
context: _$
|
|
835
|
-
app: _$
|
|
836
|
-
data: _$
|
|
837
|
-
timestamp: _$
|
|
1126
|
+
response: _$typebox.TArray<_$typebox.TObject<{
|
|
1127
|
+
id: PgAttr<PgAttr<_$typebox.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
|
|
1128
|
+
createdAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
|
|
1129
|
+
updatedAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
|
|
1130
|
+
jobName: _$typebox.TString;
|
|
1131
|
+
key: _$typebox.TOptional<_$typebox.TUnion<[_$typebox.TNull, _$typebox.TString]>>;
|
|
1132
|
+
status: PgAttr<_$typebox.TUnsafe<"pending" | "running" | "scheduled" | "ok" | "error" | "cancelled">, typeof PG_DEFAULT>;
|
|
1133
|
+
priority: PgAttr<_$typebox.TInteger, typeof PG_DEFAULT>;
|
|
1134
|
+
attempt: PgAttr<_$typebox.TInteger, typeof PG_DEFAULT>;
|
|
1135
|
+
maxAttempts: PgAttr<_$typebox.TInteger, typeof PG_DEFAULT>;
|
|
1136
|
+
payload: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
|
|
1137
|
+
scheduledAt: _$typebox.TOptional<_$typebox.TString>;
|
|
1138
|
+
startedAt: _$typebox.TOptional<_$typebox.TString>;
|
|
1139
|
+
completedAt: _$typebox.TOptional<_$typebox.TString>;
|
|
1140
|
+
error: _$typebox.TOptional<_$typebox.TString>;
|
|
1141
|
+
logs: _$typebox.TOptional<_$typebox.TArray<_$typebox.TObject<{
|
|
1142
|
+
level: _$typebox.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
|
|
1143
|
+
message: _$typebox.TString;
|
|
1144
|
+
service: _$typebox.TString;
|
|
1145
|
+
module: _$typebox.TString;
|
|
1146
|
+
context: _$typebox.TOptional<_$typebox.TString>;
|
|
1147
|
+
app: _$typebox.TOptional<_$typebox.TString>;
|
|
1148
|
+
data: _$typebox.TOptional<_$typebox.TAny>;
|
|
1149
|
+
timestamp: _$typebox.TNumber;
|
|
838
1150
|
}>>>;
|
|
839
|
-
triggeredBy: _$
|
|
840
|
-
triggeredByName: _$
|
|
841
|
-
cancelledBy: _$
|
|
842
|
-
cancelledByName: _$
|
|
843
|
-
can: _$
|
|
844
|
-
retry: _$
|
|
845
|
-
cancel: _$
|
|
1151
|
+
triggeredBy: _$typebox.TOptional<_$typebox.TString>;
|
|
1152
|
+
triggeredByName: _$typebox.TOptional<_$typebox.TString>;
|
|
1153
|
+
cancelledBy: _$typebox.TOptional<_$typebox.TString>;
|
|
1154
|
+
cancelledByName: _$typebox.TOptional<_$typebox.TString>;
|
|
1155
|
+
can: _$typebox.TObject<{
|
|
1156
|
+
retry: _$typebox.TBoolean;
|
|
1157
|
+
cancel: _$typebox.TBoolean;
|
|
846
1158
|
}>;
|
|
847
1159
|
}>>;
|
|
848
1160
|
}>;
|
|
849
1161
|
readonly getExecution: _$alepha_server0.ActionPrimitiveFn<{
|
|
850
|
-
params: _$
|
|
851
|
-
id: _$
|
|
1162
|
+
params: _$typebox.TObject<{
|
|
1163
|
+
id: _$typebox.TString;
|
|
852
1164
|
}>;
|
|
853
|
-
response: _$
|
|
854
|
-
id: PgAttr<PgAttr<_$
|
|
855
|
-
createdAt: PgAttr<PgAttr<_$
|
|
856
|
-
updatedAt: PgAttr<PgAttr<_$
|
|
857
|
-
jobName: _$
|
|
858
|
-
key: _$
|
|
859
|
-
status: PgAttr<_$
|
|
860
|
-
priority: PgAttr<_$
|
|
861
|
-
attempt: PgAttr<_$
|
|
862
|
-
maxAttempts: PgAttr<_$
|
|
863
|
-
payload: _$
|
|
864
|
-
scheduledAt: _$
|
|
865
|
-
startedAt: _$
|
|
866
|
-
completedAt: _$
|
|
867
|
-
error: _$
|
|
868
|
-
logs: _$
|
|
869
|
-
level: _$
|
|
870
|
-
message: _$
|
|
871
|
-
service: _$
|
|
872
|
-
module: _$
|
|
873
|
-
context: _$
|
|
874
|
-
app: _$
|
|
875
|
-
data: _$
|
|
876
|
-
timestamp: _$
|
|
1165
|
+
response: _$typebox.TObject<{
|
|
1166
|
+
id: PgAttr<PgAttr<_$typebox.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
|
|
1167
|
+
createdAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
|
|
1168
|
+
updatedAt: PgAttr<PgAttr<_$typebox.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
|
|
1169
|
+
jobName: _$typebox.TString;
|
|
1170
|
+
key: _$typebox.TOptional<_$typebox.TUnion<[_$typebox.TNull, _$typebox.TString]>>;
|
|
1171
|
+
status: PgAttr<_$typebox.TUnsafe<"pending" | "running" | "scheduled" | "ok" | "error" | "cancelled">, typeof PG_DEFAULT>;
|
|
1172
|
+
priority: PgAttr<_$typebox.TInteger, typeof PG_DEFAULT>;
|
|
1173
|
+
attempt: PgAttr<_$typebox.TInteger, typeof PG_DEFAULT>;
|
|
1174
|
+
maxAttempts: PgAttr<_$typebox.TInteger, typeof PG_DEFAULT>;
|
|
1175
|
+
payload: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
|
|
1176
|
+
scheduledAt: _$typebox.TOptional<_$typebox.TString>;
|
|
1177
|
+
startedAt: _$typebox.TOptional<_$typebox.TString>;
|
|
1178
|
+
completedAt: _$typebox.TOptional<_$typebox.TString>;
|
|
1179
|
+
error: _$typebox.TOptional<_$typebox.TString>;
|
|
1180
|
+
logs: _$typebox.TOptional<_$typebox.TArray<_$typebox.TObject<{
|
|
1181
|
+
level: _$typebox.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
|
|
1182
|
+
message: _$typebox.TString;
|
|
1183
|
+
service: _$typebox.TString;
|
|
1184
|
+
module: _$typebox.TString;
|
|
1185
|
+
context: _$typebox.TOptional<_$typebox.TString>;
|
|
1186
|
+
app: _$typebox.TOptional<_$typebox.TString>;
|
|
1187
|
+
data: _$typebox.TOptional<_$typebox.TAny>;
|
|
1188
|
+
timestamp: _$typebox.TNumber;
|
|
877
1189
|
}>>>;
|
|
878
|
-
triggeredBy: _$
|
|
879
|
-
triggeredByName: _$
|
|
880
|
-
cancelledBy: _$
|
|
881
|
-
cancelledByName: _$
|
|
882
|
-
can: _$
|
|
883
|
-
retry: _$
|
|
884
|
-
cancel: _$
|
|
1190
|
+
triggeredBy: _$typebox.TOptional<_$typebox.TString>;
|
|
1191
|
+
triggeredByName: _$typebox.TOptional<_$typebox.TString>;
|
|
1192
|
+
cancelledBy: _$typebox.TOptional<_$typebox.TString>;
|
|
1193
|
+
cancelledByName: _$typebox.TOptional<_$typebox.TString>;
|
|
1194
|
+
can: _$typebox.TObject<{
|
|
1195
|
+
retry: _$typebox.TBoolean;
|
|
1196
|
+
cancel: _$typebox.TBoolean;
|
|
885
1197
|
}>;
|
|
886
1198
|
}>;
|
|
887
1199
|
}>;
|
|
888
1200
|
readonly triggerJob: _$alepha_server0.ActionPrimitiveFn<{
|
|
889
|
-
params: _$
|
|
890
|
-
name: _$
|
|
1201
|
+
params: _$typebox.TObject<{
|
|
1202
|
+
name: _$typebox.TString;
|
|
891
1203
|
}>;
|
|
892
|
-
body: _$
|
|
893
|
-
payload: _$
|
|
1204
|
+
body: _$typebox.TObject<{
|
|
1205
|
+
payload: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
|
|
894
1206
|
}>;
|
|
895
|
-
response: _$
|
|
896
|
-
ok: _$
|
|
897
|
-
id: _$
|
|
898
|
-
count: _$
|
|
1207
|
+
response: _$typebox.TObject<{
|
|
1208
|
+
ok: _$typebox.TBoolean;
|
|
1209
|
+
id: _$typebox.TOptional<_$typebox.TUnion<[_$typebox.TString, _$typebox.TInteger]>>;
|
|
1210
|
+
count: _$typebox.TOptional<_$typebox.TNumber>;
|
|
899
1211
|
}>;
|
|
900
1212
|
}>;
|
|
901
1213
|
readonly retryExecution: _$alepha_server0.ActionPrimitiveFn<{
|
|
902
|
-
params: _$
|
|
903
|
-
id: _$
|
|
1214
|
+
params: _$typebox.TObject<{
|
|
1215
|
+
id: _$typebox.TString;
|
|
904
1216
|
}>;
|
|
905
|
-
response: _$
|
|
906
|
-
ok: _$
|
|
907
|
-
id: _$
|
|
908
|
-
count: _$
|
|
1217
|
+
response: _$typebox.TObject<{
|
|
1218
|
+
ok: _$typebox.TBoolean;
|
|
1219
|
+
id: _$typebox.TOptional<_$typebox.TUnion<[_$typebox.TString, _$typebox.TInteger]>>;
|
|
1220
|
+
count: _$typebox.TOptional<_$typebox.TNumber>;
|
|
909
1221
|
}>;
|
|
910
1222
|
}>;
|
|
911
1223
|
readonly cancelExecution: _$alepha_server0.ActionPrimitiveFn<{
|
|
912
|
-
params: _$
|
|
913
|
-
id: _$
|
|
1224
|
+
params: _$typebox.TObject<{
|
|
1225
|
+
id: _$typebox.TString;
|
|
914
1226
|
}>;
|
|
915
|
-
response: _$
|
|
916
|
-
ok: _$
|
|
917
|
-
id: _$
|
|
918
|
-
count: _$
|
|
1227
|
+
response: _$typebox.TObject<{
|
|
1228
|
+
ok: _$typebox.TBoolean;
|
|
1229
|
+
id: _$typebox.TOptional<_$typebox.TUnion<[_$typebox.TString, _$typebox.TInteger]>>;
|
|
1230
|
+
count: _$typebox.TOptional<_$typebox.TNumber>;
|
|
919
1231
|
}>;
|
|
920
1232
|
}>;
|
|
921
1233
|
}
|
|
922
1234
|
//#endregion
|
|
923
|
-
//#region ../../src/api/jobs/
|
|
1235
|
+
//#region ../../src/api/jobs/providers/DirectJobDispatcher.d.ts
|
|
924
1236
|
/**
|
|
925
|
-
*
|
|
1237
|
+
* Default `JobDispatcher` for environments without `AlephaApiJobsQueue`.
|
|
926
1238
|
*
|
|
927
|
-
*
|
|
928
|
-
*
|
|
929
|
-
* the
|
|
1239
|
+
* Runs `JobProvider.processExecution` in the background — the caller's
|
|
1240
|
+
* `push()` returns immediately while the handler continues to completion
|
|
1241
|
+
* in the same process. The DB outbox row is the durability guarantee:
|
|
1242
|
+
* if the process dies before the handler finishes, the next sweep tick
|
|
1243
|
+
* picks the row up and re-dispatches.
|
|
930
1244
|
*
|
|
931
|
-
*
|
|
932
|
-
*
|
|
933
|
-
*
|
|
934
|
-
*
|
|
935
|
-
*
|
|
936
|
-
*
|
|
937
|
-
*
|
|
938
|
-
* -
|
|
939
|
-
*
|
|
1245
|
+
* **Cloudflare Workers** — when an `executionCtx.waitUntil` is available
|
|
1246
|
+
* in the alepha store at `cloudflare.waitUntil`, the dispatch wraps the
|
|
1247
|
+
* background promise with `waitUntil` so the runtime keeps the isolate
|
|
1248
|
+
* alive past the HTTP response. Without this, the handler would be
|
|
1249
|
+
* terminated when the response is returned and only the next sweep
|
|
1250
|
+
* (every 5 min by default) would re-dispatch.
|
|
1251
|
+
*
|
|
1252
|
+
* **Vercel / single-Node** — on long-running runtimes the event loop
|
|
1253
|
+
* keeps the promise alive naturally; no special wiring is required.
|
|
940
1254
|
*/
|
|
941
|
-
declare
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
attempt: _$alepha_orm0.PgAttr<_$alepha.TInteger, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
950
|
-
maxAttempts: _$alepha_orm0.PgAttr<_$alepha.TInteger, typeof _$alepha_orm0.PG_DEFAULT>;
|
|
951
|
-
payload: _$alepha.TOptional<_$alepha.TRecord<"^.*$", _$alepha.TAny>>;
|
|
952
|
-
scheduledAt: _$alepha.TOptional<_$alepha.TString>;
|
|
953
|
-
startedAt: _$alepha.TOptional<_$alepha.TString>;
|
|
954
|
-
completedAt: _$alepha.TOptional<_$alepha.TString>;
|
|
955
|
-
error: _$alepha.TOptional<_$alepha.TString>;
|
|
956
|
-
logs: _$alepha.TOptional<_$alepha.TArray<_$alepha.TObject<{
|
|
957
|
-
level: _$alepha.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
|
|
958
|
-
message: _$alepha.TString;
|
|
959
|
-
service: _$alepha.TString;
|
|
960
|
-
module: _$alepha.TString;
|
|
961
|
-
context: _$alepha.TOptional<_$alepha.TString>;
|
|
962
|
-
app: _$alepha.TOptional<_$alepha.TString>;
|
|
963
|
-
data: _$alepha.TOptional<_$alepha.TAny>;
|
|
964
|
-
timestamp: _$alepha.TNumber;
|
|
965
|
-
}>>>;
|
|
966
|
-
triggeredBy: _$alepha.TOptional<_$alepha.TString>;
|
|
967
|
-
triggeredByName: _$alepha.TOptional<_$alepha.TString>;
|
|
968
|
-
cancelledBy: _$alepha.TOptional<_$alepha.TString>;
|
|
969
|
-
cancelledByName: _$alepha.TOptional<_$alepha.TString>;
|
|
970
|
-
}>>;
|
|
971
|
-
type JobExecutionEntity = Static<typeof jobExecutionEntity.schema>;
|
|
972
|
-
type JobStatus = "pending" | "running" | "scheduled" | "ok" | "error" | "cancelled";
|
|
1255
|
+
declare class DirectJobDispatcher extends JobDispatcher {
|
|
1256
|
+
readonly kind: "direct";
|
|
1257
|
+
protected readonly alepha: Alepha;
|
|
1258
|
+
protected readonly log: _$alepha_logger0.Logger;
|
|
1259
|
+
protected jobProviderRef?: JobProvider;
|
|
1260
|
+
protected getJobProvider(): JobProvider;
|
|
1261
|
+
dispatch(jobName: string, executionId: string): Promise<void>;
|
|
1262
|
+
}
|
|
973
1263
|
//#endregion
|
|
974
1264
|
//#region ../../src/api/jobs/providers/JobQueueProvider.d.ts
|
|
975
1265
|
/**
|
|
976
|
-
*
|
|
1266
|
+
* Queue-backed `JobDispatcher` registered by `AlephaApiJobsQueue`.
|
|
1267
|
+
*
|
|
1268
|
+
* Extends {@link JobDispatcher} and substitutes the default
|
|
1269
|
+
* `DirectJobDispatcher` so that `$job.push()` is delivered through
|
|
1270
|
+
* `AlephaQueue` (e.g. Cloudflare Queues, Redis, in-memory) instead of
|
|
1271
|
+
* being processed in-process.
|
|
977
1272
|
*
|
|
978
|
-
*
|
|
979
|
-
*
|
|
980
|
-
* can dispatch regardless of start-hook ordering.
|
|
1273
|
+
* The class is also kept as a `JobQueueProvider` export name for backwards
|
|
1274
|
+
* compatibility — it has always been the queue path's entry point.
|
|
981
1275
|
*/
|
|
982
|
-
declare class JobQueueProvider {
|
|
983
|
-
|
|
984
|
-
protected readonly
|
|
985
|
-
|
|
986
|
-
|
|
1276
|
+
declare class JobQueueProvider extends JobDispatcher {
|
|
1277
|
+
readonly kind: "queue";
|
|
1278
|
+
protected readonly alepha: Alepha;
|
|
1279
|
+
protected jobProviderRef?: JobProvider;
|
|
1280
|
+
protected getJobProvider(): JobProvider;
|
|
1281
|
+
protected readonly queue: _$alepha_queue0.QueuePrimitive<_$typebox.TObject<{
|
|
1282
|
+
jobName: _$typebox.TString;
|
|
1283
|
+
executionId: _$typebox.TString;
|
|
987
1284
|
}>>;
|
|
988
|
-
|
|
989
|
-
|
|
1285
|
+
dispatch(jobName: string, executionId: string): Promise<void>;
|
|
1286
|
+
/**
|
|
1287
|
+
* Fan-out to a single variadic `queue.push(...payloads)` call so the
|
|
1288
|
+
* underlying queue provider can batch the network round-trips when it
|
|
1289
|
+
* supports it (Cloudflare Queues, Redis pipelines).
|
|
1290
|
+
*/
|
|
1291
|
+
dispatchMany(items: Array<{
|
|
1292
|
+
jobName: string;
|
|
1293
|
+
executionId: string;
|
|
1294
|
+
}>): Promise<void>;
|
|
1295
|
+
/**
|
|
1296
|
+
* Backwards-compatible alias for {@link dispatch}. Older code paths called
|
|
1297
|
+
* `JobQueueProvider.push(jobName, executionId)` directly; new code should
|
|
1298
|
+
* go through the `JobDispatcher.dispatch` API.
|
|
1299
|
+
*/
|
|
990
1300
|
push(jobName: string, executionId: string): Promise<void>;
|
|
991
1301
|
}
|
|
992
1302
|
//#endregion
|
|
993
1303
|
//#region ../../src/api/jobs/schemas/jobConfigAtom.d.ts
|
|
994
|
-
declare const jobConfig: _$alepha.Atom<_$
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1304
|
+
declare const jobConfig: _$alepha.Atom<_$typebox.TObject<{
|
|
1305
|
+
sweepCron: _$typebox.TString;
|
|
1306
|
+
trimCron: _$typebox.TString;
|
|
1307
|
+
staleThreshold: _$typebox.TInteger;
|
|
1308
|
+
runTimeout: _$typebox.TInteger;
|
|
1309
|
+
keepLastSuccess: _$typebox.TInteger;
|
|
1310
|
+
keepLastError: _$typebox.TInteger;
|
|
1311
|
+
logMaxEntries: _$typebox.TInteger;
|
|
1312
|
+
drainTimeout: _$typebox.TInteger;
|
|
1002
1313
|
}>, "alepha.jobs">;
|
|
1003
1314
|
type JobConfig = Static<typeof jobConfig.schema>;
|
|
1004
1315
|
declare module "alepha" {
|
|
@@ -1007,46 +1318,9 @@ declare module "alepha" {
|
|
|
1007
1318
|
}
|
|
1008
1319
|
} //# sourceMappingURL=jobConfigAtom.d.ts.map
|
|
1009
1320
|
//#endregion
|
|
1010
|
-
//#region ../../src/api/jobs/schemas/jobExecutionResourceSchema.d.ts
|
|
1011
|
-
declare const jobExecutionResourceSchema: _$alepha.TObject<{
|
|
1012
|
-
id: PgAttr<PgAttr<_$alepha.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
|
|
1013
|
-
createdAt: PgAttr<PgAttr<_$alepha.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
|
|
1014
|
-
updatedAt: PgAttr<PgAttr<_$alepha.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
|
|
1015
|
-
jobName: _$alepha.TString;
|
|
1016
|
-
key: _$alepha.TOptional<_$alepha.TUnion<[_$alepha.TNull, _$alepha.TString]>>;
|
|
1017
|
-
status: PgAttr<_$alepha.TUnsafe<"pending" | "running" | "scheduled" | "ok" | "error" | "cancelled">, typeof PG_DEFAULT>;
|
|
1018
|
-
priority: PgAttr<_$alepha.TInteger, typeof PG_DEFAULT>;
|
|
1019
|
-
attempt: PgAttr<_$alepha.TInteger, typeof PG_DEFAULT>;
|
|
1020
|
-
maxAttempts: PgAttr<_$alepha.TInteger, typeof PG_DEFAULT>;
|
|
1021
|
-
payload: _$alepha.TOptional<_$alepha.TRecord<"^.*$", _$alepha.TAny>>;
|
|
1022
|
-
scheduledAt: _$alepha.TOptional<_$alepha.TString>;
|
|
1023
|
-
startedAt: _$alepha.TOptional<_$alepha.TString>;
|
|
1024
|
-
completedAt: _$alepha.TOptional<_$alepha.TString>;
|
|
1025
|
-
error: _$alepha.TOptional<_$alepha.TString>;
|
|
1026
|
-
logs: _$alepha.TOptional<_$alepha.TArray<_$alepha.TObject<{
|
|
1027
|
-
level: _$alepha.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
|
|
1028
|
-
message: _$alepha.TString;
|
|
1029
|
-
service: _$alepha.TString;
|
|
1030
|
-
module: _$alepha.TString;
|
|
1031
|
-
context: _$alepha.TOptional<_$alepha.TString>;
|
|
1032
|
-
app: _$alepha.TOptional<_$alepha.TString>;
|
|
1033
|
-
data: _$alepha.TOptional<_$alepha.TAny>;
|
|
1034
|
-
timestamp: _$alepha.TNumber;
|
|
1035
|
-
}>>>;
|
|
1036
|
-
triggeredBy: _$alepha.TOptional<_$alepha.TString>;
|
|
1037
|
-
triggeredByName: _$alepha.TOptional<_$alepha.TString>;
|
|
1038
|
-
cancelledBy: _$alepha.TOptional<_$alepha.TString>;
|
|
1039
|
-
cancelledByName: _$alepha.TOptional<_$alepha.TString>;
|
|
1040
|
-
can: _$alepha.TObject<{
|
|
1041
|
-
retry: _$alepha.TBoolean;
|
|
1042
|
-
cancel: _$alepha.TBoolean;
|
|
1043
|
-
}>;
|
|
1044
|
-
}>;
|
|
1045
|
-
type JobExecutionResource = Static<typeof jobExecutionResourceSchema>;
|
|
1046
|
-
//#endregion
|
|
1047
1321
|
//#region ../../src/api/jobs/schemas/triggerJobSchema.d.ts
|
|
1048
|
-
declare const triggerJobSchema: _$
|
|
1049
|
-
payload: _$
|
|
1322
|
+
declare const triggerJobSchema: _$typebox.TObject<{
|
|
1323
|
+
payload: _$typebox.TOptional<_$typebox.TRecord<"^.*$", _$typebox.TAny>>;
|
|
1050
1324
|
}>;
|
|
1051
1325
|
type TriggerJob = Static<typeof triggerJobSchema>;
|
|
1052
1326
|
//#endregion
|
|
@@ -1080,27 +1354,59 @@ declare module "alepha" {
|
|
|
1080
1354
|
/**
|
|
1081
1355
|
* Job execution framework — cron and durable queue work with a single primitive.
|
|
1082
1356
|
*
|
|
1083
|
-
* A `$job` is either **cron-only** (declares `cron`) or **
|
|
1084
|
-
*
|
|
1085
|
-
*
|
|
1357
|
+
* A `$job` is either **cron-only** (declares `cron`) or **payload-only** (declares `schema`).
|
|
1358
|
+
*
|
|
1359
|
+
* **Three runtime modes:**
|
|
1360
|
+
*
|
|
1361
|
+
* - **cron** — fires on a schedule. Cron-mode jobs are protected by a
|
|
1362
|
+
* distributed lock by default (`lock: true`), so multi-replica Docker
|
|
1363
|
+
* deployments only run the handler once per tick. Override with
|
|
1364
|
+
* `lock: false` if you genuinely want every replica to fire.
|
|
1365
|
+
* - **queue** — push-driven, dispatched through the queue infrastructure
|
|
1366
|
+
* (`AlephaQueue`, e.g. Cloudflare Queues, Redis). Real-time delivery,
|
|
1367
|
+
* ideal for high-volume systems. Requires `AlephaApiJobsQueue`.
|
|
1368
|
+
* - **direct** — push-driven, processed in-process right after the caller
|
|
1369
|
+
* awaits the push. The DB outbox row is the durability guarantee — if
|
|
1370
|
+
* the process dies, the reconciliation sweep re-dispatches. Default
|
|
1371
|
+
* when `AlephaApiJobsQueue` is *not* loaded. Best for cheap deployments
|
|
1372
|
+
* (Cloudflare Workers, single-instance Node) where standing up a queue
|
|
1373
|
+
* is overkill.
|
|
1374
|
+
*
|
|
1375
|
+
* **Retries** are sweep-driven across all modes (no exponential backoff).
|
|
1376
|
+
* Granularity is bounded by `sweepCron` (default 5 min). The first retry
|
|
1377
|
+
* may land anywhere from a few seconds to ~5 min later depending on when
|
|
1378
|
+
* the next sweep tick fires. Cron jobs that declare `retry` go through
|
|
1379
|
+
* the same sweep path — a transient failure no longer means waiting for
|
|
1380
|
+
* the next cron tick (useful for once-daily jobs).
|
|
1381
|
+
*
|
|
1382
|
+
* **Runtime support for cron triggers**
|
|
1086
1383
|
*
|
|
1087
|
-
* **
|
|
1088
|
-
*
|
|
1089
|
-
*
|
|
1090
|
-
*
|
|
1384
|
+
* - **Long-running Node / Docker** — `CronProvider` runs an in-process
|
|
1385
|
+
* timer loop. Multi-replica deployments serialize ticks via the cron
|
|
1386
|
+
* lock (see `$job.lock`).
|
|
1387
|
+
* - **Cloudflare Workers** — the build emits cron expressions into
|
|
1388
|
+
* `wrangler.jsonc`; Cloudflare invokes the worker on schedule and the
|
|
1389
|
+
* `cloudflare:scheduled` hook routes the event to the matching jobs.
|
|
1390
|
+
* - **Vercel** — the build emits cron entries into
|
|
1391
|
+
* `.vercel/output/config.json` mapped to `/_alepha/cron/:name`; the
|
|
1392
|
+
* serverless handler emits `serverless:cron` and `CronProvider` runs
|
|
1393
|
+
* the matching job. Set `CRON_SECRET` to require authenticated calls.
|
|
1091
1394
|
*
|
|
1092
1395
|
* @module alepha.api.jobs
|
|
1093
1396
|
*/
|
|
1094
1397
|
declare const AlephaApiJobs: _$alepha.Service<_$alepha.Module>;
|
|
1095
1398
|
/**
|
|
1096
1399
|
* Queue support for `$job`. Import alongside {@link AlephaApiJobs} when your
|
|
1097
|
-
* app declares queue-mode jobs (any `$job` with a `schema`)
|
|
1400
|
+
* app declares queue-mode jobs (any `$job` with a `schema`) and you want a
|
|
1401
|
+
* real queue (e.g. Cloudflare Queues, Redis) instead of in-process direct
|
|
1402
|
+
* execution.
|
|
1098
1403
|
*
|
|
1099
|
-
* Adds `JobQueueProvider`
|
|
1404
|
+
* Adds `JobQueueProvider` to the container. `JobProvider` detects its
|
|
1405
|
+
* presence at start-up and routes dispatches through it.
|
|
1100
1406
|
*
|
|
1101
1407
|
* @module alepha.api.jobs.queue
|
|
1102
1408
|
*/
|
|
1103
1409
|
declare const AlephaApiJobsQueue: _$alepha.Service<_$alepha.Module>;
|
|
1104
1410
|
//#endregion
|
|
1105
|
-
export { $job, AdminJobController, AlephaApiJobs, AlephaApiJobsQueue, CancelContext, JobConfig, JobExecutionEntity, JobExecutionQuery, JobExecutionResource, JobHandlerArgs, JobPrimitive, JobPrimitiveOptions, JobPriority, JobProvider, JobQueueProvider, JobRegistration,
|
|
1411
|
+
export { $job, AdminJobController, AlephaApiJobs, AlephaApiJobsQueue, CancelContext, DirectJobDispatcher, JobConfig, JobDispatcher, JobEffectiveMode, JobExecutionEntity, JobExecutionQuery, JobExecutionResource, JobHandlerArgs, JobPrimitive, JobPrimitiveOptions, JobPriority, JobProvider, JobQueueProvider, JobRegistration, JobRetryOptions, JobService, JobStatus, JobTriggerContext, PRIORITY_MAP, PRIORITY_REVERSE, PushManyItem, PushOptions, TriggerJob, jobConfig, jobExecutionEntity, jobExecutionQuerySchema, jobExecutionResourceSchema, jobRegistrationSchema, triggerJobSchema };
|
|
1106
1412
|
//# sourceMappingURL=index.d.ts.map
|