15 Matching Annotations
  1. Jun 2022
  2. Mar 2022
  3. Oct 2021
    1. QueueStore
    2. export interface QueueInterface {   count(): number;   dequeue?(): any;   enqueue(...args: any): void;   flush(): any[];   reset(): void;   setFifo(fifo: boolean): void;   setLifo(lifo: boolean): void;   truncate(length: number): void; } export class queue {   protected elements: any[];   protected fifo = true;   constructor(…args: any) {     this.elements = […args];   }   count() {     return this.elements.length;   }   dequeue?(): any {     if (this.fifo) {       return this.elements.shift();     }     return this.elements.pop();   }   enqueue(…args: any) {     return this.elements.push(…args);   }   // Like dequeue but will flush all queued elements   flush(): any[] {     let elms = [];     while (this.count()) {       elms.push(this.dequeue());     }     return elms;   }   setFifo(fifo = true) {     this.fifo = fifo;   }   setLifo(lifo = true) {     this.fifo = !lifo;   }   reset(): void {     this.truncate(0);   }   truncate(length: number) {     if (Number.isInteger(length) && length > -1) {       this.elements.length = length;     }   } } export default queue;
  4. Oct 2020
  5. Apr 2020
    1. def handle_exception(self, job, *exc_info):

      To unit test an exception handler:

      worker = Worker(..., exception_handler=[handle_exception])
      try:
          raise Exception()
      except Exception:
          exc_info = sys.exc_info()
      
      worker.handle_exception(job, *exc_info)
      
    1. failure_ttl

      How long to keep a failed job.

    2. result_ttl=600

      How long to keep a successful job.

    3. job.meta['handled_by'] = socket.gethostname() job.save_meta()

      You can add metadata on the job like keeping track of the number of times a job has been retried for example.

    1. w = Worker([q], exception_handlers=[foo_handler, bar_handler])

      Exception handlers are attached to the worker.

    2. def my_handler(job, exc_type, exc_value, traceback): # do custom things here

      Write an exception handler that requeues a failed job.

  6. Nov 2018