Facebook Open Academy/Cron

A common requirement in infrastructure maintenance is the ability to execute tasks at scheduled times and intervals. On Unix systems (and, by extension, Linux) this is traditionally handled by a cron daemon. Traditional crons, however, run on a single server and are therefore unscalable and create single points of failure. While there are a few open source alternatives to cron that provide for distributed scheduling, they either depend on a specific "cloud" management system or on other complex external dependencies; or are not generally compatible with cron.

Requirements
The Wikimedia Labs has a need for a scheduler that:


 * Is configurable by traditional crontabs;
 * Can run on more than one server, distributing execution between them; and
 * Guarantees that scheduled events execute as long as at least one server is operational.

The ideal distributed cron replacement would have as few external dependencies as possible.

Research
Some interesting avenues of investigations have already been mentioned in the related Bugzilla (which see), as well as possible alternatives and counterarguments.

What are the current solutions that exist and what lessons can be learned from them?
 * Chronos
 * Supports dependencies between jobs
 * Will retry failed jobs
 * One of multiple nodes is elected a master
 * Has many dependencies including Apache Mesos and Zookeeper
 * Cronie
 * If I understand the man page correctly:
 * It only allows jobs to be executed on one chosen server at a time
 * Must manually switch the chosen server if it goes down
 * Requires a network-mounted share for the directory containing the shared crontabs
 * (FYI, that requirement is met for Lab's particular use case, but would normally indeed be considered onerous) &mdash; Coren (talk)/(enwp) 06:22, 4 February 2014 (UTC)


 * Jenkins
 * Meant for continuous integration not job scheduling
 * Only allows one master (single point of failure)
 * Gearman
 * Framework for distributing tasks
 * Has fault tolerance and job retries
 * Would still require a scheduler and worker application for the APIs to be written
 * Seems to be better suited to executing jobs at arbitrary times rather than being scheduled

Language to use
Set to Python by fiat for expediency
 * Widely distributed, well known by a large development base
 * High availability of libraries
 * Many (most) Linux distributions default to it for system scripts
 * Striving to work properly for Python 2.7 and Python 3+

Coding style
We have chosen to use the PEP 8 code style. Be sure to follow this style guide as closely as possible and the use of a style checker (ex. pep8) is encouraged (note that it doesn't catch all issues).

http://legacy.python.org/dev/peps/pep-0008/

What is the difference between a job and a schedule?
A job represents an entry in a crontab (ex: */5 * * * * echo "megacron"). A schedule is a specific instance of that job. In the previous example, a schedule would be created every five minutes for the job.

Should servers that run jobs be decoupled from servers that handle scheduling?
No, every server can potentially become a scheduler. This makes it easier for the users of our project because it abstracts the distinction between a worker and scheduler away from them.

How are the schedules and jobs stored and distributed between servers?
We are depending on a database being available and accessible to every server. The user will be able to choose from a few types of supported databases.

How is the worker that runs the schedule chosen and how is that information synchronized?
The server that has been running the longest will become the scheduler. A server will know that it has been running the longest if it has the oldest Id in the database. This approach is by far the simplest to implement and it seems to be working fine (so far).

How late can a job run?
If a run of a job is missed, it will be run at the next possible opportunity. If multiple runs are missed, only one will be run.

How bad is it if a job runs multiple times?
This should never happen.

What libraries should we usewe use to solve subproblems?

 * croniter for parsing crontab intervals
 * setuptools for packaging the project

How do we tell if a worker goes down?
A worker will periodically "check in" by updating it's heartbeat timestamp in the database. If the timestamp becomes older than a predetermined value, the worker is then considered to be down.

How does the scheduler distribute schedules?
<!DOCTYPE html>



 function envFlush(a){function b(c){for(var d in a)c[d]=a[d];}if(window.requireLazy){window.requireLazy(['Env'],b);}else{Env=window.Env||{};b(Env);}} envFlush({"ajaxpipe_token":"AXgu40OHOMtaNUKo","lhsh":"EAQEWYjaA","khsh":"0`sj`e`rm`s-0fdu^gshdoer-0gc^eurf-3gc^eurf;1;enbtldou;fduDmdldourCxO`ld-2YLMIuuqSdptdru;qsnunuxqd;rdoe"}); CavalryLogger=false;   Facebook   













<link type="text/css" rel="stylesheet" href="https://fbstatic-a.akamaihd.net/rsrc.php/v2/y9/r/QJnLE4Ci0TN.css" />

<link type="text/css" rel="stylesheet" href="https://fbstatic-a.akamaihd.net/rsrc.php/v2/ye/r/G9kD3xNwOoW.css" />

<script src="https://fbstatic-a.akamaihd.net/rsrc.php/v2/yL/r/HEJnsJ3UhmU.js" crossorigin="anonymous">

(require("ServerJSDefine")).handleDefines([["URLFragmentPreludeConfig",[],{"incorporateQuicklingFragment":true,"hashtagRedirect":true},137],["BootloaderConfig",[],{},329],["CurrentUserInitialData",[],{"USER_ID":"0","ACCOUNT_ID":"0"},270],["SiteData",[],{"revision":1422324,"tier":"","push_phase":"V3","pkg_cohort":"EXP1:DEFAULT","vip":"31.13.79.128"},317],["CurrentCommunityInitialData",[],{},490],["DTSGInitialData",[],{},258],["ISB",[],{},330],["LSD",[],{"token":"AVqGxDzM"},323],["BanzaiConfig",[],{"EXPIRY":86400000,"MAX_SIZE":10000,"MAX_WAIT":150000,"RESTORE_WAIT":150000,"blacklist":["time_spent"],"gks":{"adapterhooks":true,"boosted_pagelikes":true,"boosted_website":true,"boosted_posts":true,"jslogger":true,"miny_compression":true,"pages_client_logging":true,"time_spent_bit_array":true,"time_spent_debug":true,"useraction":true,"videos":true,"visibility_tracking":true,"vitals":true}} ,7],["AsyncRequestConfig",[],{"retryOnNetworkError":"1"},328],["FbtLogger",[],{"logger":null},288],["FbtQTOverrides",[],{"overrides":{"8b0c31a270a324f26d2417a358106611":"Replacement QT String!" }} ,551],["EagleEyeConfig",[],{"seed":"0u37"},294],["TrackingConfig",[],{"domain":"https:\/\/pixel.facebook.com"},325],["ErrorSignalConfig",[],{"uri":"https:\/\/error.facebook.com\/common\/scribe_endpoint.php"},319],["InitialServerTime",[],{"serverTime":1411341342000},204],["UFIConstants",[],{"UFIActionType":{"COMMENT_LIKE":"fa-type:comment-like","COMMENT_SET_SPAM":"fa-type:mark-spam","DELETE_COMMENT":"fa-type:delete-comment","DISABLE_COMMENTS":"fa-type:disable-comments","LIVE_DELETE_COMMENT":"fa-type:live-delete-comment","LIKE_ACTION":"fa-type:like","SUBSCRIBE_ACTION":"fa-type:subscribe","REMOVE_PREVIEW":"fa-type:remove-preview","MARK_COMMENT_SPAM":"fa-type:mark-spam","CONFIRM_COMMENT_REMOVAL":"fa-type:confirm-remove","TRANSLATE_COMMENT":"fa-type:translate-comment","COMMENT_LIKECOUNT_UPDATE":"fa-type:comment-likecount-update","ADD_COMMENT_ACTION":"fa-type:add-comment"},"UFICommentOrderingMode":{"CHRONOLOGICAL":"chronological","RANKED_THREADED":"ranked_threaded","TOPLEVEL":"toplevel","RECENT_ACTIVITY":"recent_activity","FEATURED":"featured","UNSUPPORTED":"unsupported"},"UFIFeedbackSourceType":{"PROFILE":0,"NEWS_FEED":1,"OBJECT":2,"MOBILE":3,"EMAIL":4,"PROFILE_APPROVAL":10,"TICKER":12,"NONE":13,"INTERN":14,"ADS":15,"EVENT_GOING_FLYOUT":16,"PHOTOS_SNOWLIFT":17,"NOTIFICATION_FLYOUT":18,"LOCAL_FEED":19},"UFIPayloadSourceType":{"UNKNOWN":0,"INITIAL_SERVER":1,"LIVE_SEND":2,"USER_ACTION":3,"ENDPOINT_LIKE":10,"ENDPOINT_COMMENT_LIKE":11,"ENDPOINT_ADD_COMMENT":12,"ENDPOINT_EDIT_COMMENT":13,"ENDPOINT_DELETE_COMMENT":14,"ENDPOINT_COMMENT_SPAM":16,"ENDPOINT_REMOVE_PREVIEW":17,"ENDPOINT_ID_COMMENT_FETCH":18,"ENDPOINT_COMMENT_FETCH":19,"ENDPOINT_TRANSLATE_COMMENT":20,"ENDPOINT_BAN":21,"ENDPOINT_SUBSCRIBE":22,"ENDPOINT_COMMENT_LIKECOUNT_UPDATE":23,"ENDPOINT_DISABLE_COMMENTS":24,"ENDPOINT_ACTOR_CHANGE":25},"UFIStatus":{"DELETED":"status:deleted","SPAM":"status:spam","SPAM_DISPLAY":"status:spam-display","LIVE_DELETED":"status:live-deleted","FAILED_ADD":"status:failed-add","FAILED_EDIT":"status:failed-edit","PENDING_EDIT":"status:pending-edit"},"attachmentTruncationLength":80,"commentTruncationLength":420,"commentTruncationMaxLines":3,"commentTruncationPercent":0.6,"commentURLTruncationLength":60,"defaultPageSize":50,"infiniteScrollRangeForQANDAPermalinks":1000,"minCommentsForOrderingModeSelector":2,"unavailableCommentKey":"unavailable_comment_key"},240],["ImmediateActiveSecondsConfig",[],{"sampling_rate":0},423]]);new (require("ServerJS")).handle({"require":"markJSEnabled"],["lowerDomain"],["URLFragmentPrelude"],["Primer"],["Bootloader"}); <body class="fbx UIPage_LoggedOut _2gsg webkit chrome win Locale_vi_VN" dir="ltr"><div class="_li"><div id="pagelet_bluebar"><div id="blueBarDOMInspector" class="_21mm"><div id="blueBarNAXAnchor" class="_4f7n _xxp"> <div class="loggedout_menubar_container"><div class="clearfix loggedout_menubar"><a class="lfloat _ohe" href="/" title="V&amp;#xe0;o Trang ch&amp;#x1ee7; Facebook"><i class="fb_logo img sp_W-hxJRCtHHc sx_7a884a"> Logo Facebook </i></a><div class="menu_login_container rfloat _ohf"><form id="login_form" action="https://www.facebook.com/login.php?login_attempt=1" method="post" onsubmit="return window.Event &amp;amp;&amp;amp; Event.__inlineSubmit &amp;amp;&amp;amp; Event.__inlineSubmit(this,event)"><input type="hidden" name="lsd" value="AVqGxDzM" autocomplete="off" /> <input type="hidden" autocomplete="off" name="timezone" value="" id="u_0_3" /><input type="hidden" name="lgnrnd" value="161542_Us8K" /><input type="hidden" id="lgnjs" name="lgnjs" value="n" /><input type="hidden" autocomplete="off" id="locale" name="locale" value="vi_VN" /><input type="hidden" autocomplete="off" id="cuid" name="cuid" value="AYj_EWgVnQavIaXeEPc4xgXiQFjObBxykUb5oqY02xoxADC75Tt8FoJ8gLRXE8Spza_6YjdQHmcUhUQXDsIvQT-m0vYfRYger24Fd_iP_5VT6KhC_AcQH64bPGNkTgcRf1fwSjUwUgvKhbQggbGCgY83aGSLsHTrIMHfvOz4yjxYFaWGh3iPeTY4Svo2j5mqABg" /><input type="hidden" autocomplete="off" name="next" value="https://www.facebook.com/recover/initiate" />       <div id="content" class="fb_content clearfix"><div class="UIFullPage_Container"><form rel="async" class="mbl pbl" method="post" action="/ajax/recover/initiate" onsubmit="return window.Event &amp;amp;&amp;amp; Event.__inlineSubmit &amp;amp;&amp;amp; Event.__inlineSubmit(this,event)" id="u_0_4"><input type="hidden" name="lsd" value="AVqGxDzM" autocomplete="off" /><input type="hidden" autocomplete="off" name="openid_provider_id" /><input type="hidden" autocomplete="off" name="openid_provider_name" /><div class="mtl mbm ptm uiInterstitial uiInterstitialLarge uiBoxWhite" id="initiate_interstitial">  <div class="rfloat _ohf"><h2 class="accessible_elem">Đặt lại mật khẩu của bạn   <h2 class="uiHeaderTitle" aria-hidden="true">Đặt lại mật khẩu của bạn   <div class="pam hidden_elem uiBoxRed" id="openid_error">   <td class="_k2">  <img class="img" src="https://www.facebook.com/profile/pic.php?cuid=AYhXgjc9BLecitEhbx1QGjL3rYxrVbgKY-E51Eh5jaAuTJ5rHge2-1TKEpgkrzDDJXeHGa49zjv_L96gKylbZaArLN6MydNL4_HPC6lbK1lwb2gFsz9s3i-2aH6ofAYfna8VvLbpfF7krw-0mRnf1lv53YjcQAXlJrtSn2Canij6UapMqpqfR7RIpZwfNnkeF4U&amp;amp;size=square&amp;amp;usedef=1" alt="" />  Nguyễn Hiếu Công   Người dùng Facebook   <a href="/notme.php?notme_cuid=AYj0uY7D7Y9lIDrCIji6eSEuc1XOASomrSjvYKNYe4fhfaJkk5vqVPDjsi1r4uZ9UqnVdafZsdr5lh47zXDC-FKalXmVkjSQVfgNgvpUP6XRZ0zHMiv70RHX9rcKR6Wz5sKKcgHcCdEa3UIW6asRY4CpHE1KhLgGnHcD2jlpSLLNh16NJm1ZaLLWnVuCd989Sd8&amp;amp;flow=recovery">Không phải là bạn?</a>       <div class="rfloat _ohf"><label class="uiButton uiButtonConfirm" for="u_0_1"><input value="Ti&amp;#x1ebf;p t&amp;#x1ee5;c" name="reset_action" type="submit" id="u_0_1" /> <a class="uiButton" href="/" role="button" name="reset_action"> Hủy </a> <a href="/recover/extended">Không còn truy cập được nữa?</a>    <div class="mbl fsm fwn fcg _52jv">Bạn có thể nhìn thấy tên và ảnh đại diện của bạn bởi vì bạn đang dùng trình duyệt mà bạn đã đăng nhập trước đó. <div id="pageFooter" data-referrer="page_footer"> <div role="contentinfo" aria-label="Li&amp;#xea;n k&amp;#x1ebf;t trang web Facebook"> Facebook © 2014 · <a rel="dialog" ajaxify="/settings/language/language/?uri=https%3A%2F%2Fwww.facebook.com%2Frecover%2Finitiate&amp;amp;source=TOP_LOCALES_DIALOG" title="S&amp;#x1eed; d&amp;#x1ee5;ng Facebook b&amp;#x1eb1;ng ng&amp;#xf4;n ng&amp;#x1eef; kh&amp;#xe1;c." href="#" role="button">Tiếng Việt</a>    <script type="text/javascript">/*<![CDATA[*/function si_cj(m){setTimeout(function{new Image.src="https:\/\/error.facebook.com\/common\/scribe_endpoint.php?c=si_clickjacking&t=9383"+"&m="+m;},5000);}if(top!=self && !false){try{if(parent!=top){throw 1;}var si_cj_d=["apps.facebook.com","apps.beta.facebook.com"];var href=top.location.href.toLowerCase;for(var i=0;i<si_cj_d.length;i++){if (href.indexOf(si_cj_d[i])>=0){throw 1;}} si_cj("3 https:\/\/www.facebook.com\/");}catch(e){si_cj("1 \thttps:\/\/www.facebook.com\/");window.document.write("\u003Cstyle>body * {display:none !important;}\u003C\/style>\u003Ca href=\"#\" onclick=\"top.location.href=window.location.href\" style=\"display:block !important;padding:10px\">\u003Ci class=\"img sp_hPXFJ_4hGEp sx_58f1c7\" style=\"display:block !important\">\u003C\/i>T\u1edbi trang Facebook.com\u003C\/a>");/*uJ8bhDrU*/ }}/*]]>*/

requireLazy(["Bootloader"], function(Bootloader) {Bootloader.setResourceMap({"r9N82":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yS\/r\/wqbGE2GaHTW.js"},"24Tj9":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yE\/r\/vZ7rP9GSyky.js"},"z\/SYi":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yt\/r\/lOEXDEVgqgM.js"},"9IG40":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yS\/r\/KuRocRo1cau.js"},"Ld2bx":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yz\/r\/sGhj-elKDNW.js"},"4vv8\/":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yf\/r\/JvK_C44obT2.js"},"NSaRF":{"type":"css","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yB\/r\/4uMv2G6wszR.css"},"+Mawf":{"type":"css","permanent":1,"crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yB\/r\/n5IjNy_c3SJ.css"},"f5MeU":{"type":"css","permanent":1,"crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/y-\/r\/89a-If9wRS8.css"},"9ZcuM":{"type":"css","nonblocking":1,"crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/y7\/r\/xQxnjRzZ9JO.css"},"tBBfw":{"type":"css","permanent":1,"crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yq\/r\/YaAPt0NFk-H.css"},"doDKK":{"type":"css","permanent":1,"crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yN\/r\/7kvQLbISEHO.css"},"kDfdR":{"type":"css","permanent":1,"crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/y9\/r\/QJnLE4Ci0TN.css"},"Lrr1I":{"type":"css","nonblocking":1,"crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/ye\/r\/G9kD3xNwOoW.css"},"WwgQq":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yQ\/r\/_Xu_VdhuGPH.js"},"GFGa3":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yy\/r\/3HbXN3ktlc0.js"},"nt+WU":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yj\/r\/eAKnEfGGJc4.js"},"g1Mer":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yU\/r\/kamt5PJt2Xr.js"},"C9Keq":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yA\/r\/qqN8URsaJf4.js"},"20549":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yk\/r\/stx9UbA-p-V.js"},"cAkXN":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yR\/r\/IQc0ALCNDHy.js"},"oE4Do":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yK\/r\/obqKRvJtthA.js"},"0TXZQ":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yU\/r\/kJ8XjV2sGU0.js"},"cNca2":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/y4\/r\/yuKCSDDP1tN.js"},"gh9zw":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yj\/r\/nFn9YWgyneh.js"},"NB3BJ":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yR\/r\/CUdCsxCJz95.js"},"h1E9t":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yI\/r\/AgQY3-tObW1.js"},"D9V15":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/ye\/r\/rke0VtIBO2Q.js"},"KlIez":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yx\/r\/h2Qah41zp6q.js"},"VDymv":{"type":"css","permanent":1,"crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yD\/r\/ChJNw8Q5r31.css"},"fV2gC":{"type":"css","permanent":1,"crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yo\/r\/Iaddt01ezX1.css"},"UPh8f":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yw\/r\/D3kpnWHxvYh.js"},"wxq+C":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/ye\/r\/iwqkFH9LdTE.js"},"Rs18G":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yI\/r\/iqqxHqHkZcL.js"},"6AU0l":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yz\/r\/rzV8WxVfDtl.js"},"AtxWD":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yG\/r\/J74KdXozsKP.js"},"zyFOp":{"type":"js","crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yT\/r\/Ri9nQJbah9T.js"}} );if (true) {Bootloader.enableBootload({"React":{"resources":["WwgQq","24Tj9"],"module":true},"ExceptionDialog":{"resources":["24Tj9","Ld2bx","WwgQq","+Mawf","f5MeU","GFGa3","nt+WU","g1Mer","C9Keq","r9N82","20549"],"module":true},"AsyncDOM":{"resources":["24Tj9","cAkXN"],"module":true},"ConfirmationDialog":{"resources":["24Tj9","+Mawf","oE4Do"],"module":true},"Dialog":{"resources":["24Tj9","WwgQq","+Mawf","f5MeU","0TXZQ"],"module":true},"ErrorSignal":{"resources":["24Tj9","cNca2"],"module":true},"Event":{"resources":["24Tj9"],"module":true},"AsyncDialog":{"resources":["24Tj9","Ld2bx","WwgQq","+Mawf","f5MeU"],"module":true},"AsyncRequest":{"resources":["24Tj9"],"module":true},"DialogX":{"resources":["24Tj9","Ld2bx","WwgQq","+Mawf","f5MeU"],"module":true},"XUIDialogTitle.react":{"resources":["WwgQq","24Tj9","+Mawf","GFGa3","f5MeU","nt+WU"],"module":true},"XUIDialogBody.react":{"resources":["WwgQq","24Tj9","f5MeU","GFGa3"],"module":true},"XUIDialogButton.react":{"resources":["24Tj9","WwgQq","GFGa3","+Mawf","f5MeU","g1Mer"],"module":true},"XUIDialogFooter.react":{"resources":["WwgQq","24Tj9","+Mawf","f5MeU","GFGa3","g1Mer"],"module":true},"XUIGrayText.react":{"resources":["WwgQq","24Tj9","f5MeU","r9N82"],"module":true},"PhotoSnowlift":{"resources":["gh9zw","24Tj9","WwgQq","+Mawf","f5MeU","0TXZQ","Ld2bx","NB3BJ","GFGa3","h1E9t","D9V15"],"module":true},"PhotoTagger":{"resources":["24Tj9","C9Keq","+Mawf","WwgQq","f5MeU","NB3BJ","gh9zw","Ld2bx","GFGa3","nt+WU","g1Mer"],"module":true},"Live":{"resources":["24Tj9","cAkXN"],"module":true},"PhotoTagApproval":{"resources":["24Tj9","gh9zw","C9Keq"],"module":true},"PhotoTags":{"resources":["24Tj9","gh9zw","+Mawf","C9Keq"],"module":true},"TagTokenizer":{"resources":["24Tj9","GFGa3","f5MeU","KlIez","nt+WU","+Mawf","r9N82"],"module":true},"css:fb-photos-snowlift-fullscreen-css":{"resources":["VDymv"]},"SnowliftPicCropper":{"resources":["24Tj9","WwgQq","+Mawf","f5MeU","0TXZQ","C9Keq","gh9zw","fV2gC","nt+WU","UPh8f","wxq+C"],"module":true},"PhotosButtonTooltips":{"resources":["24Tj9","+Mawf","WwgQq","f5MeU","Rs18G"],"module":true},"VideoRotate":{"resources":["24Tj9","WwgQq","+Mawf","f5MeU","0TXZQ","6AU0l"],"module":true},"AsyncResponse":{"resources":["24Tj9"],"module":true},"PhotoPermalinkCropper":{"resources":["24Tj9","WwgQq","+Mawf","f5MeU","0TXZQ","C9Keq","gh9zw","fV2gC","Ld2bx","NB3BJ","GFGa3","nt+WU","g1Mer","UPh8f"],"module":true},"PhotoInlineEditor":{"resources":["24Tj9","gh9zw","WwgQq","+Mawf","Ld2bx","C9Keq","f5MeU","NB3BJ","GFGa3","nt+WU","g1Mer","KlIez","r9N82","AtxWD"],"module":true},"Form":{"resources":["24Tj9","+Mawf"],"module":true},"SpotlightShareViewer":{"resources":["24Tj9","Ld2bx","zyFOp"],"module":true},"Toggler":{"resources":["24Tj9","+Mawf","WwgQq","f5MeU"],"module":true},"Tooltip":{"resources":["24Tj9","+Mawf","WwgQq","f5MeU"],"module":true},"DOM":{"resources":["24Tj9"],"module":true},"Input":{"resources":["24Tj9","+Mawf"],"module":true},"trackReferrer":{"resources":[],"module":true},"DimensionTracking":{"resources":["24Tj9","Ld2bx"],"module":true},"HighContrastMode":{"resources":["24Tj9","Ld2bx"],"module":true},"DetectBrokenProxyCache":{"resources":["24Tj9","Ld2bx"],"module":true }});}});

requireLazy(["InitialJSLoader"], function(InitialJSLoader) {InitialJSLoader.loadOnDOMContentReady(["r9N82","24Tj9","z\/SYi","9IG40","Ld2bx","4vv8\/"]);});

requireLazy(["Bootloader"], function(Bootloader) {Bootloader.configurePage(["NSaRF","+Mawf","f5MeU","9ZcuM","tBBfw","doDKK","kDfdR","Lrr1I"]);});

(require("ServerJSDefine")).handleDefines("TimeSpentConfig",[],{"0_delay":0,"0_timeout":8,"delay":200000,"timeout":64},142);require("InitialJSLoader").handleServerJS({"elements":"m_0_2","login_form",2],["m_0_3","loginbutton",2],["m_0_1","u_0_3",2],["m_0_4","login_form",2],["m_0_0","u_0_4",2,"require":"PixelRatio","startDetecting",[],[1.25,["PostLoadJS","loadAndRequire",[],["DimensionTracking"]],["PostLoadJS","loadAndCall",[],["HighContrastMode","init",[{"isHCM":false,"spacerImage":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/y4\/r\/-PAXP-deijE.gif"}]]],["PostLoadJS","loadAndCall",[],["DetectBrokenProxyCache","run",[0,"c_user"]]],["Artillery"],["ScriptPath","set",[],["WebRecoverInitiateController","01afab33","a76ec28a"]],["ClickRefLogger"],["userAction","setUATypeConfig",[],[{"ua:e":false}]],["ScriptPathState","setUserURISampleRate",[],[0.0002]],["userAction","setCustomSampleConfig",[],[{"ua:n":{"test":{"ua_id":{"test":true }}} ,"ua:i":{"snowlift":{"action":{"open":true,"close":true }} ,"snowflake":{"action":{"open":true,"close":true }} ,"canvas":{"action":{"mouseover":true,"mouseout":true }}} }]],["Chromedome","start",[],[{"wipe":1,"hardConsole":1,"warnings":[["\u0025cCareful. This might not do what you think.","font-size:40px; background-color:red; color:yellow; font-weight:bold; font-family:tahoma;"],["\u0025cThis is a browser feature intended for developers. If someone told you to copy-paste something here to enable a Facebook feature or \"hack\" someone's account,\u0025c it is probably a scam and will give them access to your Facebook account.","font-size:20px; font-family:tahoma","font-size:20px; font-family:tahoma; font-weight:bold"]],"block":"The developer console is temporarily disabled; see https:\/\/www.facebook.com\/selfxss for more information"}]],["UserActionHistory"],["ScriptPathLogger","startLogging",[],[]],["TimeSpentBitArrayLogger","init",[],[]],["TinyViewport"],["WebStorageMonster","schedule",[],[false]],["TimezoneAutoset","setInputValue",["m_0_1"],[{"__m":"m_0_1"},1411341342]],["LoginFormController","init",["m_0_2","m_0_3"],[{"__m":"m_0_2"},{"__m":"m_0_3"},null]],["PlaceholderListener"],["PlaceholderOnsubmitFormListener"],["FlipDirectionOnKeypress"],["ModuleErrorLogger","init",[],[]]]});

onloadRegister_DEPRECATED(function {try { $("email").focus; } catch (_ignore) { }} );

var bigPipe = new (require("BigPipe"))({"lid":0,"forceFinish":true});

bigPipe.onPageletArrive({"id":"first_response","phase":0,"jsmods":{},"is_last":true,"css":["NSaRF","+Mawf","f5MeU","9ZcuM","tBBfw","doDKK","kDfdR","Lrr1I","lNr75"],"resource_map":{"lNr75":{"type":"css","permanent":1,"nonblocking":1,"crossOrigin":1,"src":"https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/v2\/yv\/r\/Vk4nQy3HcNA.css"}} ,"js":["r9N82","24Tj9","z\/SYi","9IG40","Ld2bx","4vv8\/"]}) bigPipe.onPageletArrive({"id":"","phase":1,"jsmods":{},"is_last":true,"css":["NSaRF","+Mawf","f5MeU","9ZcuM","tBBfw","doDKK","kDfdR","Lrr1I","lNr75"],"js":["r9N82","24Tj9","z\/SYi","9IG40","Ld2bx","4vv8\/"],"the_end":true}) Whenever it creates a schedule, it will specify a time to run and a worker to run it. Workers are assigned in a round-robin fashion. Workers then fetch a list of jobs assigned to them, and run them at the appropriate time.

What user executes the schedules?
The UID of the user that created the job is stored. The schedules are then executed as that user.

How bad is it if a deleted job still gets ran?

 * If a server gets isolated and the crontab is updated, it'll run all the jobs on the old table in perpetuity for as long as it cannot connect to any of the other servers. GLM
 * If a job is deleted after its start time, it should run (unless deleted refers to "aborted"). Such cases would need to be handled manually by an administrator. JT
 * In a common case of deleting a job from the crontab during the job's idle period, it should not run on non-isolated servers (this definition depends on the technique we use for server selection). Otherwise, there is essentially no delete functionality provided. FC

API

 * 1) Functions
 * 2) * get_jobs [Obtains a list of jobs that correspond 1:1 to each entry in every user's crontab]
 * 3) ** returns [Jobs]
 * 4) * get_jobs_for_user(user_id) [Obtains a list of jobs that correspond 1:1 to each entry in a single specified user's crontab]
 * 5) **returns [Jobs]
 * 6) * set_jobs([Job], user_id) [Removes existing jobs for the specified user and puts the list of Jobs into the datastore]
 * 7) * set_job_time(Job) [Sets the last time run for the job to the current time]
 * 8) * get_schedules(Worker) [Obtains a list of schedules that are currently assigned to the worker]
 * 9) ** returns [Schedule]
 * 10) * add_schedules([Schedule]) [Puts a list of schedules into the datastore]
 * 11) * add_schedule(Schedule) [Puts a schedule into the datastore]
 * 12) * remove_schedule(Schedule) [Removes a schedule from the datastore]
 * 13) * get_heartbeat(Worker) [Obtains the value of the heartbeat timestamp associated with the worker]
 * 14) ** returns timestamp
 * 15) * update_heartbeat(Worker) [Updates the worker's timestamp to the current time]
 * 16) * get_next_worker [Returns the next available worker and moves it to the end of the queue]
 * 17) ** returns Worker
 * 18) * get_workers [Obtains a list of all workers]
 * 19) ** returns [Worker]
 * 20) * create_worker [Adds a new worker to the datastore and returns it]
 * 21) ** returns Worker
 * 22) * destroy_worker(Worker) [Removes a worker from the datastore]
 * 23) * get_crontab(user_id) [Gets the crontab for the given user]
 * 24) ** returns crontab
 * 25) * set_crontab(crontab, user_id) [Adds a crontab as a string to the datastore for the given user]
 * 26) Objects
 * 27) * Job [A single parsed crontab row representing a single command to be run]
 * 28) ** String : interval [Ex: "* * * * *"]
 * 29) ** String : command [Ex: "foo.py"]
 * 30) ** String : user_id
 * 31) ** Datetime : last_time_run
 * 32) * Schedule [A single element extracted from a Job, in a format that a worker can run]
 * 33) ** Worker : worker
 * 34) ** Datetime : time_to_run
 * 35) ** Job : job
 * 36) * Worker [A machine which Scheduler is a specific instance of, capable of performing crontab tasks]
 * 37) ** Datetime : heartbeat [timestamp of last contact]

Where can the code be tested in an isolated environment?
With appropriate credentials, you can ssh into all of the three following servers:
 * megacron-one.wmflabs.org


 * megacron-two.wmflabs.org

You should have root access here using sudo. A NFS shared filesystem is mounted on each server at "/data/project/".
 * megacron-three.wmflabs.org

Packaging Instructions
To build a new Python Source Package:

python setup.py sdist python setup.py register python setup.py sdist upload

To update Python Source Package:

Down the road, after you’ve made updates to your distribution and wish to make a new release:

1.    Increment the version number in your setup.py file,

2.    Update your CHANGES.txt file,

3.    If necessary, update the “Contributors” and “Thanks also to” sections of your README.txt file.

4.    Run python setup.py sdist upload again.

To download via pip:

sudo pip install megacron sudo pip install megacron --upgrade

To build a Debian package from an existing Python Package:

py2dsc Megacron-0.1.tar.gz

sudo debuild -S -rfakeroot -kDE117DE3

sudo debsign megacron_0.1-1_amd64.changes -kDE117DE3

sudo dput ppa:johntanner/megacron megacron_0.1-1_amd64.changes

Add to your /etc/apt/sources.list:

deb http://ppa.launchpad.net/johntanner/megacron/ubuntu precise main

deb-src http://ppa.launchpad.net/johntanner/megacron/ubuntu precise main

To download via apt-get:

sudo apt-get update

sudo apt-get install python-megacron