Last active
December 16, 2015 10:58
-
-
Save mschulkind/5423453 to your computer and use it in GitHub Desktop.
Workflow DSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StateFlow | |
module Entity | |
def included(base) | |
base.field :state type: :symbol | |
end | |
end | |
def run_forever | |
every(10.seconds) do | |
# Find every entity that we know how to transition, queue the appropriate | |
# jobs. | |
end | |
# This should probably be implemented with something like: | |
# https://github.com/bvandenbos/resque-scheduler | |
end | |
end | |
class SeatGeekImportJob | |
@queue = :main | |
def self.perform(class_name, skip, limit) | |
# 1. Iterates over the entities, running find_or_create() for each. | |
# 2. Save the JSON into source_data of the entity, and set state to :unparsed. | |
# 3. Delete all the import tasks (applying skip/limit of course). | |
end | |
end | |
class SeatGeekImportTask | |
include Mongoid::Document | |
include Resque::Plugin::StateFlow::Entity | |
field :type # :event, :venue, or :performer | |
field :skip | |
field :limit | |
def self.start_import | |
# Figure out how many of each entity exists, queue up the relevant tasks (SeatGeekImportTask). | |
end | |
end | |
class SeatGeekVenue | |
include Resque::Plugin::StateFlow::Entity | |
end | |
class SeatGeekEvent | |
include Resque::Plugin::StateFlow::Entity | |
end | |
class SeatGeekFlow < StateFlow | |
transition(SeatGeekImportTask, :unfetched) do | |
job SeatGeekImportTask | |
end | |
transition(SeatGeekEvent, :unparsed) do | |
job ReparseJob | |
requires(:venue, only: :indexed) | |
end | |
transition(SeatGeekVenue, :unparsed) do | |
job ReparseJob | |
requires(SeatGeekImportTask, none: {state: :unfetched, type: :venue}) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment