data store options type added
Signed-off-by: Brian Fletcher <brian@roadie.io>
This commit is contained in:
@@ -193,9 +193,7 @@ export const createTemplateAction: <
|
||||
templateAction: TemplateAction<Input>,
|
||||
) => TemplateAction<any>;
|
||||
|
||||
// Warning: (ae-missing-release-tag) "CreateWorkerOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
// @public
|
||||
export type CreateWorkerOptions = {
|
||||
taskBroker: TaskBroker;
|
||||
actionRegistry: TemplateActionRegistry;
|
||||
@@ -206,7 +204,7 @@ export type CreateWorkerOptions = {
|
||||
|
||||
// @public
|
||||
export class DatabaseTaskStore implements TaskStore {
|
||||
constructor(db: Knex);
|
||||
constructor(options: DatabaseTaskStoreOptions);
|
||||
// (undocumented)
|
||||
claimTask(): Promise<SerializedTask | undefined>;
|
||||
// (undocumented)
|
||||
@@ -219,8 +217,10 @@ export class DatabaseTaskStore implements TaskStore {
|
||||
status: Status;
|
||||
eventBody: JsonObject;
|
||||
}): Promise<void>;
|
||||
// Warning: (ae-forgotten-export) The symbol "DatabaseTaskStoreOptions" needs to be exported by the entry point index.d.ts
|
||||
//
|
||||
// (undocumented)
|
||||
static create(knex: Knex): Promise<DatabaseTaskStore>;
|
||||
static create(options: DatabaseTaskStoreOptions): Promise<DatabaseTaskStore>;
|
||||
// (undocumented)
|
||||
createTask(
|
||||
spec: TaskSpec,
|
||||
|
||||
@@ -54,20 +54,35 @@ export type RawDbTaskEventRow = {
|
||||
created_at: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* DatabaseTaskStore
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type DatabaseTaskStoreOptions = {
|
||||
database: Knex;
|
||||
};
|
||||
|
||||
/**
|
||||
* DatabaseTaskStore
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class DatabaseTaskStore implements TaskStore {
|
||||
static async create(knex: Knex): Promise<DatabaseTaskStore> {
|
||||
await knex.migrate.latest({
|
||||
private readonly db: Knex;
|
||||
|
||||
static async create(
|
||||
options: DatabaseTaskStoreOptions,
|
||||
): Promise<DatabaseTaskStore> {
|
||||
await options.database.migrate.latest({
|
||||
directory: migrationsDir,
|
||||
});
|
||||
return new DatabaseTaskStore(knex);
|
||||
return new DatabaseTaskStore(options);
|
||||
}
|
||||
|
||||
constructor(private readonly db: Knex) {}
|
||||
constructor(options: DatabaseTaskStoreOptions) {
|
||||
this.db = options.database;
|
||||
}
|
||||
|
||||
async getTask(taskId: string): Promise<SerializedTask> {
|
||||
const [result] = await this.db<RawDbTaskRow>('tasks')
|
||||
|
||||
@@ -31,7 +31,9 @@ async function createStore(): Promise<DatabaseTaskStore> {
|
||||
},
|
||||
}),
|
||||
).forPlugin('scaffolder');
|
||||
return await DatabaseTaskStore.create(await manager.getClient());
|
||||
return await DatabaseTaskStore.create({
|
||||
database: await manager.getClient(),
|
||||
});
|
||||
}
|
||||
|
||||
describe('StorageTaskBroker', () => {
|
||||
|
||||
@@ -33,7 +33,9 @@ async function createStore(): Promise<DatabaseTaskStore> {
|
||||
},
|
||||
}),
|
||||
).forPlugin('scaffolder');
|
||||
return await DatabaseTaskStore.create(await manager.getClient());
|
||||
return await DatabaseTaskStore.create({
|
||||
database: await manager.getClient(),
|
||||
});
|
||||
}
|
||||
|
||||
describe('TaskWorker', () => {
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { DatabaseTaskStore } from './DatabaseTaskStore';
|
||||
export type { DatabaseTaskStoreOptions } from './DatabaseTaskStore';
|
||||
export { StorageTaskBroker, TaskAgent } from './StorageTaskBroker';
|
||||
export type { TaskState } from './StorageTaskBroker';
|
||||
export { TaskWorker } from './TaskWorker';
|
||||
|
||||
@@ -92,9 +92,9 @@ export async function createRouter(
|
||||
const entityClient = new CatalogEntityClient(catalogClient);
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
|
||||
const databaseTaskStore = await DatabaseTaskStore.create(
|
||||
await database.getClient(),
|
||||
);
|
||||
const databaseTaskStore = await DatabaseTaskStore.create({
|
||||
database: await database.getClient(),
|
||||
});
|
||||
const taskBroker =
|
||||
options.taskBroker || new StorageTaskBroker(databaseTaskStore, logger);
|
||||
const actionRegistry = new TemplateActionRegistry();
|
||||
|
||||
Reference in New Issue
Block a user