@chromahq/core 0.1.7 → 0.1.8

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/dist/index.cjs.js CHANGED
@@ -1079,8 +1079,8 @@ class Scheduler {
1079
1079
  this.alarm = new AlarmAdapter();
1080
1080
  this.timeout = new TimeoutAdapter();
1081
1081
  console.log("Scheduler initialized");
1082
- this.alarm.onTrigger((id) => this.execute(id));
1083
- this.timeout.onTrigger((id) => this.execute(id));
1082
+ this.alarm.onTrigger(this.execute.bind(this));
1083
+ this.timeout.onTrigger(this.execute.bind(this));
1084
1084
  }
1085
1085
  schedule(id, options) {
1086
1086
  const context = this.registry.getContext(id);
@@ -1090,7 +1090,6 @@ class Scheduler {
1090
1090
  }
1091
1091
  console.log(`Scheduling job ${id} with options:`, options);
1092
1092
  const when = this.getScheduleTime(options);
1093
- console.log(`Job ${id} will execute at:`, new Date(when).toISOString());
1094
1093
  const adapter = when - Date.now() < 6e4 ? this.timeout : this.alarm;
1095
1094
  const timerId = adapter.schedule(id, when);
1096
1095
  if (adapter === this.timeout) {
@@ -1127,7 +1126,7 @@ class Scheduler {
1127
1126
  try {
1128
1127
  this.registry.updateState(id, JobState.RUNNING);
1129
1128
  console.log(`Executing job ${id}`);
1130
- await job.handle(context);
1129
+ await job.handle.call(job, context);
1131
1130
  if (!context.isStopped() && !context.isPaused()) {
1132
1131
  this.registry.updateState(id, JobState.COMPLETED);
1133
1132
  const options = this.registry.meta(id);
@@ -1562,9 +1561,11 @@ class ApplicationBootstrap {
1562
1561
  */
1563
1562
  async registerJobs() {
1564
1563
  this.logger.info("\u{1F552} Registering jobs...");
1565
- const jobModules = undefined("/src/app/jobs/*.job.{ts,js}", {
1566
- eager: true
1567
- });
1564
+ const jobModules = undefined(
1565
+ "/src/app/jobs/**/*.job.{ts,js}",
1566
+ { eager: true }
1567
+ );
1568
+ this.scheduler = new Scheduler();
1568
1569
  for (const module of Object.values(jobModules)) {
1569
1570
  const JobClass = module?.default;
1570
1571
  if (!JobClass) continue;
@@ -1580,10 +1581,9 @@ class ApplicationBootstrap {
1580
1581
  const jobMetadata = Reflect.getMetadata("name", JobClass);
1581
1582
  const jobName = jobMetadata || JobClass.name;
1582
1583
  container.bind(JobClass).toSelf().inSingletonScope();
1583
- const id = "12";
1584
+ const id = `${jobName.toLowerCase()}:${JobClass.name.toLowerCase()} ${Math.random().toString(36).substring(2, 15)}`;
1584
1585
  const options = Reflect.getMetadata("job:options", JobClass) || {};
1585
1586
  const instance = container.get(JobClass);
1586
- this.scheduler = new Scheduler();
1587
1587
  JobRegistry.instance.register(id, instance, options);
1588
1588
  this.scheduler.schedule(id, options);
1589
1589
  this.logger.success(`\u2705 Registered job: ${jobName}`);
package/dist/index.es.js CHANGED
@@ -1077,8 +1077,8 @@ class Scheduler {
1077
1077
  this.alarm = new AlarmAdapter();
1078
1078
  this.timeout = new TimeoutAdapter();
1079
1079
  console.log("Scheduler initialized");
1080
- this.alarm.onTrigger((id) => this.execute(id));
1081
- this.timeout.onTrigger((id) => this.execute(id));
1080
+ this.alarm.onTrigger(this.execute.bind(this));
1081
+ this.timeout.onTrigger(this.execute.bind(this));
1082
1082
  }
1083
1083
  schedule(id, options) {
1084
1084
  const context = this.registry.getContext(id);
@@ -1088,7 +1088,6 @@ class Scheduler {
1088
1088
  }
1089
1089
  console.log(`Scheduling job ${id} with options:`, options);
1090
1090
  const when = this.getScheduleTime(options);
1091
- console.log(`Job ${id} will execute at:`, new Date(when).toISOString());
1092
1091
  const adapter = when - Date.now() < 6e4 ? this.timeout : this.alarm;
1093
1092
  const timerId = adapter.schedule(id, when);
1094
1093
  if (adapter === this.timeout) {
@@ -1125,7 +1124,7 @@ class Scheduler {
1125
1124
  try {
1126
1125
  this.registry.updateState(id, JobState.RUNNING);
1127
1126
  console.log(`Executing job ${id}`);
1128
- await job.handle(context);
1127
+ await job.handle.call(job, context);
1129
1128
  if (!context.isStopped() && !context.isPaused()) {
1130
1129
  this.registry.updateState(id, JobState.COMPLETED);
1131
1130
  const options = this.registry.meta(id);
@@ -1560,9 +1559,11 @@ class ApplicationBootstrap {
1560
1559
  */
1561
1560
  async registerJobs() {
1562
1561
  this.logger.info("\u{1F552} Registering jobs...");
1563
- const jobModules = import.meta.glob("/src/app/jobs/*.job.{ts,js}", {
1564
- eager: true
1565
- });
1562
+ const jobModules = import.meta.glob(
1563
+ "/src/app/jobs/**/*.job.{ts,js}",
1564
+ { eager: true }
1565
+ );
1566
+ this.scheduler = new Scheduler();
1566
1567
  for (const module of Object.values(jobModules)) {
1567
1568
  const JobClass = module?.default;
1568
1569
  if (!JobClass) continue;
@@ -1578,10 +1579,9 @@ class ApplicationBootstrap {
1578
1579
  const jobMetadata = Reflect.getMetadata("name", JobClass);
1579
1580
  const jobName = jobMetadata || JobClass.name;
1580
1581
  container.bind(JobClass).toSelf().inSingletonScope();
1581
- const id = "12";
1582
+ const id = `${jobName.toLowerCase()}:${JobClass.name.toLowerCase()} ${Math.random().toString(36).substring(2, 15)}`;
1582
1583
  const options = Reflect.getMetadata("job:options", JobClass) || {};
1583
1584
  const instance = container.get(JobClass);
1584
- this.scheduler = new Scheduler();
1585
1585
  JobRegistry.instance.register(id, instance, options);
1586
1586
  this.scheduler.schedule(id, options);
1587
1587
  this.logger.success(`\u2705 Registered job: ${jobName}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromahq/core",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Core library for building Chrome extensions with Chroma framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",