@luisrodrigues/nestjs-scheduler-dashboard 0.1.4 → 0.1.6

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.
@@ -54,6 +54,9 @@ function TrackJob(cronTime, options) {
54
54
  const original = descriptor.value;
55
55
  const jobName = options?.name ?? `${target.constructor.name}.${String(propertyKey)}`;
56
56
  const jobNoOverlap = options?.noOverlap;
57
+ if (options?.disabled) {
58
+ scheduler_dash_context_1.SchedulerDashContext.disabledJobs.add(jobName);
59
+ }
57
60
  descriptor.value = async function (...args) {
58
61
  const noOverlap = jobNoOverlap ?? scheduler_dash_context_1.SchedulerDashContext.noOverlap;
59
62
  const storage = scheduler_dash_context_1.SchedulerDashContext.storage;
@@ -8,6 +8,7 @@ export declare class JobsService {
8
8
  cron: {
9
9
  name: string;
10
10
  cronExpression: string;
11
+ active: boolean;
11
12
  running: boolean;
12
13
  nextRun: string;
13
14
  history: import(".").JobExecution[];
@@ -23,6 +24,7 @@ export declare class JobsService {
23
24
  getJob(name: string): {
24
25
  name: string;
25
26
  cronExpression: string;
27
+ active: boolean;
26
28
  running: boolean;
27
29
  nextRun: string;
28
30
  history: import(".").JobExecution[];
@@ -15,6 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.JobsService = void 0;
16
16
  const common_1 = require("@nestjs/common");
17
17
  const schedule_1 = require("@nestjs/schedule");
18
+ const storage_abstract_1 = require("./storage/storage.abstract");
19
+ const job_concurrency_1 = require("./decorators/job-concurrency");
20
+ const scheduler_dash_context_1 = require("./scheduler-dash.context");
21
+ const scheduler_dash_constants_1 = require("./scheduler-dash.constants");
18
22
  function resolveNextRun(job) {
19
23
  try {
20
24
  const next = job.nextDate?.();
@@ -37,30 +41,27 @@ function resolveCronExpression(cronTime) {
37
41
  const src = ct['source'] ?? ct['_source'];
38
42
  if (typeof src === 'string')
39
43
  return src;
40
- if (typeof cronTime.toString === 'function') {
41
- const str = cronTime.toString();
42
- if (str !== '[object Object]')
43
- return str;
44
- }
45
- return null;
44
+ const str = cronTime.toString?.();
45
+ return str && str !== '[object Object]' ? str : null;
46
46
  }
47
- const storage_abstract_1 = require("./storage/storage.abstract");
48
- const job_concurrency_1 = require("./decorators/job-concurrency");
49
- const scheduler_dash_constants_1 = require("./scheduler-dash.constants");
50
47
  let JobsService = class JobsService {
51
48
  constructor(schedulerRegistry, storage) {
52
49
  this.schedulerRegistry = schedulerRegistry;
53
50
  this.storage = storage;
54
51
  }
55
52
  getJobs() {
56
- const cron = [...this.schedulerRegistry.getCronJobs().entries()].map(([name, job]) => ({
57
- name,
58
- cronExpression: resolveCronExpression(job.cronTime),
59
- running: job.running ?? false,
60
- nextRun: job.nextDate()?.toISO() ?? null,
61
- history: this.storage.findByJob(name),
62
- metrics: this.storage.getMetrics(name),
63
- }));
53
+ const cron = [...this.schedulerRegistry.getCronJobs().entries()].map(([name, job]) => {
54
+ const nextRun = resolveNextRun(job);
55
+ return {
56
+ name,
57
+ cronExpression: resolveCronExpression(job.cronTime),
58
+ active: !scheduler_dash_context_1.SchedulerDashContext.disabledJobs.has(name),
59
+ running: job.running ?? false,
60
+ nextRun,
61
+ history: this.storage.findByJob(name),
62
+ metrics: this.storage.getMetrics(name),
63
+ };
64
+ });
64
65
  const intervals = this.schedulerRegistry.getIntervals().map((name) => ({ name }));
65
66
  const timeouts = this.schedulerRegistry.getTimeouts().map((name) => ({ name }));
66
67
  return { cron, intervals, timeouts };
@@ -69,11 +70,13 @@ let JobsService = class JobsService {
69
70
  const job = this.schedulerRegistry.getCronJobs().get(name);
70
71
  if (!job)
71
72
  return null;
73
+ const nextRun = resolveNextRun(job);
72
74
  return {
73
75
  name,
74
76
  cronExpression: resolveCronExpression(job.cronTime),
77
+ active: !scheduler_dash_context_1.SchedulerDashContext.disabledJobs.has(name),
75
78
  running: job.running ?? false,
76
- nextRun: job.nextDate()?.toISO() ?? null,
79
+ nextRun,
77
80
  history: this.storage.findByJob(name),
78
81
  metrics: this.storage.getMetrics(name),
79
82
  };