Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Client

Hierarchy

  • EventEmitter
    • Client

Constructors

constructor

Accessors

isConnected

  • get isConnected(): boolean
  • Indicates whether client is connected to the server.

    Returns boolean

isWorking

  • get isWorking(): boolean
  • Indicates whether client is waiting for server response.

    Returns boolean

queueSize

  • get queueSize(): number
  • Amount of requests waiting in queue, including connect and disconnect.

    Returns number

Client Methods

connect

  • connect(): Promise<void>

disconnect

  • disconnect(force?: boolean): Promise<void>
  • Disconnect the client from server after all pending requests performed.

    If {force} set to truthy value - only currently running request will be awaited.

    Parameters

    • force: boolean = false

    Returns Promise<void>

Other Commands Methods

kick

  • kick(bound: number): Promise<number>
  • The kick command applies only to the currently used tube. It moves jobs into the ready queue. If there are any buried jobs, it will only kick buried jobs. Otherwise it will kick delayed jobs.

    Parameters

    • bound: number

      integer upper bound on the number of jobs to kick. The server will kick no more than jobs.

    Returns Promise<number>

kickJob

  • kickJob(jobId: number): Promise<boolean>
  • The kick-job command is a variant of kick that operates with a single job identified by its job id. If the given job id exists and is in a buried or delayed state, it will be moved to the ready queue of the the same tube where it currently belongs.

    Parameters

    • jobId: number

    Returns Promise<boolean>

listTubeUsed

  • listTubeUsed(): Promise<string>
  • The list-tube-used command returns the tube currently being used by the client.

    Returns Promise<string>

listTubes

  • listTubes(): Promise<string[]>
  • The list-tubes command returns a list of all existing tubes.

    Returns Promise<string[]>

listTubesWatched

  • listTubesWatched(): Promise<string[]>
  • The list-tubes-watched command returns a list tubes currently being watched by the client.

    Returns Promise<string[]>

pauseTube

  • pauseTube(tubeName: string, delay: number): Promise<boolean>
  • The pause-tube command can delay any new job being reserved for a given time.

    Parameters

    • tubeName: string

      tube to pause

    • delay: number

      integer number of seconds < 2**32 to wait before reserving any more jobs from the queue

    Returns Promise<boolean>

peek

peekBuried

peekDelayed

peekReady

stats

statsJob

  • The stats-job command gives statistical information about the specified job if it exists.

    Parameters

    • jobId: number

    Returns Promise<null | IBeanstalkJobStats>

statsTube

  • The stats-tube command gives statistical information about the specified tube if it exists.

    Parameters

    • tubeName: string

    Returns Promise<null | IBeanstalkTubeStats>

Producer Commands Methods

put

  • put(payload: any, ttr?: number, priority?: number, delay?: number): Promise<object>
  • This command for any process that wants to insert a job into the queue.

    Parameters

    • payload: any

      Payload of the job. Non string or integer values will be serialized with IClientCtorOptions.serializer. Byte size of payload should be less than less than server's max-job-size (default: 2**16) and client's IClientCtorOptions.maxPayloadSize.

    • ttr: number = ...

      Time to run -- is an integer number of seconds to allow a worker to run this job. This time is counted from the moment a worker reserves this job. If the worker does not delete, release, or bury the job within seconds, the job will time out and the server will release the job. The minimum ttr is 1. Maximum ttr is 2**32-1.

    • priority: number = ...

      Integer < 2**32. Jobs with smaller priority values will be scheduled before jobs with larger priorities. The most urgent priority is 0; the least urgent priority is 4,294,967,295.

    • delay: number = ...

      Integer number of seconds to wait before putting the job in the ready queue. The job will be in the "delayed" state during this time. Maximum delay is 2**32-1.

    Returns Promise<object>

use

  • use(tubeName: string): Promise<string>
  • Subsequent put commands will put jobs into the tube specified by this command. If no use command has been issued, jobs will be put into the tube named "default".

    Parameters

    • tubeName: string

    Returns Promise<string>

Worker Commands Methods

bury

  • bury(jobId: number, priority?: number): Promise<boolean>
  • The bury command puts a job into the "buried" state. Buried jobs are put into a FIFO linked list and will not be touched by the server again until a client kicks them with the Client.kick command

    Parameters

    • jobId: number

      job id to bury.

    • priority: number = ...

      a new priority to assign to the job.

    Returns Promise<boolean>

delete

  • delete(jobId: number): Promise<boolean>
  • The delete command removes a job from the server entirely. It is normally used by the client when the job has successfully run to completion. A client can delete jobs that it has reserved, ready jobs, delayed jobs, and jobs that are buried.

    Parameters

    • jobId: number

    Returns Promise<boolean>

ignore

  • ignore(tubeName: string): Promise<boolean>
  • Removes the named tube from the watch list for the current connection.

    False returned in case of attempt to ignore last tube watched (NOT_IGNORED returned from server).

    Parameters

    • tubeName: string

    Returns Promise<boolean>

release

  • release(jobId: number, priority?: number, delay?: number): Promise<null | ready | delayed | buried>
  • The release command puts a reserved job back into the ready queue (and marks its state as "ready") to be run by any client. It is normally used when the job fails because of a transitory error.

    Parameters

    • jobId: number

      job id to release.

    • priority: number = ...

      a new priority to assign to the job.

    • delay: number = ...

      integer number of seconds to wait before putting the job in the ready queue. The job will be in the "delayed" state during this time.

    Returns Promise<null | ready | delayed | buried>

reserve

  • This will return a newly-reserved job. If no job is available to be reserved, beanstalkd will wait to send a response until one becomes available. Once a job is reserved for the client, the client has limited time to run (TTR) the job before the job times out. When the job times out, the server will put the job back into the ready queue. Both the TTR and the actual time left can be found in response to the Client.statsJob command.

    If more than one job is ready, beanstalkd will choose the one with the smallest priority value. Within each priority, it will choose the one that was received first.

    During the TTR of a reserved job, the last second is kept by the server as a safety margin, during which the client will not be made to wait for another job. If the client issues a reserve command during the safety margin, or if the safety margin arrives while the client is waiting on a reserve command, the server will respond with: DEADLINE_SOON

    This gives the client a chance to delete or release its reserved job before the server automatically releases it.

    Returns Promise<null | IClientRawReservedJob>

reserveJob

  • A job can be reserved by its id. Once a job is reserved for the client, the client has limited time to run (TTR) the job before the job times out. When the job times out, the server will put the job back into the ready queue.

    Parameters

    • jobId: number

    Returns Promise<null | IClientRawReservedJob>

reserveWithTimeout

  • Same as Client.reserve but with limited amount of time to wait for the job.

    A timeout value of 0 will cause the server to immediately return either a response or TIMED_OUT. A positive value of timeout will limit the amount of time the client will block on the reserve request until a job becomes available.

    Parameters

    • timeout: number

    Returns Promise<null | IClientRawReservedJob>

touch

  • touch(jobId: number): Promise<boolean>
  • The "touch" command allows a worker to request more time to work on a job. This is useful for jobs that potentially take a long time, but you still want the benefits of a TTR pulling a job away from an unresponsive worker. A worker may periodically tell the server that it's still alive and processing a job (e.g. it may do this on DEADLINE_SOON). The command postpones the auto release of a reserved job until TTR seconds from when the command is issued

    Parameters

    • jobId: number

    Returns Promise<boolean>

watch

  • watch(tubeName: string): Promise<number>
  • The "watch" command adds the named tube to the watch list for the current connection. A reserve command will take a job from any of the tubes in the watch list. For each new connection, the watch list initially consists of one tube, named "default".

    Parameters

    • tubeName: string

    Returns Promise<number>

Generated using TypeDoc