@bejibun/core 0.2.0 → 0.2.11

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/CHANGELOG.md CHANGED
@@ -3,7 +3,38 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  ---
5
5
 
6
- ## [v0.2.0](https://github.com/Bejibun-Framework/bejibun-core/compare/v0.1.73...v0.2.0) - 2026-02-02
6
+ ## [v0.2.11](https://github.com/Bejibun-Framework/bejibun-core/compare/v0.2.1...v0.2.11) - 2026-02-13
7
+
8
+ ### 🩹 Fixes
9
+
10
+ ### 📖 Changes
11
+ #### Upgrade [@bejibun/cors](https://github.com/Bejibun-Framework/bejibun-cors) to v0.1.17
12
+ [https://github.com/Bejibun-Framework/bejibun-cors/releases/tag/v0.1.17](https://github.com/Bejibun-Framework/bejibun-cors/releases/tag/v0.1.17)
13
+
14
+ ### ❤️Contributors
15
+ - Havea Crenata ([@crenata](https://github.com/crenata))
16
+
17
+ **Full Changelog**: https://github.com/Bejibun-Framework/bejibun-core/blob/master/CHANGELOG.md
18
+
19
+ ---
20
+
21
+ ## [v0.2.1](https://github.com/Bejibun-Framework/bejibun-core/compare/v0.2.0...v0.2.1) - 2026-02-13
22
+
23
+ ### 🩹 Fixes
24
+
25
+ ### 📖 Changes
26
+ - Added `queue:flush` to flush all failed queue jobs.
27
+ - Added `queue:retry` to retry a failed queue job.
28
+ - Close database connection after using command.
29
+
30
+ ### ❤️Contributors
31
+ - Havea Crenata ([@crenata](https://github.com/crenata))
32
+
33
+ **Full Changelog**: https://github.com/Bejibun-Framework/bejibun-core/blob/master/CHANGELOG.md
34
+
35
+ ---
36
+
37
+ ## [v0.2.0](https://github.com/Bejibun-Framework/bejibun-core/compare/v0.1.73...v0.2.0) - 2026-02-12
7
38
 
8
39
  ### 🩹 Fixes
9
40
  - Invalid namespace for model - [#15](https://github.com/Bejibun-Framework/bejibun-core/issues/15)
@@ -16,7 +47,8 @@ All notable changes to this project will be documented in this file.
16
47
 
17
48
  #### What's New :
18
49
  - Epoch Timestamp Trait
19
- - Queue Jobs
50
+ - Job Dispatch
51
+ - Queue Worker
20
52
 
21
53
  #### What is Epoch Timestamp Trait?
22
54
  Override default model timestamps for `created_at`, `updated_at`, and `deleted_at` to unix timestamp.
package/README.md CHANGED
@@ -562,6 +562,17 @@ await Storage.build({
562
562
  }).delete("path/to/your/file.ext");
563
563
  ```
564
564
 
565
+ ### Queue
566
+ Run processes at background.
567
+
568
+ ```ts
569
+ // Immediately
570
+ await TestJob.dispatch(/*any params here*/).send();
571
+
572
+ // With delay
573
+ await TestJob.dispatch(/*any params here*/).delay(60 * 10 /*10 minutes*/).send();
574
+ ```
575
+
565
576
  ### Cors
566
577
  Documentation : [@bejibun/cors](https://github.com/Bejibun-Framework/bejibun-cors/blob/master/README.md)
567
578
 
@@ -589,6 +600,7 @@ Commands:
589
600
  maintenance:up Turn app into live mode
590
601
  make:command <file> Create a new command file
591
602
  make:controller <file> Create a new controller file
603
+ make:job <file> Create a new job file
592
604
  make:middleware <file> Create a new middleware file
593
605
  make:migration <file> Create a new migration file
594
606
  make:model <file> Create a new model file
@@ -599,6 +611,9 @@ Commands:
599
611
  migrate:rollback [options] Rollback the latest migrations
600
612
  migrate:status [options] List migrations status
601
613
  package:configure [options] Configure package after installation
614
+ queue:flush Flush all of the failed queue jobs
615
+ queue:retry Retry a failed queue job
616
+ queue:work Start processing jobs on the queue as a daemon
602
617
  help [command] display help for command
603
618
 
604
619
  Examples:
package/ace.js CHANGED
@@ -1,8 +1,10 @@
1
+ import App from "@bejibun/app";
1
2
  import Str from "@bejibun/utils/facades/Str";
2
3
  import { program } from "commander";
3
4
  import os from "os";
4
5
  import Kernel from "./commands/Kernel";
5
6
  import { version } from "package.json";
7
+ await import(App.Path.rootPath("bootstrap.ts"));
6
8
  const commandExec = "ace";
7
9
  program
8
10
  .name(commandExec)
@@ -1,5 +1,6 @@
1
1
  import App from "@bejibun/app";
2
2
  import { defineValue, isEmpty } from "@bejibun/utils";
3
+ import BaseModel from "../bases/BaseModel";
3
4
  export default class Kernel {
4
5
  static registerCommands(program) {
5
6
  const rootCommands = require(App.Path.configPath("command.ts")).default;
@@ -55,7 +56,12 @@ export default class Kernel {
55
56
  const commandObj = args[args.length - 1];
56
57
  const options = typeof commandObj.opts === "function" ? commandObj.opts() : commandObj;
57
58
  const positionalArgs = args[0];
58
- await instance.handle(options, positionalArgs);
59
+ try {
60
+ await instance.handle(options, positionalArgs);
61
+ }
62
+ finally {
63
+ await BaseModel.knex().destroy();
64
+ }
59
65
  });
60
66
  }
61
67
  }
@@ -0,0 +1,27 @@
1
+ export default class QueueFlushCommand {
2
+ /**
3
+ * The name and signature of the console command.
4
+ *
5
+ * @var $signature string
6
+ */
7
+ protected $signature: string;
8
+ /**
9
+ * The console command description.
10
+ *
11
+ * @var $description string
12
+ */
13
+ protected $description: string;
14
+ /**
15
+ * The options or optional flag of the console command.
16
+ *
17
+ * @var $options Array<Array<any>>
18
+ */
19
+ protected $options: Array<Array<any>>;
20
+ /**
21
+ * The arguments of the console command.
22
+ *
23
+ * @var $arguments Array<Array<string>>
24
+ */
25
+ protected $arguments: Array<Array<string>>;
26
+ handle(options: any, args: string): Promise<void>;
27
+ }
@@ -0,0 +1,32 @@
1
+ import Logger from "@bejibun/logger";
2
+ import JobModel from "../../models/JobModel";
3
+ export default class QueueFlushCommand {
4
+ /**
5
+ * The name and signature of the console command.
6
+ *
7
+ * @var $signature string
8
+ */
9
+ $signature = "queue:flush";
10
+ /**
11
+ * The console command description.
12
+ *
13
+ * @var $description string
14
+ */
15
+ $description = "Flush all of the failed queue jobs";
16
+ /**
17
+ * The options or optional flag of the console command.
18
+ *
19
+ * @var $options Array<Array<any>>
20
+ */
21
+ $options = [];
22
+ /**
23
+ * The arguments of the console command.
24
+ *
25
+ * @var $arguments Array<Array<string>>
26
+ */
27
+ $arguments = [];
28
+ async handle(options, args) {
29
+ await JobModel.query().where("attempts", ">=", 3).delete();
30
+ Logger.setContext("Queue").info("All failed jobs deleted successfully.");
31
+ }
32
+ }
@@ -0,0 +1,27 @@
1
+ export default class QueueRetryCommand {
2
+ /**
3
+ * The name and signature of the console command.
4
+ *
5
+ * @var $signature string
6
+ */
7
+ protected $signature: string;
8
+ /**
9
+ * The console command description.
10
+ *
11
+ * @var $description string
12
+ */
13
+ protected $description: string;
14
+ /**
15
+ * The options or optional flag of the console command.
16
+ *
17
+ * @var $options Array<Array<any>>
18
+ */
19
+ protected $options: Array<Array<any>>;
20
+ /**
21
+ * The arguments of the console command.
22
+ *
23
+ * @var $arguments Array<Array<string>>
24
+ */
25
+ protected $arguments: Array<Array<string>>;
26
+ handle(options: any, args: string): Promise<void>;
27
+ }
@@ -0,0 +1,74 @@
1
+ import App from "@bejibun/app";
2
+ import Logger from "@bejibun/logger";
3
+ import { defineValue, isEmpty } from "@bejibun/utils";
4
+ import RuntimeException from "../../exceptions/RuntimeException";
5
+ import JobModel from "../../models/JobModel";
6
+ export default class QueueRetryCommand {
7
+ /**
8
+ * The name and signature of the console command.
9
+ *
10
+ * @var $signature string
11
+ */
12
+ $signature = "queue:retry";
13
+ /**
14
+ * The console command description.
15
+ *
16
+ * @var $description string
17
+ */
18
+ $description = "Retry a failed queue job";
19
+ /**
20
+ * The options or optional flag of the console command.
21
+ *
22
+ * @var $options Array<Array<any>>
23
+ */
24
+ $options = [];
25
+ /**
26
+ * The arguments of the console command.
27
+ *
28
+ * @var $arguments Array<Array<string>>
29
+ */
30
+ $arguments = [];
31
+ async handle(options, args) {
32
+ let running = true;
33
+ process.on("exit", async () => {
34
+ running = false;
35
+ Logger.setContext("Queue").info("Queue worker stopped.");
36
+ });
37
+ process.on("SIGINT", async () => {
38
+ running = false;
39
+ Logger.setContext("Queue").info("Stopping queue worker, SIGINT sent.");
40
+ });
41
+ process.on("SIGTERM", async () => {
42
+ running = false;
43
+ Logger.setContext("Queue").info("Stopping queue worker, SIGTERM sent.");
44
+ });
45
+ while (running) {
46
+ const job = await JobModel.query().where("attempts", ">=", 3).orderBy("id", "asc").first();
47
+ if (isEmpty(job?.id)) {
48
+ running = false;
49
+ }
50
+ else {
51
+ const handler = async () => {
52
+ const module = await import(App.Path.rootPath(job.queue));
53
+ const Class = module.default;
54
+ if (isEmpty(Class))
55
+ throw new RuntimeException(`Job class not found [${job.queue}].`);
56
+ const instance = new Class();
57
+ if (typeof instance.handle !== "function")
58
+ throw new RuntimeException(`Job class has no handle function in [${job.queue}].`);
59
+ instance.handle(JSON.parse(job.payload));
60
+ };
61
+ try {
62
+ await handler();
63
+ await JobModel.query().findById(job.id).delete();
64
+ }
65
+ catch {
66
+ await JobModel.query().findById(job.id).update({
67
+ attempts: defineValue(Number(job.attempts), 0) + 1
68
+ });
69
+ }
70
+ }
71
+ }
72
+ Logger.setContext("Queue").info("All failed jobs retried successfully.");
73
+ }
74
+ }
@@ -29,7 +29,6 @@ export default class QueueWorkCommand {
29
29
  */
30
30
  $arguments = [];
31
31
  async handle(options, args) {
32
- await import(App.Path.rootPath("bootstrap.ts"));
33
32
  let running = true;
34
33
  process.on("exit", async () => {
35
34
  running = false;
@@ -67,6 +66,5 @@ export default class QueueWorkCommand {
67
66
  }
68
67
  }
69
68
  }
70
- process.exit(0);
71
69
  }
72
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bejibun/core",
3
- "version": "0.2.0",
3
+ "version": "0.2.11",
4
4
  "author": "Havea Crenata <havea.crenata@gmail.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@bejibun/app": "^0.1.23",
13
13
  "@bejibun/cache": "^0.1.18",
14
- "@bejibun/cors": "^0.1.16",
14
+ "@bejibun/cors": "^0.1.17",
15
15
  "@bejibun/database": "^0.1.19",
16
16
  "@bejibun/logger": "^0.1.22",
17
17
  "@bejibun/utils": "^0.1.28",
package/server.js CHANGED
@@ -5,7 +5,7 @@ import RuntimeException from "./exceptions/RuntimeException";
5
5
  import Router from "./facades/Router";
6
6
  import MaintenanceMiddleware from "./middlewares/MaintenanceMiddleware";
7
7
  import RateLimiterMiddleware from "./middlewares/RateLimiterMiddleware";
8
- import(App.Path.rootPath("bootstrap.ts"));
8
+ await import(App.Path.rootPath("bootstrap.ts"));
9
9
  export default class Server {
10
10
  get exceptionHandler() {
11
11
  const exceptionHandlerPath = App.Path.appPath("exceptions/handler.ts");