Skip to content

Instantly share code, notes, and snippets.

@bcg
Created January 17, 2012 20:44
Show Gist options
  • Save bcg/1628768 to your computer and use it in GitHub Desktop.
Save bcg/1628768 to your computer and use it in GitHub Desktop.
State System
An app, "counter" is registered in the DB:
counter.starts = hourly
counter.depends = {"adx": hourly, "retarget": hourly}
counter.timeout = 6000 (seconds)
counter.host = tr-oddjob-dal-01
Also app, "bigcounter":
# bcounter.starts = weekly (might be unnecessary)
bcounter.depends = {"adx": weekly, "retarget": weekly}
bcounter.timeout = 600000 (seconds)
bcounter.host = tr-oddjob-dal-01
Two other apps already existed:
adxcheck.starts = hourly
adxcheck.host = tr-oddjob-dal-01
retgtcheck.starts = hourly
retgtcheck.hosts = tr-oddjob-dal-01
A State manager listens on all of the ZK paths under /prod
A Job Manager (on each box) listens on ZK path:
/prod/jobs/$host/
When 1200 hits the State manager fires off its hourly jobs. Two of the hourly jobs it fires off are adxcheck and retgtcheck:
/prod/jobs/tr-oddjob-dal-01/2011-01-02-1300-adxcheck/conf = { doc }
/prod/jobs/tr-oddjob-dal-01/2011-01-02-1300-rtgtcheck/conf = { doc }
The JobManager listening on this path, gets the new job notifications:
/prod/jobs/tr-oddjob-dal-01/2011-01-02-1300-adxcheck/state = pending
/prod/jobs/tr-oddjob-dal-01/2011-01-02-1300-rtgtcheck/state = pending
Once the jobs are complete the JobManager removes the jobs:
DELETE /prod/jobs/tr-oddjob-dal-01/2011-01-02-1300-adxcheck
DELETE /prod/jobs/tr-oddjob-dal-01/2011-01-02-1300-rtgtcheck
The State manager sees this updates and logs these jobs as complete. The State manager then checks against its
internal DB what jobs depend on the adxcheck and rtgtcheck. It finds "counter" depends on them hourly. So it creates the following job:
/prod/jobs/tr-oddjob-dal-01/2011-01-02-1300-counter/conf = { :adx => {}, rtgt: => { } }
... After a while the following jobs are completed:
DELETE /prod/jobs/tr-oddjob-dal-01/2011-01-02-2300-adxcheck
DELETE /prod/jobs/tr-oddjob-dal-01/2011-01-02-2300-rtgtcheck
This signals another day is complete and State runs through its DB to see if there are any weekly, monthly or yearly jobs that need to be run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment