agenda 4.1.3 → 4.3.0

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.
Files changed (67) hide show
  1. package/History.md +27 -6
  2. package/README.md +50 -13
  3. package/dist/agenda/cancel.d.ts +2 -2
  4. package/dist/agenda/cancel.d.ts.map +1 -1
  5. package/dist/agenda/cancel.js +3 -3
  6. package/dist/agenda/cancel.js.map +1 -1
  7. package/dist/agenda/close.d.ts +1 -1
  8. package/dist/agenda/close.js +1 -1
  9. package/dist/agenda/create.d.ts.map +1 -1
  10. package/dist/agenda/create.js +2 -1
  11. package/dist/agenda/create.js.map +1 -1
  12. package/dist/agenda/database.d.ts +9 -8
  13. package/dist/agenda/database.d.ts.map +1 -1
  14. package/dist/agenda/database.js +17 -19
  15. package/dist/agenda/database.js.map +1 -1
  16. package/dist/agenda/db-init.d.ts +2 -2
  17. package/dist/agenda/db-init.d.ts.map +1 -1
  18. package/dist/agenda/db-init.js +5 -0
  19. package/dist/agenda/db-init.js.map +1 -1
  20. package/dist/agenda/define.d.ts +5 -1
  21. package/dist/agenda/define.d.ts.map +1 -1
  22. package/dist/agenda/define.js +1 -0
  23. package/dist/agenda/define.js.map +1 -1
  24. package/dist/agenda/disable.d.ts +11 -0
  25. package/dist/agenda/disable.d.ts.map +1 -0
  26. package/dist/agenda/disable.js +42 -0
  27. package/dist/agenda/disable.js.map +1 -0
  28. package/dist/agenda/enable.d.ts +12 -0
  29. package/dist/agenda/enable.d.ts.map +1 -0
  30. package/dist/agenda/enable.js +43 -0
  31. package/dist/agenda/enable.js.map +1 -0
  32. package/dist/agenda/find-and-lock-next-job.d.ts.map +1 -1
  33. package/dist/agenda/find-and-lock-next-job.js +39 -60
  34. package/dist/agenda/find-and-lock-next-job.js.map +1 -1
  35. package/dist/agenda/index.d.ts +11 -5
  36. package/dist/agenda/index.d.ts.map +1 -1
  37. package/dist/agenda/index.js +9 -4
  38. package/dist/agenda/index.js.map +1 -1
  39. package/dist/agenda/jobs.d.ts +2 -2
  40. package/dist/agenda/jobs.d.ts.map +1 -1
  41. package/dist/agenda/jobs.js.map +1 -1
  42. package/dist/agenda/mongo.d.ts +2 -2
  43. package/dist/agenda/mongo.d.ts.map +1 -1
  44. package/dist/agenda/mongo.js.map +1 -1
  45. package/dist/agenda/save-job.d.ts.map +1 -1
  46. package/dist/agenda/save-job.js +23 -9
  47. package/dist/agenda/save-job.js.map +1 -1
  48. package/dist/agenda/stop.js.map +1 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js.map +1 -1
  51. package/dist/job/compute-next-run-at.js.map +1 -1
  52. package/dist/job/index.d.ts +12 -2
  53. package/dist/job/index.d.ts.map +1 -1
  54. package/dist/job/index.js +4 -0
  55. package/dist/job/index.js.map +1 -1
  56. package/dist/job/repeat-every.js.map +1 -1
  57. package/dist/job/run.d.ts.map +1 -1
  58. package/dist/job/run.js +7 -4
  59. package/dist/job/run.js.map +1 -1
  60. package/dist/job/set-shouldsaveresult.d.ts +7 -0
  61. package/dist/job/set-shouldsaveresult.d.ts.map +1 -0
  62. package/dist/job/set-shouldsaveresult.js +13 -0
  63. package/dist/job/set-shouldsaveresult.js.map +1 -0
  64. package/dist/utils/process-jobs.d.ts.map +1 -1
  65. package/dist/utils/process-jobs.js +8 -3
  66. package/dist/utils/process-jobs.js.map +1 -1
  67. package/package.json +24 -21
package/History.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  - _Contributions welcome!_ https://github.com/agenda/agenda/pulls
4
4
 
5
+ - # 4.2.0 / 2021-08-09
6
+
7
+ - fix: deprecation warning for collection.findOneAndUpdate ([#1338](https://github.com/agenda/agenda/pull/1338)) thanks @frobinsonj
8
+
9
+ - # 4.2.0 / 2021-08-05
10
+
11
+ - Feat: Add top level disable and enable ([#1109](https://github.com/agenda/agenda/pull/1109)) thanks @pdfowler
12
+ - fix(history): match cron-parser pattern ([#1335](https://github.com/agenda/agenda/pull/1335)) thanks @dockleryxk
13
+ - fix: "RangeError: Maximum call stack size exceeded" ([#1365](https://github.com/agenda/agenda/pull/1365)) thanks @koresar
14
+ - fix: JobAttributes.lockedAt to allow null values ([#1340](https://github.com/agenda/agenda/pull/1340)) thanks @tjramage
15
+ - Updated dependencies: `mongodb@3.6.6`, `lodash@4.17.21`, as well as various dev dependencies.
16
+ - Added node 16 in tests ([#1314](https://github.com/agenda/agenda/pull/1086)) thanks @simison
17
+
18
+ # 4.1.3 / 2021-05-02
19
+
20
+ - fix: export cjs and es (#1298) thanks @koresar
21
+
22
+ # 4.1.2 / 2021-05-02
23
+
24
+ - fix: broken main cjs export works again. See more [here](https://github.com/agenda/agenda/issues/1266#issuecomment-830628762).
25
+
5
26
  # 4.1.2 / 2021-04-04
6
27
 
7
28
  - Docs, JSDocs and TS typo fixes. Thanks @niftylettuce @thebestnom @simllll and @Igor-lkm
@@ -82,12 +103,12 @@
82
103
  ```
83
104
  * * * * * *
84
105
  | | | | | |
85
- | | | | | +-- Year (range: 1900-3000)
86
- | | | | +---- Day of the Week (range: 1-7, 1 standing for Monday)
87
- | | | +------ Month of the Year (range: 1-12) NOTE: Difference here
88
- | | +-------- Day of the Month (range: 1-31)
89
- | +---------- Hour (range: 0-23)
90
- +------------ Minute (range: 0-59)
106
+ | | | | | +-- Day of the Week (range: 0-7, 0 or 7 is Sunday)
107
+ | | | | +---- Month of the Year (range: 1-12) NOTE: Difference here
108
+ | | | +------ Day of the Month (range: 1-31)
109
+ | | +-------- Hour (range: 0-23)
110
+ | +---------- Minute (range: 0-59)
111
+ +------------ Second (range: 0-59, optional)
91
112
  ```
92
113
 
93
114
  # 3.1.0 / 2020-04-07
package/README.md CHANGED
@@ -4,22 +4,13 @@
4
4
  <p align="center">
5
5
  A light-weight job scheduling library for Node.js
6
6
  </p>
7
- <p align="center">
8
- <a href="https://slackin-ekwifvcwbr.now.sh/"><img src="https://slackin-ekwifvcwbr.now.sh/badge.svg" alt="Slack Status"></a>
9
- <a href="https://david-dm.org/agenda/agenda"><img src="https://david-dm.org/agenda/agenda/status.svg" alt="dependencies Status"></a>
10
- <a href="https://david-dm.org/agenda/agenda?type=dev"><img src="https://david-dm.org/agenda/agenda/dev-status.svg" alt="devDependencies Status"></a>
11
- <a href="https://coveralls.io/github/agenda/agenda?branch=master"><img src="https://coveralls.io/repos/github/agenda/agenda/badge.svg?branch=master" alt="Coverage Status"></a>
12
- <br>
13
- <br>
14
- <br>
15
- </p>
16
7
 
17
8
  # Agenda offers
18
9
 
19
10
  - Minimal overhead. Agenda aims to keep its code base small.
20
11
  - Mongo backed persistence layer.
21
12
  - Promises based API.
22
- - Scheduling with configurable priority, concurrency, and repeating.
13
+ - Scheduling with configurable priority, concurrency, repeating and persistence of job results.
23
14
  - Scheduling via cron or human readable syntax.
24
15
  - Event backed job queue that you can hook into.
25
16
  - [Agenda-rest](https://github.com/agenda/agenda-rest): optional standalone REST API.
@@ -54,6 +45,10 @@ _Kudos for making the comparison chart goes to [Bull](https://www.npmjs.com/pack
54
45
 
55
46
  # Installation
56
47
 
48
+ ### Notice
49
+
50
+ In order to support new MongoDB 5.0 and mongodb node.js driver/package the next release (5.x.x) of Agenda will be major. The required node version will become >=12. The mongodb dependency version will become >=3.2.
51
+
57
52
  Install via NPM
58
53
 
59
54
  npm install agenda
@@ -63,16 +58,19 @@ You will also need a working [Mongo](https://www.mongodb.com/) database (v3) to
63
58
  # CJS / Module Imports
64
59
 
65
60
  for regular javascript code, just use the default entrypoint
61
+
66
62
  ```js
67
- const Agenda = require('agenda');
63
+ const Agenda = require("agenda");
68
64
  ```
69
65
 
70
66
  For Typescript, Webpack or other module imports, use `agenda/es` entrypoint:
71
67
  e.g.
68
+
72
69
  ```ts
73
- import { Agenda } from 'agenda/es';
70
+ import { Agenda } from "agenda/es";
74
71
  ```
75
- ***NOTE***: If you're migrating from `@types/agenda` you also should change imports to `agenda/es`.
72
+
73
+ **_NOTE_**: If you're migrating from `@types/agenda` you also should change imports to `agenda/es`.
76
74
  Instead of `import Agenda from 'agenda'` use `import Agenda from 'agenda/es'`.
77
75
 
78
76
  # Example Usage
@@ -346,6 +344,13 @@ Takes a `query` which specifies the sort query to be used for finding and lockin
346
344
 
347
345
  By default it is `{ nextRunAt: 1, priority: -1 }`, which obeys a first in first out approach, with respect to priority.
348
346
 
347
+ ### disableAutoIndex(boolean)
348
+
349
+ Optional. Disables the automatic creation of the default index on the jobs table.
350
+ By default, Agenda creates an index to optimize its queries against Mongo while processing jobs.
351
+
352
+ This is useful if you want to use your own index in specific use-cases.
353
+
349
354
  ## Agenda Events
350
355
 
351
356
  An instance of an agenda will emit the following events:
@@ -382,6 +387,7 @@ the following:
382
387
  - `priority`: `(lowest|low|normal|high|highest|number)` specifies the priority
383
388
  of the job. Higher priority jobs will run first. See the priority mapping
384
389
  below
390
+ - `shouldSaveResult`: `boolean` flag that specifies whether the result of the job should also be stored in the database. Defaults to false
385
391
 
386
392
  Priority mapping:
387
393
 
@@ -546,6 +552,26 @@ const numRemoved = await agenda.cancel({ name: "printAnalyticsReport" });
546
552
 
547
553
  This functionality can also be achieved by first retrieving all the jobs from the database using `agenda.jobs()`, looping through the resulting array and calling `job.remove()` on each. It is however preferable to use `agenda.cancel()` for this use case, as this ensures the operation is atomic.
548
554
 
555
+ ### disable(mongodb-native query)
556
+
557
+ Disables any jobs matching the passed mongodb-native query, preventing any matching jobs from being run by the Job Processor.
558
+
559
+ ```js
560
+ const numDisabled = await agenda.disable({ name: "pollExternalService" });
561
+ ```
562
+
563
+ Similar to `agenda.cancel()`, this functionality can be acheived with a combination of `agenda.jobs()` and `job.disable()`
564
+
565
+ ### enable(mongodb-native query)
566
+
567
+ Enables any jobs matching the passed mongodb-native query, allowing any matching jobs to be run by the Job Processor.
568
+
569
+ ```js
570
+ const numEnabled = await agenda.enable({ name: "pollExternalService" });
571
+ ```
572
+
573
+ Similar to `agenda.cancel()`, this functionality can be acheived with a combination of `agenda.jobs()` and `job.enable()`
574
+
549
575
  ### purge()
550
576
 
551
577
  Removes all jobs in the database without defined behaviors. Useful if you change a definition name and want to remove old jobs. Returns a Promise resolving to the number of removed jobs, or rejecting on error.
@@ -692,6 +718,17 @@ job.priority("low");
692
718
  await job.save();
693
719
  ```
694
720
 
721
+ ### setShouldSaveResult(setShouldSaveResult)
722
+
723
+ Specifies whether the result of the job should also be stored in the database. Defaults to false.
724
+
725
+ ```js
726
+ job.setShouldSaveResult(true);
727
+ await job.save();
728
+ ```
729
+
730
+ The data returned by the job will be available on the `result` attribute after it succeeded and got retrieved again from the database, e.g. via `agenda.jobs(...)` or through the [success job event](#agenda-events)).
731
+
695
732
  ### unique(properties, [options])
696
733
 
697
734
  Ensure that only one instance of this job exists with the specified properties
@@ -1,5 +1,5 @@
1
1
  import { Agenda } from ".";
2
- import { FilterQuery } from "mongodb";
2
+ import { Document, Filter } from "mongodb";
3
3
  /**
4
4
  * Cancels any jobs matching the passed MongoDB query, and removes them from the database.
5
5
  * @name Agenda#cancel
@@ -7,5 +7,5 @@ import { FilterQuery } from "mongodb";
7
7
  * @param query MongoDB query to use when cancelling
8
8
  * @caller client code, Agenda.purge(), Job.remove()
9
9
  */
10
- export declare const cancel: (this: Agenda, query: FilterQuery<any>) => Promise<number | undefined>;
10
+ export declare const cancel: (this: Agenda, query: Filter<Document>) => Promise<number | undefined>;
11
11
  //# sourceMappingURL=cancel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cancel.d.ts","sourceRoot":"","sources":["../../lib/agenda/cancel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAItC;;;;;;GAMG;AAEH,eAAO,MAAM,MAAM,SACX,MAAM,SACL,YAAY,GAAG,CAAC,KACtB,QAAQ,MAAM,GAAG,SAAS,CAU5B,CAAC"}
1
+ {"version":3,"file":"cancel.d.ts","sourceRoot":"","sources":["../../lib/agenda/cancel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAI3C;;;;;;GAMG;AAEH,eAAO,MAAM,MAAM,SACX,MAAM,SACL,OAAO,QAAQ,CAAC,KACtB,QAAQ,MAAM,GAAG,SAAS,CAU5B,CAAC"}
@@ -27,9 +27,9 @@ const cancel = function (query) {
27
27
  return __awaiter(this, void 0, void 0, function* () {
28
28
  debug("attempting to cancel all Agenda jobs", query);
29
29
  try {
30
- const { result } = yield this._collection.deleteMany(query);
31
- debug("%s jobs cancelled", result.n);
32
- return result.n;
30
+ const { deletedCount } = yield this._collection.deleteMany(query);
31
+ debug("%s jobs cancelled", deletedCount);
32
+ return deletedCount;
33
33
  }
34
34
  catch (error) {
35
35
  debug("error trying to delete jobs from MongoDB");
@@ -1 +1 @@
1
- {"version":3,"file":"cancel.js","sourceRoot":"","sources":["../../lib/agenda/cancel.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,kDAAmC;AAGnC,MAAM,KAAK,GAAG,eAAc,CAAC,eAAe,CAAC,CAAC;AAE9C;;;;;;GAMG;AACH,8DAA8D;AACvD,MAAM,MAAM,GAAG,UAEpB,KAAuB;;QAEvB,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QACrD,IAAI;YACF,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAC5D,KAAK,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;YACrC,OAAO,MAAM,CAAC,CAAC,CAAC;SACjB;QAAC,OAAO,KAAK,EAAE;YACd,KAAK,CAAC,0CAA0C,CAAC,CAAC;YAClD,MAAM,KAAK,CAAC;SACb;IACH,CAAC;CAAA,CAAC;AAbW,QAAA,MAAM,UAajB"}
1
+ {"version":3,"file":"cancel.js","sourceRoot":"","sources":["../../lib/agenda/cancel.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,kDAAmC;AAGnC,MAAM,KAAK,GAAG,eAAc,CAAC,eAAe,CAAC,CAAC;AAE9C;;;;;;GAMG;AACH,8DAA8D;AACvD,MAAM,MAAM,GAAG,UAEpB,KAAuB;;QAEvB,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QACrD,IAAI;YACF,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAClE,KAAK,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;YACzC,OAAO,YAAY,CAAC;SACrB;QAAC,OAAO,KAAK,EAAE;YACd,KAAK,CAAC,0CAA0C,CAAC,CAAC;YAClD,MAAM,KAAK,CAAC;SACb;IACH,CAAC;CAAA,CAAC;AAbW,QAAA,MAAM,UAajB"}
@@ -4,7 +4,7 @@ import { Agenda } from ".";
4
4
  * If the mongoDb instance was supplied during instantiation or via agenda.mongo, this function will do nothing and return agenda anyway.
5
5
  * @name Agenda#close
6
6
  * @function
7
- * @param [option]: { force: boolean } Force close, emitting no events
7
+ * @param [option] {{ force: boolean }} Force close, emitting no events
8
8
  *
9
9
  *
10
10
  * @caller client code
@@ -20,7 +20,7 @@ const debug = debug_1.default("agenda:close");
20
20
  * If the mongoDb instance was supplied during instantiation or via agenda.mongo, this function will do nothing and return agenda anyway.
21
21
  * @name Agenda#close
22
22
  * @function
23
- * @param [option]: { force: boolean } Force close, emitting no events
23
+ * @param [option] {{ force: boolean }} Force close, emitting no events
24
24
  *
25
25
  *
26
26
  * @caller client code
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../lib/agenda/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAI3B;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,SAAmB,MAAM,QAAQ,MAAM,QAAQ,GAAG,KAAG,GAOvE,CAAC"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../lib/agenda/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAI3B;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,SAAmB,MAAM,QAAQ,MAAM,QAAQ,GAAG,KAAG,GAQvE,CAAC"}
@@ -19,7 +19,8 @@ const create = function (name, data) {
19
19
  const priority = this._definitions[name]
20
20
  ? this._definitions[name].priority
21
21
  : 0;
22
- const job = new job_1.Job({ name, data, type: "normal", priority, agenda: this });
22
+ const shouldSaveResult = this._definitions[name] ? this._definitions[name].shouldSaveResult || false : false;
23
+ const job = new job_1.Job({ name, data, type: "normal", priority, shouldSaveResult, agenda: this });
23
24
  return job;
24
25
  };
25
26
  exports.create = create;
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../../lib/agenda/create.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAmC;AACnC,gCAA6B;AAG7B,MAAM,KAAK,GAAG,eAAc,CAAC,eAAe,CAAC,CAAC;AAE9C;;;;;;GAMG;AACI,MAAM,MAAM,GAAG,UAAwB,IAAY,EAAE,IAAS;IACnE,KAAK,CAAC,6BAA6B,EAAE,IAAI,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;QACtC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,QAAQ;QAClC,CAAC,CAAC,CAAC,CAAC;IACN,MAAM,GAAG,GAAG,IAAI,SAAG,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5E,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAPW,QAAA,MAAM,UAOjB"}
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../lib/agenda/create.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAmC;AACnC,gCAA6B;AAG7B,MAAM,KAAK,GAAG,eAAc,CAAC,eAAe,CAAC,CAAC;AAE9C;;;;;;GAMG;AACI,MAAM,MAAM,GAAG,UAAwB,IAAY,EAAE,IAAS;IACnE,KAAK,CAAC,6BAA6B,EAAE,IAAI,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;QACtC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,QAAQ;QAClC,CAAC,CAAC,CAAC,CAAC;IACN,MAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,gBAAgB,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;IAC5G,MAAM,GAAG,GAAG,IAAI,SAAG,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9F,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AARW,QAAA,MAAM,UAQjB"}
@@ -1,19 +1,20 @@
1
- import { Collection, MongoClientOptions } from "mongodb";
1
+ import { AnyError, Collection, MongoClientOptions } from "mongodb";
2
2
  import { Agenda } from ".";
3
3
  /**
4
4
  * Connect to the spec'd MongoDB server and database.
5
- * @name Agenda#database
6
- * @function
7
- * @param url MongoDB server URI
8
- * @param [collection] name of collection to use. Defaults to `agendaJobs`
9
- * @param [options] options for connecting
10
- * @param [cb] callback of MongoDB connection
5
+ *
11
6
  * NOTE:
12
7
  * If `url` includes auth details then `options` must specify: { 'uri_decode_auth': true }. This does Auth on
13
8
  * the specified database, not the Admin database. If you are using Auth on the Admin DB and not on the Agenda DB,
14
9
  * then you need to authenticate against the Admin DB and then pass the MongoDB instance into the constructor
15
10
  * or use Agenda.mongo(). If your app already has a MongoDB connection then use that. ie. specify config.mongo in
16
11
  * the constructor or use Agenda.mongo().
12
+ * @name Agenda#database
13
+ * @function
14
+ * @param url MongoDB server URI
15
+ * @param [collection] name of collection to use. Defaults to `agendaJobs`
16
+ * @param [options] options for connecting
17
+ * @param [cb] callback of MongoDB connection
17
18
  */
18
- export declare const database: (this: Agenda, url: string, collection?: string | undefined, options?: MongoClientOptions | undefined, cb?: ((error: Error, collection: Collection<any> | null) => void) | undefined) => Agenda | void;
19
+ export declare const database: (this: Agenda, url: string, collection?: string | undefined, options?: MongoClientOptions, cb?: ((error: AnyError | undefined, collection: Collection<any> | null) => void) | undefined) => Agenda | void;
19
20
  //# sourceMappingURL=database.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../lib/agenda/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAe,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGtE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAI3B;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,SACb,MAAM,OACP,MAAM,2FAGE,KAAK,cAAc,WAAW,GAAG,CAAC,GAAG,IAAI,KAAK,IAAI,kBAC9D,MAAM,GAAG,IAqCX,CAAC"}
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../lib/agenda/database.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAe,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAK3B;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ,SACb,MAAM,OACP,MAAM,6CAEF,kBAAkB,gBACd,QAAQ,GAAG,SAAS,cAAc,WAAW,GAAG,CAAC,GAAG,IAAI,KAAK,IAAI,kBAC7E,MAAM,GAAG,IAiCX,CAAC"}
@@ -4,38 +4,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.database = void 0;
7
- const mongodb_1 = require("mongodb");
8
7
  const debug_1 = __importDefault(require("debug"));
8
+ const mongodb_1 = require("mongodb");
9
9
  const has_mongo_protocol_1 = require("./has-mongo-protocol");
10
10
  const debug = debug_1.default("agenda:database");
11
11
  /**
12
12
  * Connect to the spec'd MongoDB server and database.
13
- * @name Agenda#database
14
- * @function
15
- * @param url MongoDB server URI
16
- * @param [collection] name of collection to use. Defaults to `agendaJobs`
17
- * @param [options] options for connecting
18
- * @param [cb] callback of MongoDB connection
13
+ *
19
14
  * NOTE:
20
15
  * If `url` includes auth details then `options` must specify: { 'uri_decode_auth': true }. This does Auth on
21
16
  * the specified database, not the Admin database. If you are using Auth on the Admin DB and not on the Agenda DB,
22
17
  * then you need to authenticate against the Admin DB and then pass the MongoDB instance into the constructor
23
18
  * or use Agenda.mongo(). If your app already has a MongoDB connection then use that. ie. specify config.mongo in
24
19
  * the constructor or use Agenda.mongo().
20
+ * @name Agenda#database
21
+ * @function
22
+ * @param url MongoDB server URI
23
+ * @param [collection] name of collection to use. Defaults to `agendaJobs`
24
+ * @param [options] options for connecting
25
+ * @param [cb] callback of MongoDB connection
25
26
  */
26
- const database = function (url, collection, options, cb) {
27
+ const database = function (url, collection, options = {}, cb) {
27
28
  if (!has_mongo_protocol_1.hasMongoProtocol(url)) {
28
29
  url = "mongodb://" + url;
29
30
  }
30
- const reconnectOptions = (options === null || options === void 0 ? void 0 : options.useUnifiedTopology) === true
31
- ? {}
32
- : {
33
- autoReconnect: true,
34
- reconnectTries: Number.MAX_SAFE_INTEGER,
35
- reconnectInterval: this._processEvery,
36
- };
37
31
  collection = collection || "agendaJobs";
38
- options = Object.assign(Object.assign({}, reconnectOptions), options);
39
32
  mongodb_1.MongoClient.connect(url, options, (error, client) => {
40
33
  if (error) {
41
34
  debug("error connecting to MongoDB using collection: [%s]", collection);
@@ -48,9 +41,14 @@ const database = function (url, collection, options, cb) {
48
41
  return;
49
42
  }
50
43
  debug("successful connection to MongoDB using collection: [%s]", collection);
51
- this._db = client;
52
- this._mdb = client.db();
53
- this.db_init(collection, cb);
44
+ if (client) {
45
+ this._db = client;
46
+ this._mdb = client.db();
47
+ this.db_init(collection, cb);
48
+ }
49
+ else {
50
+ throw new Error("Mongo Client is undefined");
51
+ }
54
52
  });
55
53
  return this;
56
54
  };
@@ -1 +1 @@
1
- {"version":3,"file":"database.js","sourceRoot":"","sources":["../../lib/agenda/database.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAsE;AACtE,kDAAmC;AACnC,6DAAwD;AAGxD,MAAM,KAAK,GAAG,eAAc,CAAC,iBAAiB,CAAC,CAAC;AAEhD;;;;;;;;;;;;;;GAcG;AACI,MAAM,QAAQ,GAAG,UAEtB,GAAW,EACX,UAAmB,EACnB,OAA4B,EAC5B,EAA+D;IAE/D,IAAI,CAAC,qCAAgB,CAAC,GAAG,CAAC,EAAE;QAC1B,GAAG,GAAG,YAAY,GAAG,GAAG,CAAC;KAC1B;IAED,MAAM,gBAAgB,GACpB,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,kBAAkB,MAAK,IAAI;QAClC,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC;YACE,aAAa,EAAE,IAAI;YACnB,cAAc,EAAE,MAAM,CAAC,gBAAgB;YACvC,iBAAiB,EAAE,IAAI,CAAC,aAAa;SACtC,CAAC;IAER,UAAU,GAAG,UAAU,IAAI,YAAY,CAAC;IACxC,OAAO,mCAAQ,gBAAgB,GAAK,OAAO,CAAE,CAAC;IAC9C,qBAAW,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAClD,IAAI,KAAK,EAAE;YACT,KAAK,CAAC,oDAAoD,EAAE,UAAU,CAAC,CAAC;YACxE,IAAI,EAAE,EAAE;gBACN,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;aACjB;iBAAM;gBACL,MAAM,KAAK,CAAC;aACb;YAED,OAAO;SACR;QAED,KAAK,CACH,yDAAyD,EACzD,UAAU,CACX,CAAC;QACF,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,EAAE,CAAC;QACxB,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA3CW,QAAA,QAAQ,YA2CnB"}
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../../lib/agenda/database.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAmC;AACnC,qCAAgF;AAEhF,6DAAwD;AAExD,MAAM,KAAK,GAAG,eAAc,CAAC,iBAAiB,CAAC,CAAC;AAEhD;;;;;;;;;;;;;;;GAeG;AACI,MAAM,QAAQ,GAAG,UAEtB,GAAW,EACX,UAAmB,EACnB,UAA8B,EAAE,EAChC,EAA8E;IAE9E,IAAI,CAAC,qCAAgB,CAAC,GAAG,CAAC,EAAE;QAC1B,GAAG,GAAG,YAAY,GAAG,GAAG,CAAC;KAC1B;IAED,UAAU,GAAG,UAAU,IAAI,YAAY,CAAC;IAExC,qBAAW,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAClD,IAAI,KAAK,EAAE;YACT,KAAK,CAAC,oDAAoD,EAAE,UAAU,CAAC,CAAC;YACxE,IAAI,EAAE,EAAE;gBACN,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;aACjB;iBAAM;gBACL,MAAM,KAAK,CAAC;aACb;YAED,OAAO;SACR;QAED,KAAK,CACH,yDAAyD,EACzD,UAAU,CACX,CAAC;QAEF,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC;YAClB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,EAAE,CAAC;YACxB,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;SAC9B;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;SAC9C;IACH,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAvCW,QAAA,QAAQ,YAuCnB"}
@@ -1,4 +1,4 @@
1
- import { Collection } from "mongodb";
1
+ import { AnyError, Collection } from "mongodb";
2
2
  import { Agenda } from ".";
3
3
  /**
4
4
  * Setup and initialize the collection used to manage Jobs.
@@ -7,5 +7,5 @@ import { Agenda } from ".";
7
7
  * @param collection name or undefined for default 'agendaJobs'
8
8
  * @param [cb] called when the db is initialized
9
9
  */
10
- export declare const dbInit: (this: Agenda, collection?: string, cb?: ((error: Error, collection: Collection<any> | null) => void) | undefined) => void;
10
+ export declare const dbInit: (this: Agenda, collection?: string, cb?: ((error: AnyError | undefined, collection: Collection<any> | null) => void) | undefined) => void;
11
11
  //# sourceMappingURL=db-init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"db-init.d.ts","sourceRoot":"","sources":["../../lib/agenda/db-init.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAI3B;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,SACX,MAAM,qCAEC,KAAK,cAAc,WAAW,GAAG,CAAC,GAAG,IAAI,KAAK,IAAI,kBAC9D,IAqBF,CAAC"}
1
+ {"version":3,"file":"db-init.d.ts","sourceRoot":"","sources":["../../lib/agenda/db-init.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAI3B;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,SACX,MAAM,qCAEC,QAAQ,GAAG,SAAS,cAAc,WAAW,GAAG,CAAC,GAAG,IAAI,KAAK,IAAI,kBAC7E,IA2BF,CAAC"}
@@ -16,6 +16,11 @@ const debug = debug_1.default("agenda:db_init");
16
16
  const dbInit = function (collection = "agendaJobs", cb) {
17
17
  debug("init database collection using name [%s]", collection);
18
18
  this._collection = this._mdb.collection(collection);
19
+ if (this._disableAutoIndex) {
20
+ debug("skipping auto index creation");
21
+ this.emit("ready");
22
+ return;
23
+ }
19
24
  debug("attempting index creation");
20
25
  this._collection.createIndex(this._indices, { name: "findAndLockNextJobIndex" }, (error) => {
21
26
  if (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"db-init.js","sourceRoot":"","sources":["../../lib/agenda/db-init.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAmC;AAInC,MAAM,KAAK,GAAG,eAAc,CAAC,gBAAgB,CAAC,CAAC;AAE/C;;;;;;GAMG;AACI,MAAM,MAAM,GAAG,UAEpB,UAAU,GAAG,YAAY,EACzB,EAA+D;IAE/D,KAAK,CAAC,0CAA0C,EAAE,UAAU,CAAC,CAAC;IAC9D,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IACpD,KAAK,CAAC,2BAA2B,CAAC,CAAC;IACnC,IAAI,CAAC,WAAW,CAAC,WAAW,CAC1B,IAAI,CAAC,QAAQ,EACb,EAAE,IAAI,EAAE,yBAAyB,EAAE,EACnC,CAAC,KAAY,EAAE,EAAE;QACf,IAAI,KAAK,EAAE;YACT,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC/B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;SAC3B;aAAM;YACL,KAAK,CAAC,wBAAwB,CAAC,CAAC;YAChC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACpB;QAED,IAAI,EAAE,EAAE;YACN,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;SAC7B;IACH,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AAzBW,QAAA,MAAM,UAyBjB"}
1
+ {"version":3,"file":"db-init.js","sourceRoot":"","sources":["../../lib/agenda/db-init.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAmC;AAInC,MAAM,KAAK,GAAG,eAAc,CAAC,gBAAgB,CAAC,CAAC;AAE/C;;;;;;GAMG;AACI,MAAM,MAAM,GAAG,UAEpB,UAAU,GAAG,YAAY,EACzB,EAA8E;IAE9E,KAAK,CAAC,0CAA0C,EAAE,UAAU,CAAC,CAAC;IAC9D,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IACpD,IAAI,IAAI,CAAC,iBAAiB,EAAE;QAC1B,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnB,OAAO;KACR;IAED,KAAK,CAAC,2BAA2B,CAAC,CAAC;IACnC,IAAI,CAAC,WAAW,CAAC,WAAW,CAC1B,IAAI,CAAC,QAAQ,EACb,EAAE,IAAI,EAAE,yBAAyB,EAAE,EACnC,CAAC,KAAK,EAAE,EAAE;QACR,IAAI,KAAK,EAAE;YACT,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC/B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;SAC3B;aAAM;YACL,KAAK,CAAC,wBAAwB,CAAC,CAAC;YAChC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACpB;QAED,IAAI,EAAE,EAAE;YACN,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;SAC7B;IACH,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AA/BW,QAAA,MAAM,UA+BjB"}
@@ -26,6 +26,10 @@ export interface DefineOptions {
26
26
  * first.
27
27
  */
28
28
  priority?: JobPriority;
29
+ /**
30
+ * Should the return value of the job be persisted
31
+ */
32
+ shouldSaveResult?: boolean;
29
33
  }
30
34
  export declare type Processor = ((job: Job) => Promise<void>) | ((job: Job, done: () => void) => void);
31
35
  /**
@@ -37,5 +41,5 @@ export declare type Processor = ((job: Job) => Promise<void>) | ((job: Job, done
37
41
  * @param options options for job to run
38
42
  * @param [processor] function to be called to run actual job
39
43
  */
40
- export declare const define: (this: Agenda, name: string, options: DefineOptions | Processor, processor?: ((job: Job) => Promise<void>) | ((job: Job, done: () => void) => void) | undefined) => void;
44
+ export declare const define: (this: Agenda, name: string, options: DefineOptions | Processor, processor?: Processor | undefined) => void;
41
45
  //# sourceMappingURL=define.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../lib/agenda/define.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAE3B,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAI7B,oBAAY,WAAW;IACrB,OAAO,KAAK;IACZ,IAAI,KAAK;IACT,MAAM,IAAI;IACV,GAAG,MAAM;IACT,MAAM,MAAM;CACb;AAED,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,QAAQ,CAAC,EAAE,WAAW,CAAC;CACxB;AAED,oBAAY,SAAS,GACjB,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAC7B,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC,CAAC;AAE3C;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,SACX,MAAM,QACN,MAAM,WACH,aAAa,GAAG,SAAS,qBAfzB,GAAG,KAAK,QAAQ,IAAI,CAAC,WACrB,GAAG,QAAQ,MAAM,IAAI,KAAK,IAAI,kBAgBtC,IAsBF,CAAC"}
1
+ {"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../lib/agenda/define.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAE3B,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAI7B,oBAAY,WAAW;IACrB,OAAO,KAAK;IACZ,IAAI,KAAK;IACT,MAAM,IAAI;IACV,GAAG,MAAM;IACT,MAAM,MAAM;CACb;AAED,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,QAAQ,CAAC,EAAE,WAAW,CAAC;IAEvB;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,oBAAY,SAAS,GACjB,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAC7B,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC,CAAC;AAE3C;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,SACX,MAAM,QACN,MAAM,WACH,aAAa,GAAG,SAAS,wCAEjC,IAuBF,CAAC"}
@@ -36,6 +36,7 @@ const define = function (name, options, processor) {
36
36
  lockLifetime: options.lockLifetime || this._defaultLockLifetime,
37
37
  running: 0,
38
38
  locked: 0,
39
+ shouldSaveResult: options.shouldSaveResult || false
39
40
  };
40
41
  debug("job [%s] defined with following options: \n%O", name, this._definitions[name]);
41
42
  };
@@ -1 +1 @@
1
- {"version":3,"file":"define.js","sourceRoot":"","sources":["../../lib/agenda/define.ts"],"names":[],"mappings":";;;;;;AACA,kDAAmC;AAGnC,MAAM,KAAK,GAAG,eAAc,CAAC,eAAe,CAAC,CAAC;AAE9C,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,oDAAY,CAAA;IACZ,8CAAS,CAAA;IACT,iDAAU,CAAA;IACV,6CAAS,CAAA;IACT,mDAAY,CAAA;AACd,CAAC,EANW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAMtB;AA8BD;;;;;;;;GAQG;AACI,MAAM,MAAM,GAAG,UAEpB,IAAY,EACZ,OAAkC,EAClC,SAAqB;IAErB,IAAI,SAAS,KAAK,SAAS,EAAE;QAC3B,SAAS,GAAG,OAAoB,CAAC;QACjC,OAAO,GAAG,EAAE,CAAC;KACd;IAED,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG;QACxB,EAAE,EAAE,SAAS;QACb,WAAW,EACR,OAAyB,CAAC,WAAW,IAAI,IAAI,CAAC,mBAAmB;QACpE,SAAS,EAAG,OAAyB,CAAC,SAAS,IAAI,IAAI,CAAC,iBAAiB;QACzE,QAAQ,EAAG,OAAyB,CAAC,QAAQ,IAAI,WAAW,CAAC,MAAM;QACnE,YAAY,EACT,OAAyB,CAAC,YAAY,IAAI,IAAI,CAAC,oBAAoB;QACtE,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,CAAC;KACV,CAAC;IACF,KAAK,CACH,+CAA+C,EAC/C,IAAI,EACJ,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CACxB,CAAC;AACJ,CAAC,CAAC;AA3BW,QAAA,MAAM,UA2BjB"}
1
+ {"version":3,"file":"define.js","sourceRoot":"","sources":["../../lib/agenda/define.ts"],"names":[],"mappings":";;;;;;AACA,kDAAmC;AAGnC,MAAM,KAAK,GAAG,eAAc,CAAC,eAAe,CAAC,CAAC;AAE9C,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,oDAAY,CAAA;IACZ,8CAAS,CAAA;IACT,iDAAU,CAAA;IACV,6CAAS,CAAA;IACT,mDAAY,CAAA;AACd,CAAC,EANW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAMtB;AAmCD;;;;;;;;GAQG;AACI,MAAM,MAAM,GAAG,UAEpB,IAAY,EACZ,OAAkC,EAClC,SAAqB;IAErB,IAAI,SAAS,KAAK,SAAS,EAAE;QAC3B,SAAS,GAAG,OAAoB,CAAC;QACjC,OAAO,GAAG,EAAE,CAAC;KACd;IAED,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG;QACxB,EAAE,EAAE,SAAS;QACb,WAAW,EACR,OAAyB,CAAC,WAAW,IAAI,IAAI,CAAC,mBAAmB;QACpE,SAAS,EAAG,OAAyB,CAAC,SAAS,IAAI,IAAI,CAAC,iBAAiB;QACzE,QAAQ,EAAG,OAAyB,CAAC,QAAQ,IAAI,WAAW,CAAC,MAAM;QACnE,YAAY,EACT,OAAyB,CAAC,YAAY,IAAI,IAAI,CAAC,oBAAoB;QACtE,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,CAAC;QACT,gBAAgB,EAAG,OAAyB,CAAC,gBAAgB,IAAI,KAAK;KACvE,CAAC;IACF,KAAK,CACH,+CAA+C,EAC/C,IAAI,EACJ,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CACxB,CAAC;AACJ,CAAC,CAAC;AA5BW,QAAA,MAAM,UA4BjB"}
@@ -0,0 +1,11 @@
1
+ import { Filter } from "mongodb";
2
+ import { Agenda } from ".";
3
+ /**
4
+ * Disables any jobs matching the passed MongoDB query by setting the `disabled` flag to `true`
5
+ * @name Agenda#disable
6
+ * @function
7
+ * @param query MongoDB query to use when enabling
8
+ * @returns {Promise<number>} Resolved with the number of disabled job instances.
9
+ */
10
+ export declare const disable: (this: Agenda, query?: Filter<unknown>) => Promise<number>;
11
+ //# sourceMappingURL=disable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disable.d.ts","sourceRoot":"","sources":["../../lib/agenda/disable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAG3B;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,SACZ,MAAM,UACL,OAAO,OAAO,CAAC,KACrB,QAAQ,MAAM,CAYhB,CAAC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.disable = void 0;
16
+ const debug_1 = __importDefault(require("debug"));
17
+ const debug = debug_1.default("agenda:disable");
18
+ /**
19
+ * Disables any jobs matching the passed MongoDB query by setting the `disabled` flag to `true`
20
+ * @name Agenda#disable
21
+ * @function
22
+ * @param query MongoDB query to use when enabling
23
+ * @returns {Promise<number>} Resolved with the number of disabled job instances.
24
+ */
25
+ const disable = function (query = {}) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ debug("attempting to disable all jobs matching query", query);
28
+ try {
29
+ const { modifiedCount } = yield this._collection.updateMany(query, {
30
+ $set: { disabled: true },
31
+ });
32
+ debug("%s jobs disabled");
33
+ return modifiedCount;
34
+ }
35
+ catch (error) {
36
+ debug("error trying to mark jobs as `disabled`");
37
+ throw error;
38
+ }
39
+ });
40
+ };
41
+ exports.disable = disable;
42
+ //# sourceMappingURL=disable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disable.js","sourceRoot":"","sources":["../../lib/agenda/disable.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAmC;AAGnC,MAAM,KAAK,GAAG,eAAc,CAAC,gBAAgB,CAAC,CAAC;AAE/C;;;;;;GAMG;AACI,MAAM,OAAO,GAAG,UAErB,QAAyB,EAAE;;QAE3B,KAAK,CAAC,+CAA+C,EAAE,KAAK,CAAC,CAAC;QAC9D,IAAI;YACF,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,EAAE;gBACjE,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;aACzB,CAAC,CAAC;YACH,KAAK,CAAC,kBAAkB,CAAC,CAAC;YAC1B,OAAO,aAAa,CAAC;SACtB;QAAC,OAAO,KAAK,EAAE;YACd,KAAK,CAAC,yCAAyC,CAAC,CAAC;YACjD,MAAM,KAAK,CAAC;SACb;IACH,CAAC;CAAA,CAAC;AAfW,QAAA,OAAO,WAelB"}
@@ -0,0 +1,12 @@
1
+ import { Filter } from "mongodb";
2
+ import { Agenda } from ".";
3
+ /**
4
+ * Enables any jobs matching the passed MongoDB query by setting the `disabled` flag to `false`
5
+ * @name Agenda#enable
6
+ * @function
7
+ * @param query MongoDB query to use when enabling
8
+ * @caller client code, Agenda.purge(), Job.remove()
9
+ * @returns {Promise<Number>} A promise that contains the number of removed documents when fulfilled.
10
+ */
11
+ export declare const enable: (this: Agenda, query?: Filter<unknown>) => Promise<number>;
12
+ //# sourceMappingURL=enable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enable.d.ts","sourceRoot":"","sources":["../../lib/agenda/enable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAG3B;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,SACX,MAAM,UACL,OAAO,OAAO,CAAC,KACrB,QAAQ,MAAM,CAYhB,CAAC"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.enable = void 0;
16
+ const debug_1 = __importDefault(require("debug"));
17
+ const debug = debug_1.default("agenda:enable");
18
+ /**
19
+ * Enables any jobs matching the passed MongoDB query by setting the `disabled` flag to `false`
20
+ * @name Agenda#enable
21
+ * @function
22
+ * @param query MongoDB query to use when enabling
23
+ * @caller client code, Agenda.purge(), Job.remove()
24
+ * @returns {Promise<Number>} A promise that contains the number of removed documents when fulfilled.
25
+ */
26
+ const enable = function (query = {}) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ debug("attempting to enable all jobs matching query", query);
29
+ try {
30
+ const { modifiedCount } = yield this._collection.updateMany(query, {
31
+ $set: { disabled: false },
32
+ });
33
+ debug("%s jobs enabled", modifiedCount);
34
+ return modifiedCount;
35
+ }
36
+ catch (error) {
37
+ debug("error trying to mark jobs as `enabled`");
38
+ throw error;
39
+ }
40
+ });
41
+ };
42
+ exports.enable = enable;
43
+ //# sourceMappingURL=enable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enable.js","sourceRoot":"","sources":["../../lib/agenda/enable.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAmC;AAGnC,MAAM,KAAK,GAAG,eAAc,CAAC,eAAe,CAAC,CAAC;AAE9C;;;;;;;GAOG;AACI,MAAM,MAAM,GAAG,UAEpB,QAAyB,EAAE;;QAE3B,KAAK,CAAC,8CAA8C,EAAE,KAAK,CAAC,CAAC;QAC7D,IAAI;YACF,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,EAAE;gBACjE,IAAI,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE;aAC1B,CAAC,CAAC;YACH,KAAK,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC;YACxC,OAAO,aAAa,CAAC;SACtB;QAAC,OAAO,KAAK,EAAE;YACd,KAAK,CAAC,wCAAwC,CAAC,CAAC;YAChD,MAAM,KAAK,CAAC;SACb;IACH,CAAC;CAAA,CAAC;AAfW,QAAA,MAAM,UAejB"}
@@ -1 +1 @@
1
- {"version":3,"file":"find-and-lock-next-job.d.ts","sourceRoot":"","sources":["../../lib/agenda/find-and-lock-next-job.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAC3B,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAI7B;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,SACvB,MAAM,WACH,MAAM,cACH,GAAG,KACd,QAAQ,GAAG,GAAG,SAAS,CAsFzB,CAAC"}
1
+ {"version":3,"file":"find-and-lock-next-job.d.ts","sourceRoot":"","sources":["../../lib/agenda/find-and-lock-next-job.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAC3B,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAI7B;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,SACvB,MAAM,WACH,MAAM,cACH,GAAG,KACd,QAAQ,GAAG,GAAG,SAAS,CAyDzB,CAAC"}