Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bull
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 175
    • Issues 175
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 9
    • Merge requests 9
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OptimalBits
  • bull
  • Merge requests
  • !982

Add events 'completed' and 'failed' to a Job

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/scinos/master into master Jun 20, 2018
  • Overview 2
  • Commits 2
  • Pipelines 0
  • Changes 4

Created by: scinos

This PR makes a Job an EventEmitter, so it can trigger events too. I implemented two events, 'completed' and 'failed'. These events are triggered after the queue's events, because there is little value in doing it before: in that case, you could as well run the code handling the event in the Job processor.

Our use case:

We have a WebServer that creates jobs, and a Worker that picks those jobs, generates the output, and then has to do some expensive cleanup before accepting the next job. We can control it with pause/resume, but it is hard to schedule the cleanup and not interfere with the "main loop". For example, if we use setTimeout inside the processor to schedule the clean up, it might end up running before the job is marked as done in Redis, delaying the whole process.

Having a event we can listen to that signals "the job has been processed and handled by the queue" is a great solution for us.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/scinos/master