alepha 0.11.6 → 0.11.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/api/jobs.d.ts CHANGED
@@ -3,84 +3,82 @@ import { Alepha, Async, Descriptor, KIND, Static } from "alepha";
3
3
  import "alepha/server/security";
4
4
  import * as _alepha_postgres0 from "alepha/postgres";
5
5
  import * as _alepha_server0 from "alepha/server";
6
- import * as _alepha_logger0 from "alepha/logger";
7
6
  import { DateTime, DateTimeProvider } from "alepha/datetime";
8
- import * as _alepha_lock0 from "alepha/lock";
7
+ import { LockDescriptor } from "alepha/lock";
9
8
  import { CronProvider } from "alepha/scheduler";
10
- import * as typebox176 from "typebox";
11
- import * as dayjs0 from "dayjs";
9
+ import * as typebox79 from "typebox";
12
10
 
13
11
  //#region src/schemas/jobExecutionQuerySchema.d.ts
14
- declare const jobExecutionQuerySchema: typebox176.TObject<{
15
- page: typebox176.TOptional<typebox176.TInteger>;
16
- size: typebox176.TOptional<typebox176.TInteger>;
17
- sort: typebox176.TOptional<typebox176.TString>;
18
- status: typebox176.TOptional<typebox176.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">>;
19
- job: typebox176.TOptional<typebox176.TString>;
12
+ declare const jobExecutionQuerySchema: typebox79.TObject<{
13
+ page: typebox79.TOptional<typebox79.TInteger>;
14
+ size: typebox79.TOptional<typebox79.TInteger>;
15
+ sort: typebox79.TOptional<typebox79.TString>;
16
+ status: typebox79.TOptional<typebox79.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">>;
17
+ job: typebox79.TOptional<typebox79.TString>;
20
18
  }>;
21
19
  type JobExecutionQuery = Static<typeof jobExecutionQuerySchema>;
22
20
  //#endregion
23
21
  //#region src/services/JobService.d.ts
24
22
  declare class JobService {
25
23
  protected readonly alepha: Alepha;
26
- protected readonly executionRepository: _alepha_postgres0.Repository<typebox176.TObject<{
27
- id: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TString, typeof _alepha_postgres0.PG_PRIMARY_KEY>, typeof _alepha_postgres0.PG_DEFAULT>;
28
- version: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TInteger, typeof _alepha_postgres0.PG_VERSION>, typeof _alepha_postgres0.PG_DEFAULT>;
29
- createdAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>, typeof _alepha_postgres0.PG_CREATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
30
- updatedAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>, typeof _alepha_postgres0.PG_UPDATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
31
- finishedAt: typebox176.TOptional<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>>;
32
- job: typebox176.TString;
33
- status: typebox176.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
34
- error: typebox176.TOptional<typebox176.TString>;
35
- logs: typebox176.TOptional<typebox176.TArray<typebox176.TObject<{
36
- level: typebox176.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
37
- message: typebox176.TString;
38
- service: typebox176.TString;
39
- module: typebox176.TString;
40
- context: typebox176.TOptional<typebox176.TString>;
41
- app: typebox176.TOptional<typebox176.TString>;
42
- data: typebox176.TOptional<typebox176.TAny>;
43
- timestamp: typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>;
24
+ protected readonly executionRepository: _alepha_postgres0.Repository<typebox79.TObject<{
25
+ id: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_PRIMARY_KEY>, typeof _alepha_postgres0.PG_DEFAULT>;
26
+ version: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TInteger, typeof _alepha_postgres0.PG_VERSION>, typeof _alepha_postgres0.PG_DEFAULT>;
27
+ createdAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_CREATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
28
+ updatedAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_UPDATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
29
+ finishedAt: typebox79.TOptional<typebox79.TString>;
30
+ job: typebox79.TString;
31
+ status: typebox79.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
32
+ error: typebox79.TOptional<typebox79.TString>;
33
+ logs: typebox79.TOptional<typebox79.TArray<typebox79.TObject<{
34
+ level: typebox79.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
35
+ message: typebox79.TString;
36
+ service: typebox79.TString;
37
+ module: typebox79.TString;
38
+ context: typebox79.TOptional<typebox79.TString>;
39
+ app: typebox79.TOptional<typebox79.TString>;
40
+ data: typebox79.TOptional<typebox79.TAny>;
41
+ timestamp: typebox79.TString;
44
42
  }>>>;
45
43
  }>>;
46
44
  getJobs(): Promise<string[]>;
47
- getJobExecutions(query?: JobExecutionQuery): Promise<_alepha_core1.Page<_alepha_postgres0.PgStatic<typebox176.TObject<{
48
- id: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TString, typeof _alepha_postgres0.PG_PRIMARY_KEY>, typeof _alepha_postgres0.PG_DEFAULT>;
49
- version: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TInteger, typeof _alepha_postgres0.PG_VERSION>, typeof _alepha_postgres0.PG_DEFAULT>;
50
- createdAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>, typeof _alepha_postgres0.PG_CREATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
51
- updatedAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>, typeof _alepha_postgres0.PG_UPDATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
52
- finishedAt: typebox176.TOptional<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>>;
53
- job: typebox176.TString;
54
- status: typebox176.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
55
- error: typebox176.TOptional<typebox176.TString>;
56
- logs: typebox176.TOptional<typebox176.TArray<typebox176.TObject<{
57
- level: typebox176.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
58
- message: typebox176.TString;
59
- service: typebox176.TString;
60
- module: typebox176.TString;
61
- context: typebox176.TOptional<typebox176.TString>;
62
- app: typebox176.TOptional<typebox176.TString>;
63
- data: typebox176.TOptional<typebox176.TAny>;
64
- timestamp: typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>;
45
+ getJobExecutions(query?: JobExecutionQuery): Promise<_alepha_core1.Page<_alepha_postgres0.PgStatic<typebox79.TObject<{
46
+ id: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_PRIMARY_KEY>, typeof _alepha_postgres0.PG_DEFAULT>;
47
+ version: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TInteger, typeof _alepha_postgres0.PG_VERSION>, typeof _alepha_postgres0.PG_DEFAULT>;
48
+ createdAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_CREATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
49
+ updatedAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_UPDATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
50
+ finishedAt: typebox79.TOptional<typebox79.TString>;
51
+ job: typebox79.TString;
52
+ status: typebox79.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
53
+ error: typebox79.TOptional<typebox79.TString>;
54
+ logs: typebox79.TOptional<typebox79.TArray<typebox79.TObject<{
55
+ level: typebox79.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
56
+ message: typebox79.TString;
57
+ service: typebox79.TString;
58
+ module: typebox79.TString;
59
+ context: typebox79.TOptional<typebox79.TString>;
60
+ app: typebox79.TOptional<typebox79.TString>;
61
+ data: typebox79.TOptional<typebox79.TAny>;
62
+ timestamp: typebox79.TString;
65
63
  }>>>;
66
- }>, _alepha_postgres0.PgRelationMap<typebox176.TObject<{
67
- id: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TString, typeof _alepha_postgres0.PG_PRIMARY_KEY>, typeof _alepha_postgres0.PG_DEFAULT>;
68
- version: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TInteger, typeof _alepha_postgres0.PG_VERSION>, typeof _alepha_postgres0.PG_DEFAULT>;
69
- createdAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>, typeof _alepha_postgres0.PG_CREATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
70
- updatedAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>, typeof _alepha_postgres0.PG_UPDATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
71
- finishedAt: typebox176.TOptional<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>>;
72
- job: typebox176.TString;
73
- status: typebox176.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
74
- error: typebox176.TOptional<typebox176.TString>;
75
- logs: typebox176.TOptional<typebox176.TArray<typebox176.TObject<{
76
- level: typebox176.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
77
- message: typebox176.TString;
78
- service: typebox176.TString;
79
- module: typebox176.TString;
80
- context: typebox176.TOptional<typebox176.TString>;
81
- app: typebox176.TOptional<typebox176.TString>;
82
- data: typebox176.TOptional<typebox176.TAny>;
83
- timestamp: typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>;
64
+ }>, _alepha_postgres0.PgRelationMap<typebox79.TObject<{
65
+ id: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_PRIMARY_KEY>, typeof _alepha_postgres0.PG_DEFAULT>;
66
+ version: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TInteger, typeof _alepha_postgres0.PG_VERSION>, typeof _alepha_postgres0.PG_DEFAULT>;
67
+ createdAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_CREATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
68
+ updatedAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_UPDATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
69
+ finishedAt: typebox79.TOptional<typebox79.TString>;
70
+ job: typebox79.TString;
71
+ status: typebox79.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
72
+ error: typebox79.TOptional<typebox79.TString>;
73
+ logs: typebox79.TOptional<typebox79.TArray<typebox79.TObject<{
74
+ level: typebox79.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
75
+ message: typebox79.TString;
76
+ service: typebox79.TString;
77
+ module: typebox79.TString;
78
+ context: typebox79.TOptional<typebox79.TString>;
79
+ app: typebox79.TOptional<typebox79.TString>;
80
+ data: typebox79.TOptional<typebox79.TAny>;
81
+ timestamp: typebox79.TString;
84
82
  }>>>;
85
83
  }>>>>>;
86
84
  triggerJob(name: string): Promise<{
@@ -94,116 +92,87 @@ declare class JobController {
94
92
  protected readonly group: string;
95
93
  protected readonly jobService: JobService;
96
94
  readonly getJobs: _alepha_server0.ActionDescriptorFn<{
97
- response: typebox176.TArray<typebox176.TString>;
95
+ response: typebox79.TArray<typebox79.TString>;
98
96
  }>;
99
97
  readonly getJobExecutions: _alepha_server0.ActionDescriptorFn<{
100
- query: typebox176.TObject<{
101
- page: typebox176.TOptional<typebox176.TInteger>;
102
- size: typebox176.TOptional<typebox176.TInteger>;
103
- sort: typebox176.TOptional<typebox176.TString>;
104
- status: typebox176.TOptional<typebox176.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">>;
105
- job: typebox176.TOptional<typebox176.TString>;
98
+ query: typebox79.TObject<{
99
+ page: typebox79.TOptional<typebox79.TInteger>;
100
+ size: typebox79.TOptional<typebox79.TInteger>;
101
+ sort: typebox79.TOptional<typebox79.TString>;
102
+ status: typebox79.TOptional<typebox79.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">>;
103
+ job: typebox79.TOptional<typebox79.TString>;
106
104
  }>;
107
- response: _alepha_core1.TPage<typebox176.TObject<{
108
- id: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TString, typeof _alepha_postgres0.PG_PRIMARY_KEY>, typeof _alepha_postgres0.PG_DEFAULT>;
109
- version: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TInteger, typeof _alepha_postgres0.PG_VERSION>, typeof _alepha_postgres0.PG_DEFAULT>;
110
- createdAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>, typeof _alepha_postgres0.PG_CREATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
111
- updatedAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>, typeof _alepha_postgres0.PG_UPDATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
112
- finishedAt: typebox176.TOptional<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>>;
113
- job: typebox176.TString;
114
- status: typebox176.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
115
- error: typebox176.TOptional<typebox176.TString>;
116
- logs: typebox176.TOptional<typebox176.TArray<typebox176.TObject<{
117
- level: typebox176.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
118
- message: typebox176.TString;
119
- service: typebox176.TString;
120
- module: typebox176.TString;
121
- context: typebox176.TOptional<typebox176.TString>;
122
- app: typebox176.TOptional<typebox176.TString>;
123
- data: typebox176.TOptional<typebox176.TAny>;
124
- timestamp: typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>;
105
+ response: _alepha_core1.TPage<typebox79.TObject<{
106
+ id: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_PRIMARY_KEY>, typeof _alepha_postgres0.PG_DEFAULT>;
107
+ version: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TInteger, typeof _alepha_postgres0.PG_VERSION>, typeof _alepha_postgres0.PG_DEFAULT>;
108
+ createdAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_CREATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
109
+ updatedAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_UPDATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
110
+ finishedAt: typebox79.TOptional<typebox79.TString>;
111
+ job: typebox79.TString;
112
+ status: typebox79.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
113
+ error: typebox79.TOptional<typebox79.TString>;
114
+ logs: typebox79.TOptional<typebox79.TArray<typebox79.TObject<{
115
+ level: typebox79.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
116
+ message: typebox79.TString;
117
+ service: typebox79.TString;
118
+ module: typebox79.TString;
119
+ context: typebox79.TOptional<typebox79.TString>;
120
+ app: typebox79.TOptional<typebox79.TString>;
121
+ data: typebox79.TOptional<typebox79.TAny>;
122
+ timestamp: typebox79.TString;
125
123
  }>>>;
126
124
  }>>;
127
125
  }>;
128
126
  readonly triggerJob: _alepha_server0.ActionDescriptorFn<{
129
- body: typebox176.TObject<{
130
- name: typebox176.TString;
127
+ body: typebox79.TObject<{
128
+ name: typebox79.TString;
131
129
  }>;
132
- response: typebox176.TObject<{
133
- ok: typebox176.TBoolean;
134
- id: typebox176.TOptional<typebox176.TUnion<[typebox176.TString, typebox176.TInteger]>>;
135
- count: typebox176.TOptional<typebox176.TNumber>;
130
+ response: typebox79.TObject<{
131
+ ok: typebox79.TBoolean;
132
+ id: typebox79.TOptional<typebox79.TUnion<[typebox79.TString, typebox79.TInteger]>>;
133
+ count: typebox79.TOptional<typebox79.TNumber>;
136
134
  }>;
137
135
  }>;
138
136
  }
139
137
  //#endregion
140
- //#region src/descriptors/$job.d.ts
141
- /**
142
- * Job descriptor - a drop-in replacement for $scheduler with built-in execution tracking.
143
- */
144
- declare const $job: {
145
- (options: JobDescriptorOptions): JobDescriptor;
146
- [KIND]: typeof JobDescriptor;
147
- };
148
- type JobDescriptorOptions = {
149
- /**
150
- * Function to run on schedule.
151
- */
152
- handler: (args: JobHandlerArguments) => Async<void>;
153
- /**
154
- * Name of the job. Defaults to the function name.
155
- */
156
- name?: string;
157
- /**
158
- * Optional description of the job.
159
- */
160
- description?: string;
161
- /**
162
- * Cron expression to run the job.
163
- */
164
- cron?: string;
165
- /**
166
- * If true, the job will be locked and only one instance will run at a time.
167
- * You probably need to import {@link AlephaLockRedis} for distributed locking.
168
- *
169
- * @default true
170
- */
171
- lock?: boolean;
172
- };
138
+ //#region src/providers/JobProvider.d.ts
173
139
  declare const envSchema: _alepha_core1.TObject<{
174
140
  JOB_PREFIX: _alepha_core1.TOptional<_alepha_core1.TString>;
175
141
  }>;
176
142
  declare module "alepha" {
177
143
  interface Env extends Partial<Static<typeof envSchema>> {}
178
144
  }
179
- declare class JobDescriptor extends Descriptor<JobDescriptorOptions> {
180
- protected readonly log: _alepha_logger0.Logger;
181
- protected readonly env: {
182
- JOB_PREFIX?: string | undefined;
183
- };
145
+ /**
146
+ * Provider for job management and execution.
147
+ * Handles job lifecycle, execution tracking, log capturing, and event emission.
148
+ */
149
+ declare class JobProvider {
184
150
  protected readonly alepha: Alepha;
185
151
  protected readonly dateTimeProvider: DateTimeProvider;
186
152
  protected readonly cronProvider: CronProvider;
187
153
  protected readonly executionRepository: _alepha_postgres0.Repository<_alepha_core1.TObject<{
188
154
  id: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<_alepha_core1.TString, typeof _alepha_postgres0.PG_PRIMARY_KEY>, typeof _alepha_postgres0.PG_DEFAULT>;
189
- version: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TInteger, typeof _alepha_postgres0.PG_VERSION>, typeof _alepha_postgres0.PG_DEFAULT>;
190
- createdAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TCodec<_alepha_core1.TString, dayjs0.Dayjs>, typeof _alepha_postgres0.PG_CREATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
191
- updatedAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TCodec<_alepha_core1.TString, dayjs0.Dayjs>, typeof _alepha_postgres0.PG_UPDATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
192
- finishedAt: _alepha_core1.TOptional<typebox176.TCodec<_alepha_core1.TString, dayjs0.Dayjs>>;
155
+ version: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TInteger, typeof _alepha_postgres0.PG_VERSION>, typeof _alepha_postgres0.PG_DEFAULT>;
156
+ createdAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<_alepha_core1.TString, typeof _alepha_postgres0.PG_CREATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
157
+ updatedAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<_alepha_core1.TString, typeof _alepha_postgres0.PG_UPDATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
158
+ finishedAt: _alepha_core1.TOptional<_alepha_core1.TString>;
193
159
  job: _alepha_core1.TString;
194
- status: typebox176.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
160
+ status: typebox79.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
195
161
  error: _alepha_core1.TOptional<_alepha_core1.TString>;
196
- logs: _alepha_core1.TOptional<typebox176.TArray<_alepha_core1.TObject<{
197
- level: typebox176.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
162
+ logs: _alepha_core1.TOptional<typebox79.TArray<_alepha_core1.TObject<{
163
+ level: typebox79.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
198
164
  message: _alepha_core1.TString;
199
165
  service: _alepha_core1.TString;
200
166
  module: _alepha_core1.TString;
201
167
  context: _alepha_core1.TOptional<_alepha_core1.TString>;
202
168
  app: _alepha_core1.TOptional<_alepha_core1.TString>;
203
- data: _alepha_core1.TOptional<typebox176.TAny>;
204
- timestamp: typebox176.TCodec<_alepha_core1.TString, dayjs0.Dayjs>;
169
+ data: _alepha_core1.TOptional<typebox79.TAny>;
170
+ timestamp: _alepha_core1.TString;
205
171
  }>>>;
206
172
  }>>;
173
+ protected readonly env: {
174
+ JOB_PREFIX?: string | undefined;
175
+ };
207
176
  protected readonly logs: Map<string, {
208
177
  context?: string | undefined;
209
178
  app?: string | undefined;
@@ -212,66 +181,134 @@ declare class JobDescriptor extends Descriptor<JobDescriptorOptions> {
212
181
  message: string;
213
182
  service: string;
214
183
  module: string;
215
- timestamp: dayjs0.Dayjs;
184
+ timestamp: string;
216
185
  }[]>;
186
+ protected readonly jobs: Map<string, JobRegistration>;
187
+ /**
188
+ * Register and set up a job for execution (called during descriptor initialization).
189
+ */
190
+ registerJob(options: Job): JobRegistration;
191
+ /**
192
+ * Trigger a job by name.
193
+ */
194
+ triggerJob(jobName: string): Promise<void>;
195
+ /**
196
+ * Execute a job handler (called by the job descriptor).
197
+ */
198
+ executeJob(jobName: string, handler: (args: {
199
+ now: DateTime;
200
+ }) => Async<void>): Promise<void>;
201
+ }
202
+ interface Job {
203
+ /**
204
+ * Name of the job.
205
+ */
206
+ name: string;
207
+ /**
208
+ * Optional description of the job.
209
+ */
210
+ description?: string;
211
+ /**
212
+ * Function to run on schedule.
213
+ */
214
+ handler: (args: {
215
+ now: DateTime;
216
+ }) => Async<void>;
217
+ /**
218
+ * Cron expression to run the job.
219
+ */
220
+ cron?: string;
221
+ /**
222
+ * If true, the job will be locked and only one instance will run at a time.
223
+ * You probably need to import {@link AlephaLockRedis} for distributed locking.
224
+ *
225
+ * @default true
226
+ */
227
+ lock?: boolean;
228
+ /**
229
+ * Optional prefix for job lock keys.
230
+ */
231
+ lockPrefix?: string;
232
+ }
233
+ interface JobRegistration {
234
+ name: string;
235
+ options: Job;
236
+ lockDescriptor: LockDescriptor<() => Promise<void>> | null;
237
+ }
238
+ //#endregion
239
+ //#region src/descriptors/$job.d.ts
240
+ /**
241
+ * Job descriptor - a drop-in replacement for $scheduler with built-in execution tracking.
242
+ */
243
+ declare const $job: {
244
+ (options: JobDescriptorOptions): JobDescriptor;
245
+ [KIND]: typeof JobDescriptor;
246
+ };
247
+ type JobDescriptorOptions = Omit<Job, "name"> & {
248
+ /**
249
+ * Name of the job. Defaults to the descriptor property name.
250
+ */
251
+ name?: string;
252
+ };
253
+ declare class JobDescriptor extends Descriptor<JobDescriptorOptions> {
254
+ protected readonly jobProvider: JobProvider;
217
255
  get name(): string;
218
256
  protected onInit(): void;
219
257
  trigger(): Promise<void>;
220
- protected jobLock: _alepha_lock0.LockDescriptor<(args: JobHandlerArguments) => Promise<void>>;
221
258
  }
222
259
  interface JobHandlerArguments {
223
260
  now: DateTime;
224
261
  }
225
262
  //#endregion
226
263
  //#region src/entities/jobExecutions.d.ts
227
- declare const jobExecutions: _alepha_postgres0.EntityDescriptor<typebox176.TObject<{
228
- id: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TString, typeof _alepha_postgres0.PG_PRIMARY_KEY>, typeof _alepha_postgres0.PG_DEFAULT>;
229
- version: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TInteger, typeof _alepha_postgres0.PG_VERSION>, typeof _alepha_postgres0.PG_DEFAULT>;
230
- createdAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>, typeof _alepha_postgres0.PG_CREATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
231
- updatedAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>, typeof _alepha_postgres0.PG_UPDATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
232
- finishedAt: typebox176.TOptional<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>>;
233
- job: typebox176.TString;
234
- status: typebox176.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
235
- error: typebox176.TOptional<typebox176.TString>;
236
- logs: typebox176.TOptional<typebox176.TArray<typebox176.TObject<{
237
- level: typebox176.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
238
- message: typebox176.TString;
239
- service: typebox176.TString;
240
- module: typebox176.TString;
241
- context: typebox176.TOptional<typebox176.TString>;
242
- app: typebox176.TOptional<typebox176.TString>;
243
- data: typebox176.TOptional<typebox176.TAny>;
244
- timestamp: typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>;
264
+ declare const jobExecutions: _alepha_postgres0.EntityDescriptor<typebox79.TObject<{
265
+ id: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_PRIMARY_KEY>, typeof _alepha_postgres0.PG_DEFAULT>;
266
+ version: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TInteger, typeof _alepha_postgres0.PG_VERSION>, typeof _alepha_postgres0.PG_DEFAULT>;
267
+ createdAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_CREATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
268
+ updatedAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_UPDATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
269
+ finishedAt: typebox79.TOptional<typebox79.TString>;
270
+ job: typebox79.TString;
271
+ status: typebox79.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
272
+ error: typebox79.TOptional<typebox79.TString>;
273
+ logs: typebox79.TOptional<typebox79.TArray<typebox79.TObject<{
274
+ level: typebox79.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
275
+ message: typebox79.TString;
276
+ service: typebox79.TString;
277
+ module: typebox79.TString;
278
+ context: typebox79.TOptional<typebox79.TString>;
279
+ app: typebox79.TOptional<typebox79.TString>;
280
+ data: typebox79.TOptional<typebox79.TAny>;
281
+ timestamp: typebox79.TString;
245
282
  }>>>;
246
283
  }>>;
247
284
  type JobExecutionEntity = Static<typeof jobExecutions.schema>;
248
285
  //#endregion
249
286
  //#region src/schemas/jobExecutionResourceSchema.d.ts
250
- declare const jobExecutionResourceSchema: typebox176.TObject<{
251
- id: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TString, typeof _alepha_postgres0.PG_PRIMARY_KEY>, typeof _alepha_postgres0.PG_DEFAULT>;
252
- version: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TInteger, typeof _alepha_postgres0.PG_VERSION>, typeof _alepha_postgres0.PG_DEFAULT>;
253
- createdAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>, typeof _alepha_postgres0.PG_CREATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
254
- updatedAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>, typeof _alepha_postgres0.PG_UPDATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
255
- finishedAt: typebox176.TOptional<typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>>;
256
- job: typebox176.TString;
257
- status: typebox176.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
258
- error: typebox176.TOptional<typebox176.TString>;
259
- logs: typebox176.TOptional<typebox176.TArray<typebox176.TObject<{
260
- level: typebox176.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
261
- message: typebox176.TString;
262
- service: typebox176.TString;
263
- module: typebox176.TString;
264
- context: typebox176.TOptional<typebox176.TString>;
265
- app: typebox176.TOptional<typebox176.TString>;
266
- data: typebox176.TOptional<typebox176.TAny>;
267
- timestamp: typebox176.TCodec<typebox176.TString, dayjs0.Dayjs>;
287
+ declare const jobExecutionResourceSchema: typebox79.TObject<{
288
+ id: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_PRIMARY_KEY>, typeof _alepha_postgres0.PG_DEFAULT>;
289
+ version: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TInteger, typeof _alepha_postgres0.PG_VERSION>, typeof _alepha_postgres0.PG_DEFAULT>;
290
+ createdAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_CREATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
291
+ updatedAt: _alepha_postgres0.PgAttr<_alepha_postgres0.PgAttr<typebox79.TString, typeof _alepha_postgres0.PG_UPDATED_AT>, typeof _alepha_postgres0.PG_DEFAULT>;
292
+ finishedAt: typebox79.TOptional<typebox79.TString>;
293
+ job: typebox79.TString;
294
+ status: typebox79.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
295
+ error: typebox79.TOptional<typebox79.TString>;
296
+ logs: typebox79.TOptional<typebox79.TArray<typebox79.TObject<{
297
+ level: typebox79.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
298
+ message: typebox79.TString;
299
+ service: typebox79.TString;
300
+ module: typebox79.TString;
301
+ context: typebox79.TOptional<typebox79.TString>;
302
+ app: typebox79.TOptional<typebox79.TString>;
303
+ data: typebox79.TOptional<typebox79.TAny>;
304
+ timestamp: typebox79.TString;
268
305
  }>>>;
269
306
  }>;
270
307
  type JobExecutionResource = Static<typeof jobExecutionResourceSchema>;
271
308
  //#endregion
272
309
  //#region src/schemas/triggerJobSchema.d.ts
273
- declare const triggerJobSchema: typebox176.TObject<{
274
- name: typebox176.TString;
310
+ declare const triggerJobSchema: typebox79.TObject<{
311
+ name: typebox79.TString;
275
312
  }>;
276
313
  type TriggerJob = Static<typeof triggerJobSchema>;
277
314
  //#endregion
@@ -286,5 +323,5 @@ type TriggerJob = Static<typeof triggerJobSchema>;
286
323
  */
287
324
  declare const AlephaApiJobs: _alepha_core1.Service<_alepha_core1.Module>;
288
325
  //#endregion
289
- export { $job, AlephaApiJobs, JobController, JobDescriptor, JobDescriptorOptions, JobExecutionEntity, JobExecutionQuery, JobExecutionResource, JobHandlerArguments, JobService, TriggerJob, jobExecutionQuerySchema, jobExecutionResourceSchema, jobExecutions, triggerJobSchema };
326
+ export { $job, AlephaApiJobs, Job, JobController, JobDescriptor, JobDescriptorOptions, JobExecutionEntity, JobExecutionQuery, JobExecutionResource, JobHandlerArguments, JobProvider, JobRegistration, JobService, TriggerJob, jobExecutionQuerySchema, jobExecutionResourceSchema, jobExecutions, triggerJobSchema };
290
327
  //# sourceMappingURL=index.d.ts.map