Skip to content

Commit de635aa

Browse files
committed
✨ Make TaskSchedules#startFromMenu() return the started instance
1 parent 973a8bb commit de635aa

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Add `Model#beforeCommit(document, options)` support
55
* Add `castToBigInt` and `convertBigIntForDatasource` to `Datasource` class
66
* Add `LocalDateTime`, `LocalDate` and `LocalTime` fields
7+
* Make `TaskSchedules#startFromMenu()` return the started instance
78

89
## 1.3.19 (2023-10-18)
910

lib/class/task_service.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,15 @@ class TaskSchedules {
526526
*
527527
* @author Jelle De Loecker <jelle@elevenways.be>
528528
* @since 1.3.17
529-
* @version 1.3.17
529+
* @version 1.3.20
530530
*/
531-
#startFromMenu(task_record) {
531+
async #startFromMenu(task_record) {
532532
console.log('Manually starting', task_record.type, 'task:', task_record);
533533
let schedule = new TaskSchedule(this, null, task_record.settings, task_record);
534-
schedule.startManually();
534+
let task_instance = await schedule.startManually();
535+
console.log(' -- Started:', task_instance);
536+
537+
return task_instance;
535538
}
536539

537540
/**
@@ -579,6 +582,7 @@ class TaskSchedule {
579582
janeway_menu_item = null;
580583

581584
#change_counter = 0;
585+
#instance_pledge = null;
582586

583587
/**
584588
* Initialize the instance
@@ -845,18 +849,30 @@ class TaskSchedule {
845849
*
846850
* @author Jelle De Loecker <jelle@elevenways.be>
847851
* @since 1.3.17
848-
* @version 1.3.17
852+
* @version 1.3.20
853+
*
854+
* @return {Task}
849855
*/
850856
async startManually() {
851-
return this.#run(true);
857+
858+
if (this.is_running) {
859+
return false;
860+
}
861+
862+
let pledge = new Pledge();
863+
this.#instance_pledge = pledge;
864+
865+
this.#run(true);
866+
867+
return pledge;
852868
}
853869

854870
/**
855871
* Actually run the task
856872
*
857873
* @author Jelle De Loecker <jelle@elevenways.be>
858874
* @since 1.3.17
859-
* @version 1.3.17
875+
* @version 1.3.20
860876
*/
861877
async #run(started_manually = false) {
862878

@@ -889,6 +905,12 @@ class TaskSchedule {
889905
if (started_manually || await this.ownsScheduledTask()) {
890906
let instance = this.createInstance();
891907
this.task_instance = instance;
908+
909+
if (this.#instance_pledge) {
910+
this.#instance_pledge.resolve(instance);
911+
this.#instance_pledge = null;
912+
}
913+
892914
await instance.start();
893915
}
894916
} catch (err) {

0 commit comments

Comments
 (0)