Skip to content

Commit

Permalink
docs: Document reasons to throw on public API functions and update co…
Browse files Browse the repository at this point in the history
…ntributing guidelines

Signed-off-by: Niklas Eicker <[email protected]>
  • Loading branch information
NiklasEi committed Sep 30, 2021
1 parent 7a00a50 commit 1aa11da
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## Next release
- Feature: schedule a job to run with delay

## v0.3.0 (2021-09-29)
- Feature: compatibility with mongodb v4 (removed typeorm dependency)
- Breaking: moved utility functions into classes
Expand Down
38 changes: 26 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,32 @@

Contributions are very welcome. The following will provide some helpful guidelines.

## How to build the project
## Getting started

Create a clone of the project and navigate into the directory.

### Install all dependencies

```shell
npm i
```

### Build the project

```shell
npm run build
```

### Run tests

```shell
npm run test
```
$ cd /path/to/git/clone/of/Momo
$ npm run build

### Format the code

```shell
npm run format
```

## How to contribute
Expand All @@ -16,7 +37,8 @@ If you want to submit a contribution, please follow the following workflow:
* Fork the project
* Create a feature branch
* Add your contribution
* When you're completely done, build the project and run all tests via `npm run test`
* Make sure that the project successfully builds and all tests are green
* Please format your code
* Create a Pull Request

### Commits
Expand All @@ -37,11 +59,3 @@ If your Pull Request resolves an issue, please add a respective line to the end,
```
Resolves #123
```

### Formatting

Please adjust your code formatter to the general style of the project or use
```
npm run format
```
to format the code.
17 changes: 17 additions & 0 deletions src/schedule/Schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export class Schedule extends LogEmitter {
*
* @param momoJob the job to define
* @returns true if jobs was defined, false if the job was invalid
*
* @throws if the database throws
*/
public async define(momoJob: MomoJob): Promise<boolean> {
const job = toJob(momoJob);
Expand Down Expand Up @@ -98,6 +100,8 @@ export class Schedule extends LogEmitter {
* Updates made to jobs after starting the scheduler are picked up
* automatically from the database, EXCEPT for changes to the interval.
* Start the scheduler again to change a job's interval.
*
* @throws if an interval cannot be parsed or the database throws
*/
public async start(): Promise<void> {
this.logger.debug('start all jobs', { count: this.count() });
Expand All @@ -113,6 +117,7 @@ export class Schedule extends LogEmitter {
* Start the scheduler again to change a job's interval.
*
* @param name the job to start
* @throws if the jobs interval cannot be parsed or the database throws
*/
public async startJob(name: string): Promise<void> {
const jobScheduler = this.jobSchedulers[name];
Expand Down Expand Up @@ -180,6 +185,8 @@ export class Schedule extends LogEmitter {
* Does nothing if no job with the given name exists.
*
* @param name the job to remove
*
* @throws if the database throws
*/
public async removeJob(name: string): Promise<void> {
await this.cancelJob(name);
Expand All @@ -189,6 +196,8 @@ export class Schedule extends LogEmitter {

/**
* Stops all scheduled jobs and removes them from the schedule and the database.
*
* @throws if the database throws
*/
public async remove(): Promise<void> {
const names = Object.keys(this.jobSchedulers);
Expand All @@ -210,6 +219,8 @@ export class Schedule extends LogEmitter {

/**
* Returns descriptions of all jobs on the schedule.
*
* @throws if the database throws
*/
public async list(): Promise<MomoJobDescription[]> {
return (
Expand All @@ -220,6 +231,8 @@ export class Schedule extends LogEmitter {
* Retrieves execution information about the job from the database. Returns undefined if the job cannot be found or was never executed.
*
* @param name the job to check
*
* @throws if the database throws
*/
public async check(name: string): Promise<ExecutionInfo | undefined> {
return this.jobRepository.check(name);
Expand All @@ -232,6 +245,8 @@ export class Schedule extends LogEmitter {
* This also removes jobs that are not on this schedule, but were defined by other schedules.
* However, does NOT stop job executions - this will cause currently running jobs to fail.
* Consider using stop/cancel/remove methods instead!
*
* @throws if the database throws
*/
public async clear(): Promise<void> {
await this.jobRepository.delete();
Expand All @@ -241,6 +256,8 @@ export class Schedule extends LogEmitter {
* Returns the description of a job or undefined if no job with the given name is on the schedule.
*
* @param name the name of the job to return
*
* @throws if the database throws
*/
public async get(name: string): Promise<MomoJobDescription | undefined> {
return this.jobSchedulers[name]?.getJobDescription();
Expand Down

0 comments on commit 1aa11da

Please sign in to comment.