Giter VIP home page Giter VIP logo

jobcenter's Introduction

Job center:- A simple job management service

Build and Test

A terrible solution to the Chapter 22 exercise in Joe's Programming Erlang (2nd edition). Read the book if you haven't already. It's good!

Getting Started

Follow the Elixir Installation Guide to install Elixir.

Clone the repository, install dependencies, run tests, ....

$ git clone https://github.com/lgmfred/jobcenter.git
$ cd jobcenter
$ mix deps.get
$ mix test
$ mix docs

Start the IEx shell and the server. Confirm there are no jobs done, in queue, or in progress.

iex(1)> {:ok, pid} = JobCenter.start_link()
{:ok, #PID<0.235.0>}
iex(2)> JobCenter.get_queue_list(pid)
[]
iex(3)> JobCenter.get_progress_list(pid)
[]
iex(4)> JobCenter.get_done_list(pid)    
[]

Lets add three jobs to queue and check the three lists.

iex(5)> JobCenter.add_job(pid, fn -> :one end)
1
iex(6)> JobCenter.add_job(pid, fn -> :two end)
2
iex(7)> JobCenter.add_job(pid, fn -> :three end) 
3
iex(8)> JobCenter.get_queue_list(pid)           
[
  {1, #Function<45.65746770/0 in :erl_eval.expr/5>},
  {2, #Function<45.65746770/0 in :erl_eval.expr/5>},
  {3, #Function<45.65746770/0 in :erl_eval.expr/5>}
]
iex(9)> JobCenter.get_progress_list(pid)        
[]
iex(10)> JobCenter.get_done_list(pid)            
[]

How about we request for 2 jobs, and tell the server we're done with one.

iex(11)> {id1, fun1} = JobCenter.work_wanted(pid)
{1, #Function<45.65746770/0 in :erl_eval.expr/5>}
iex(12)> {id2, fun2} = JobCenter.work_wanted(pid)
{2, #Function<45.65746770/0 in :erl_eval.expr/5>}
iex(13)> JobCenter.get_progress_list(pid)        
[
  {2, #Function<45.65746770/0 in :erl_eval.expr/5>},
  {1, #Function<45.65746770/0 in :erl_eval.expr/5>}
]
iex(14)> JobCenter.job_done(pid, id1) 
:ok

Current state of the server.

iex(15)> JobCenter.get_done_list(pid)            
[{1, #Function<45.65746770/0 in :erl_eval.expr/5>}]
iex(16)> JobCenter.get_progress_list(pid)        
[{2, #Function<45.65746770/0 in :erl_eval.expr/5>}]
iex(17)> JobCenter.get_queue_list(pid)
{3, #Function<45.65746770/0 in :erl_eval.expr/5>}

Concepts learned

  • Processes
  • GenServers (and how to test them)
  • Testing and TDD
  • Documentation and Static Analysis (Doctests, Typespecs, ExDoc and Credo)

jobcenter's People

Contributors

lgmfred avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.