Skip to content

Commit

Permalink
GITBOOK-35: No subject
Browse files Browse the repository at this point in the history
  • Loading branch information
code-xhyun authored and gitbook-bot committed May 9, 2024
1 parent d8f1fc5 commit 0c15790
Show file tree
Hide file tree
Showing 21 changed files with 223 additions and 59 deletions.
15 changes: 9 additions & 6 deletions gitbook/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@
* [Save](docs/managing-jobs/manually-working/save.md)
* [Unique](docs/managing-jobs/manually-working/unique.md)
* [RepeatEvery](docs/managing-jobs/manually-working/repeatevery.md)
* [Schedule](docs/managing-jobs/manually-working/repeatevery-1.md)
* [Remove](docs/managing-jobs/manually-working/repeatevery-2.md)
* [Priority](docs/managing-jobs/manually-working/repeatevery-3.md)
* [Touch](docs/managing-jobs/manually-working/repeatevery-4.md)
* [SetShouldSaveResult](docs/managing-jobs/manually-working/repeatevery-5.md)
* [Fail](docs/managing-jobs/manually-working/repeatevery-6.md)
* [RepeatAt](docs/managing-jobs/manually-working/repeatevery-1.md)
* [Schedule](docs/managing-jobs/manually-working/repeatevery-2.md)
* [Remove](docs/managing-jobs/manually-working/repeatevery-3.md)
* [Priority](docs/managing-jobs/manually-working/repeatevery-4.md)
* [Touch](docs/managing-jobs/manually-working/repeatevery-5.md)
* [SetShouldSaveResult](docs/managing-jobs/manually-working/repeatevery-6.md)
* [Run](docs/managing-jobs/manually-working/repeatevery-7.md)
* [Disable](docs/managing-jobs/manually-working/repeatevery-8.md)
* [Enable](docs/managing-jobs/manually-working/repeatevery-9.md)
16 changes: 9 additions & 7 deletions gitbook/docs/managing-jobs/manually-working/repeatevery-1.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Schedule
# RepeatAt



## `job.schedule(time)`
## `job.repeatAt(time)`

{% hint style="info" %}
The `schedule` method sets a job to run at a specific time determined by the input parameter. This method accepts both `Date` objects and date strings, providing flexibility in scheduling jobs.\
\
The `repeatAt` method schedules a job to repeat at a specific time that is stated in a [human-readable format](https://github.com/matthewmueller/date#examples) or as a precise time value. This capability is essential for scheduling jobs that must run at regular intervals on specific schedules.\


_This does **NOT** save the job in the database. you must explicitly declare_ [_`save()`_](save.md)_if you want to save it_
Expand All @@ -16,22 +15,25 @@ _This does **NOT** save the job in the database. you must explicitly declare_ [

{% code fullWidth="false" %}
```typescript
job.schedule(new Date(2023, 11, 17, 10, 30));
const job = pulse.create('test', {});
job.repeatAt("17:00");
await job.save(); // If you want to save it

```
{% endcode %}

### Parameters

* **`time`** (`string | Date`): The time at which the job is scheduled to run. This can be a `Date` object representing the exact time for the job to run.


* **`time`** (`string`): The time at which the job should repeat. This can be specified in a human-readable format (e.g., "03:00 PM", "15:00").[ Format docs](https://github.com/matthewmueller/date#examples)

\


### Returns

* **`Job`**: Returns the job instance with the updated `nextRunAt` attribute, allowing for method chaining.
* **`Job`**: Returns the job instance, allowing for method chaining. This facilitates additional configurations or method calls to be chained after setting the repeat time.

\

Expand Down
20 changes: 12 additions & 8 deletions gitbook/docs/managing-jobs/manually-working/repeatevery-2.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
# Remove
# Schedule



## `job.remove()`
## `job.schedule(time)`

{% hint style="info" %}
The `remove` method deletes a specific job from the MongoDB database, ensuring that it is no longer available for processing or querying. This method is crucial for managing job lifecycle and maintaining a clean job queue.
The `schedule` method sets a job to run at a specific time determined by the input parameter. This method accepts both `Date` objects and date strings, providing flexibility in scheduling jobs.\
\


_This does **NOT** save the job in the database. you must explicitly declare_ [_`save()`_](save.md)_if you want to save it_
{% endhint %}

### Example Usage

{% code fullWidth="false" %}
```typescript
job.remove();
const job = pulse.create('test', {});
job.schedule(new Date(2023, 11, 17, 10, 30));
await job.save(); // If you want to save it

```
{% endcode %}

### Parameters

* **`time`** (`string | Date`): The time at which the job is scheduled to run. This can be a `Date` object representing the exact time for the job to run.

\


### Returns

* **`Promise<number | undefined>`**: A promise that resolves with the number of documents removed from the database. If no document is found with the specified job ID, it may resolve to `undefined`.

\

* **`Job`**: Returns the job instance with the updated `nextRunAt` attribute, allowing for method chaining.

\

Expand Down
17 changes: 7 additions & 10 deletions gitbook/docs/managing-jobs/manually-working/repeatevery-3.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
# Priority
# Remove



## `job.priority(priority)`
## `job.remove()`

{% hint style="info" %}
The `priority` method assigns a priority level to a job, determining its processing order relative to other jobs in the queue. This method is crucial for managing execution precedence, especially in systems where certain tasks need urgent handling.
The `remove` method deletes a specific job from the MongoDB database, ensuring that it is no longer available for processing or querying. This method is crucial for managing job lifecycle and maintaining a clean job queue.


\
_This does **NOT** save the job in the database. you must explicitly declare_ [_`save()`_](save.md)_if you want to save it_
{% endhint %}

### Example Usage

{% code fullWidth="false" %}
```typescript
job.priority('highest');
await job.save(); // If you want to save it
const job = pulse.create('test', {});
job.remove();
```
{% endcode %}

### Parameters

* **`priority`** (`string` | `number`): A priority label (`'lowest'`, `'low'`, `'normal'`, `'high'`, `'highest'`) or a numeric value that corresponds to a predefined priority level.

\


### Returns

* **`Job`**: Returns the job instance, enabling method chaining.
* **`Promise<number | undefined>`**: A promise that resolves with the number of documents removed from the database. If no document is found with the specified job ID, it may resolve to `undefined`.

\

Expand Down
17 changes: 10 additions & 7 deletions gitbook/docs/managing-jobs/manually-working/repeatevery-4.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
# Touch
# Priority



## `job.touch()`
## `job.priority(priority)`

{% hint style="info" %}
The `touch` method updates the `lockedAt` timestamp of a job to the current time. This is particularly useful for ensuring that a job remains locked during long-running processes, preventing it from being considered as timed out or available for reprocessing by other workers or job instances.

The `priority` method assigns a priority level to a job, determining its processing order relative to other jobs in the queue. This method is crucial for managing execution precedence, especially in systems where certain tasks need urgent handling.

\
_This does **NOT** save the job in the database. you must explicitly declare_ [_`save()`_](save.md)_if you want to save it_
{% endhint %}

### Example Usage

{% code fullWidth="false" %}
```typescript
job.touch();
const job = pulse.create('test', {});
job.priority('highest');
job.save(); // If you want to save it
```
{% endcode %}

### Parameters


* **`priority`** (`string` | `number`): A priority label (`'lowest'`, `'low'`, `'normal'`, `'high'`, `'highest'`) or a numeric value that corresponds to a predefined priority level.

\


### Returns

* **`Promise<Job>`**: A promise that resolves with the updated job instance after the `lockedAt` time has been refreshed and the job has been saved.
* **`Job`**: Returns the job instance, enabling method chaining.

\

Expand Down
20 changes: 8 additions & 12 deletions gitbook/docs/managing-jobs/manually-working/repeatevery-5.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
# SetShouldSaveResult
# Touch



## `job.setShouldSaveResult(shouldSaveResult)`
## `job.touch()`

{% hint style="info" %}
The `setShouldSaveResult` method sets a flag indicating whether the outcome of the job's execution should be persisted in the database. This option is useful for managing storage and performance by selectively saving results only when necessary.
The `touch` method updates the `lockedAt` timestamp of a job to the current time. This is particularly useful for ensuring that a job remains locked during long-running processes, preventing it from being considered as timed out or available for reprocessing by other workers or job instances.


\
_This does **NOT** save the job in the database. you must explicitly declare_ [_`save()`_](save.md)_if you want to save it_
{% endhint %}

### Example Usage

{% code fullWidth="false" %}
```typescript
job.setShouldSaveResult(true);
await job.save();
const job = pulse.create('test', {});
job.touch();
```
{% endcode %}

### Parameters

* **`shouldSaveResult`** (`boolean`): A boolean flag that determines if the job’s result should be saved upon completion. Setting this to `true` enables result persistence, while `false` disables it.


\


### Returns

* **`Job`**: Returns the job instance, allowing for method chaining.

\

* **`Promise<Job>`**: A promise that resolves with the updated job instance after the `lockedAt` time has been refreshed and the job has been saved.

\

Expand Down
15 changes: 8 additions & 7 deletions gitbook/docs/managing-jobs/manually-working/repeatevery-6.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Fail
# SetShouldSaveResult



## `job.fail(reason)`
## `job.setShouldSaveResult(shouldSaveResult)`

{% hint style="info" %}
The `fail` method marks a job as failed and updates its attributes accordingly. It records the reason for failure, increments the failure count, and, if the job configuration permits, schedules the job for a retry based on the specified backoff strategy.
The `setShouldSaveResult` method sets a flag indicating whether the outcome of the job's execution should be persisted in the database. This option is useful for managing storage and performance by selectively saving results only when necessary.

\
_This does **NOT** save the job in the database. you must explicitly declare_ [_`save()`_](save.md)_if you want to save it_
Expand All @@ -15,21 +15,22 @@ _This does **NOT** save the job in the database. you must explicitly declare_ [

{% code fullWidth="false" %}
```typescript
job.fail(new Error('Unable to connect to database'));
await job.save();
const job = pulse.create('test', {});
job.setShouldSaveResult(true);
job.save(); // If you want to save it
```
{% endcode %}

### Parameters

* **`reason`** (`string | Error`): The reason for the job's failure, which can be provided as either a string or an Error object. If an Error object is provided, its message is used as the failure reason.
* **`shouldSaveResult`** (`boolean`): A boolean flag that determines if the job’s result should be saved upon completion. Setting this to `true` enables result persistence, while `false` disables it.

\


### Returns

* **`Job`**: Returns the job instance, allowing for method chaining. This enables further actions or logging after the failure is recorded.
* **`Job`**: Returns the job instance, allowing for method chaining.

\

Expand Down
46 changes: 46 additions & 0 deletions gitbook/docs/managing-jobs/manually-working/repeatevery-7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Run



## `job.run()`

{% hint style="info" %}
The `run` method executes the processing logic defined for a specific job, handling lifecycle events and managing job state updates based on execution results. It's designed to be an internal method that drives the main execution flow of jobs within the system.

\
**Normally you never need to call this manually.**
{% endhint %}

### Example Usage

{% code fullWidth="false" %}
```typescript
const job = pulse.create('test', {});
job.run()
.then(() => console.log('Job execution completed.'))
.catch(error => console.error('Job execution failed:', error));
```
{% endcode %}

### Parameters



\


### Returns

* **`Promise<Job>`**: A promise that resolves with the job instance after execution, whether successful or not. This method handles both successful completion and errors internally, ensuring the job's state is updated accordingly.

\


\


\




45 changes: 45 additions & 0 deletions gitbook/docs/managing-jobs/manually-working/repeatevery-8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Disable



## `job.disable()`

{% hint style="info" %}
The `disable` method sets a job's status to disabled, preventing it from being run by the job processing system. This is useful for temporarily halting a job's execution without permanently removing it from the job queue.

\
_This does **NOT** save the job in the database. you must explicitly declare_ [_`save()`_](save.md)_if you want to save it_
{% endhint %}

### Example Usage

{% code fullWidth="false" %}
```typescript
const job = pulse.create('test', {});
job.disable();
job.save(); // If you want to save it
```
{% endcode %}

### Parameters



\


### Returns

* **`Job`**: Returns the job instance, allowing for method chaining. This facilitates further modifications to the job or chaining additional method calls.

\


\


\




Loading

1 comment on commit 0c15790

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 51%
53.65% (543/1012) 38.79% (116/299) 46.79% (73/156)

Pulse Test Report

Tests Skipped Failures Errors Time
45 0 💤 0 ❌ 0 🔥 8.08s ⏱️

Please sign in to comment.