Skip to content

Instantly share code, notes, and snippets.

@mschulkind
Last active December 16, 2015 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mschulkind/5423453 to your computer and use it in GitHub Desktop.
Save mschulkind/5423453 to your computer and use it in GitHub Desktop.
Workflow DSL
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