Commit 97205438 authored by Micaël Bergeron's avatar Micaël Bergeron

added the DEAD state for job that should not retry

parent 900eb7a9
......@@ -31,10 +31,11 @@ class ImpossibleTransitionError(Error):
class State(Enum):
SUCCESS = (2, ())
FAIL = (3, ())
RUNNING = (1, ('SUCCESS', 'FAIL'))
IDLE = (0, ('RUNNING', 'FAIL'))
RUNNING = (1, ('SUCCESS', 'FAIL'))
SUCCESS = (2, ())
FAIL = (3, ('RUNNING',))
DEAD = (4, ())
def transitions(self):
return self.value[1]
......@@ -60,6 +61,9 @@ class Job(SystemModel):
def transit(self, state: State) -> (State, State):
transition = (self.state, state)
if self.state is state:
return transition
if state.name not in self.state.transitions():
raise ImpossibleTransitionError(transition)
......
import sys
import psycopg2
import logging
import re
from functools import reduce
from elt.db import DB
......@@ -18,6 +19,45 @@ def compose(*fs):
"""
return reduce(lambda f, g: lambda x: f(g(x)), fs, lambda x: x)
# from http://www.dolphmathews.com/2012/09/slugify-string-in-python.html
def slugify(s):
"""
Simplifies ugly strings into something URL-friendly.
>>> print slugify("[Some] _ Article's Title--")
some-articles-title
"""
# "[Some] _ Article's Title--"
# "[some] _ article's title--"
s = s.lower()
# "[some] _ article's_title--"
# "[some]___article's_title__"
for c in [' ', '-', '.', '/']:
s = s.replace(c, '_')
# "[some]___article's_title__"
# "some___articles_title__"
s = re.sub('\W', '', s)
# "some___articles_title__"
# "some articles title "
s = s.replace('_', ' ')
# "some articles title "
# "some articles title "
s = re.sub('\s+', ' ', s)
# "some articles title "
# "some articles title"
s = s.strip()
# "some articles title"
# "some-articles-title"
s = s.replace(' ', '-')
return s
def setup_db(args=None):
if args is None:
DB.setup()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment