Assembly Line v0.5.0 AssemblyLine.JobQueue.Server

Provides a common interface for interacting with Job Queues.

The Server both manages the Job Queues directly and provides an interface for interacting with the underlying Job Queues.

Starting a Queue

To start a new job queue you simply need to ask the AssemblyLine.JobQueue.Supervisor to do so:

alias AssemblyLine.JobQueue.Supervisor

Supervisor.start_queue "doc queue", []

While it is always possible to interact directly with the Server it is recommended that you use AssemblyLine.JobQueue.Handler to process the job queue for you.

Summary

Functions

Removes the current job set from the work list and adds the entries to the finished set

Adds a specified job to the finished set

Stops the JobQueue with name

Fetches the set of completed jobs

Fetches the next job set for the named queue

Starts a new job queue with the given name and task load

Functions

complete_current_set(queue)

Specs

complete_current_set(String.t) :: atom

Removes the current job set from the work list and adds the entries to the finished set

Returns :ok

complete_current_set takes the current state does two things:

  • pops the first job group off the list
  • adds each job in that group to the finished set

This function should be called when all the jobs in a group have completed successfully.

finish_job(job, queue)

Specs

finish_job(AssemblyLine.Job.t, String.t) :: atom

Adds a specified job to the finished set

Returns an updated Server struct

This function is intended to be used when adding tasks to the finished set outside the scope of the complete_current_set/1 function.

finished(name)

Specs

finished(String.t) :: atom

Stops the JobQueue with name

It returns :ok if the JobQueue terminates normally otherwise it will exit.

get_completed(queue)

Specs

get_completed(String.t) :: MapSet.t

Fetches the set of completed jobs

Returns a MapSet of AssemblyLine.Job structs

get_completed will return all the jobs that have been marked as complete. This is useful when a finished job could have a negative impact if repeated. Tracking completed jobs can help prevent re-executing a sensitive job that is part of an incomplete job set.

next_set(queue)

Specs

next_set(String.t) :: [AssemblyLine.Job.t]

Fetches the next job set for the named queue

Returns a list of AssemblyLine.Job structs

next_for will return the first element currently in the work list, note that it does not modify the list at all. You must explicitly indicate that a job set is finished via complete_current_set/1 before it will be removed from the list.

start_link(name, work)

Specs

start_link(String.t, [AssemblyLine.Job.t]) :: {atom, pid}

Starts a new job queue with the given name and task load

Returns {:ok, pid}

A new job queue should be initialized will all required work upfront. The work should be in the form of a list of AssemblyLine.Job structs. Each nesting in the list can be run in parallel but must finish before the next entry can start.

Examples

Lets say we have three jobs two of those jobs are independent but are required before the third can be run. We would need the following work list:

    [[%AssemblyLine.Job{}, %AssemblyLine.Job{}], %AssemblyLine.Job{}]