Documentation ¶
Overview ¶
Mediation layer between the server and database queries.
Logic that's not related to validating request input/turning errors into HTTP responses should go here.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultTimeout = 5 * time.Minute
DefaultTimeout is the default amount of time a JobProcessor should wait for a job to complete, once it's been sent to the downstream server.
UnavailableSleepFactor determines how long the application should sleep between 503 Service Unavailable downstream responses.
Functions ¶
func ArchiveStuckJobs ¶
ArchiveStuckJobs marks as failed any queued jobs with an updated_at timestamp older than the olderThan value.
func HandleStatusCallback ¶
func HandleStatusCallback(id types.PrefixUUID, name string, status models.JobStatus, attempt uint8, retryable bool) error
HandleStatusCallback updates a queued job with the provided status and the attempts remaining. Likely the job will either be inserted into archived_jobs and removed from queued_jobs, or the job will have its attempts counter decremented in queued_jobs.
This can return an error if any of the following happens: the archived_job already exists, the queued job no longer exists by the time you attempt to delete it, the number of attempts for the queued job don't match up with the passed in value (slow)
Types ¶
type JobProcessor ¶
type JobProcessor struct { // A Client for making requests to the downstream server. Client *downstream.Client // Amount of time we should wait for the downstream server to hit the // callback before marking the job as failed. Timeout time.Duration // Multiplier used to determine how long to sleep between failed attempts // to acquire a job. The formula for sleeps is 10 * (Factor) ^ (Attempts) // ms. Set to 0 to not sleep between attempts. SleepFactor float64 }
JobProcessor is the default implementation of the Worker interface.
func NewJobProcessor ¶
func NewJobProcessor(downstreamUrl string, downstreamPassword string) *JobProcessor
NewJobProcessor creates a services.JobProcessor that makes requests to the downstream url.
By default the Client uses Basic Auth with "jobs" as the username, and the configured password as the password.
If the downstream server does not hit the callback, jobs sent to the downstream server are timed out and marked as failed after DefaultTimeout has elapsed.