Skip to content

Commit 3d9a6da

Browse files
authored
fix: executeTask should fallback to priority's args (#1610)
1 parent c047c39 commit 3d9a6da

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/actions/lifecycle.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ export abstract class TasksMixin {
3737
* Register priorities for this generator
3838
*/
3939
registerPriorities(this: BaseGeneratorImpl, priorities: Priority[]) {
40-
priorities = priorities.filter(priority => {
41-
if (priority.edit) {
42-
const queue = this._queues[priority.priorityName];
40+
priorities = priorities.filter(({ priorityName, edit, ...priority }) => {
41+
if (edit) {
42+
const queue = this._queues[priorityName];
4343
if (!queue) {
44-
throw new Error(`Error editing priority ${priority.priorityName}, not found`);
44+
throw new Error(`Error editing priority ${priorityName}, not found`);
4545
}
4646

4747
Object.assign(queue, { ...priority, edit: undefined });
4848
}
4949

50-
return !priority.edit;
50+
return !edit;
5151
});
5252

5353
const customPriorities = priorities.map(customPriority => ({ ...customPriority }));
@@ -321,21 +321,21 @@ export abstract class TasksMixin {
321321
async executeTask(
322322
this: BaseGeneratorImpl,
323323
task: Task,
324-
args = task.args ?? this.args,
324+
args = task.args,
325325
taskStatus: TaskStatus | undefined = this._taskStatus,
326326
): Promise<void> {
327327
const { reject, queueName = 'default', taskName: methodName, method } = task;
328328
const { _namespace: namespace } = this;
329-
const priority = Object.entries(this._queues).find(([_, options]) => (options as any).queueName === queueName);
330-
const priorityName = priority ? priority[0] : undefined;
331329

332330
debug(`Running ${namespace}#${methodName}`);
333331
this.emit(`method:${methodName}`);
334332
const taskCancelled = task.cancellable && taskStatus?.cancelled;
335333
if (taskCancelled) {
336334
return;
337335
}
338-
336+
const [priorityName, priority] =
337+
Object.entries(this._queues).find(([_, queue]) => queue.queueName === queueName) ?? [];
338+
args ??= priority?.args ?? this.args;
339339
args = typeof args === 'function' ? args(this as any) : args;
340340
this.runningState = { namespace, queueName, methodName };
341341
try {

test/base.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,24 @@ describe('Base', () => {
807807
});
808808
});
809809

810+
describe('#executeTask()', () => {
811+
it('should execute the task passing priority args', () => {
812+
const priority = {
813+
priorityName: 'initializing',
814+
args: ['an arg array'],
815+
};
816+
dummy.registerPriorities([priority]);
817+
818+
const task = vi.fn();
819+
dummy.executeTask({
820+
queueName: 'dummy#initializing',
821+
method: task,
822+
taskName: 'testTask',
823+
});
824+
expect(task).toHaveBeenCalledWith('an arg array');
825+
});
826+
});
827+
810828
describe('#parseOptions()', () => {
811829
beforeEach(() => {
812830
dummy = new Dummy(['start', '--foo', 'bar', '-s', 'baz', 'remain'], {

0 commit comments

Comments
 (0)