graphile-worker
Advanced tools
Comparing version 0.2.0 to 0.3.0-rc.0
@@ -1,5 +0,5 @@ | ||
export interface Deferred<T> extends Promise<T> { | ||
export interface Deferred<T = void> extends Promise<T> { | ||
resolve: (result?: T) => void; | ||
reject: (error: Error) => void; | ||
} | ||
export default function deferred<T = void>(): Deferred<T>; | ||
export default function defer<T = void>(): Deferred<T>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function deferred() { | ||
function defer() { | ||
let resolve; | ||
@@ -10,6 +10,6 @@ let reject; | ||
}), | ||
// @ts-ignore Non-sense, these aren't used before being defined. | ||
// @ts-ignore error TS2454: Variable 'resolve' is used before being assigned. | ||
{ resolve, reject }); | ||
} | ||
exports.default = deferred; | ||
exports.default = defer; | ||
//# sourceMappingURL=deferred.js.map |
@@ -110,5 +110,2 @@ "use strict"; | ||
if (running) { | ||
throw new Error("Runner is already stopped"); | ||
} | ||
else { | ||
running = false; | ||
@@ -118,2 +115,5 @@ await workerPool.release(); | ||
} | ||
else { | ||
throw new Error("Runner is already stopped"); | ||
} | ||
}, | ||
@@ -120,0 +120,0 @@ addJob: helpers_1.makeAddJob(withPgClient), |
{ | ||
"name": "graphile-worker", | ||
"version": "0.2.0", | ||
"version": "0.3.0-rc.0", | ||
"description": "Job queue for PostgreSQL", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -423,2 +423,3 @@ # graphile-worker | ||
- `max_attempts` - if this task fails, how many times should we retry it? Default: 25. | ||
- `job_key` - unique identifier for the job, used to update or remove it later if needed (see [Updating and removing jobs](#updating-and-removing-jobs)) | ||
@@ -437,3 +438,3 @@ Typically you'll want to set the `identifier` and `payload`: | ||
You can skip parameters you don't need by using PostgreSQL's named parameter support: | ||
It's recommended that you use [PostgreSQL's named parameters](https://www.postgresql.org/docs/current/sql-syntax-calling-funcs.html#SQL-SYNTAX-CALLING-FUNCS-NAMED) for the other parameters so that you only need specify the arguments you're using: | ||
@@ -444,2 +445,16 @@ ```sql | ||
**TIP**: if you want to run a job after a variable number of seconds according | ||
to the database time (rather than the application time), you can use | ||
interval multiplication; see `run_at` in this example: | ||
```sql | ||
SELECT graphile_worker.add_job( | ||
$1, | ||
payload := $2, | ||
queue_name := $3, | ||
max_attempts := $4, | ||
run_at := NOW() + ($5 * INTERVAL '1 second') | ||
); | ||
``` | ||
**NOTE:** `graphile_worker.add_job(...)` requires database owner privileges | ||
@@ -510,2 +525,21 @@ to execute. To allow lower-privileged users to call it, wrap it inside a | ||
## Updating and removing jobs | ||
Jobs scheduled with a `job_key` parameter may be updated later, provided they are still pending, by calling `add_job` again with the same `job_key` value. This can be used for rescheduling jobs or to ensure only one of a given job is scheduled at a time. When a job is updated, any omitted parameters are reset to their defaults, with the exception of `queue_name` which persists unless overridden. For example after the below SQL transaction, the `send_email` job will run only once, with the payload `'{"count": 2}'`: | ||
```sql | ||
BEGIN; | ||
SELECT graphile_worker.add_job('send_email', '{"count": 1}', job_key := 'abc'); | ||
SELECT graphile_worker.add_job('send_email', '{"count": 2}', job_key := 'abc'); | ||
COMMIT; | ||
``` | ||
Pending jobs may also be removed using `job_key`: | ||
```sql | ||
SELECT graphile_worker.remove_job('abc'); | ||
``` | ||
**Note:** If a job is updated using `add_job` once it is already running or completed, the second job will be scheduled separately, meaning both will run. Likewise, calling `remove_job` for a running or completed job is a no-op. | ||
## Uninstallation | ||
@@ -603,1 +637,35 @@ | ||
``` | ||
### Using Docker | ||
Start the dev db and app in the background | ||
``` | ||
docker-compose up -d | ||
``` | ||
Run the tests | ||
``` | ||
docker-compose exec app yarn jest -i | ||
``` | ||
Reset the test db | ||
``` | ||
cat __tests__/reset-db.sql | docker-compose exec -T db psql -U postgres graphile_worker_test | ||
``` | ||
Run the perf tests | ||
``` | ||
docker-compose exec app ./perfTest/run.sh | ||
``` | ||
monitor the container logs | ||
``` | ||
docker-compose logs -f db | ||
docker-compose logs -f app | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
115985
51
667