Skip to content

Instantly share code, notes, and snippets.

@farukcankaya
Created August 15, 2017 05:55
Show Gist options
  • Save farukcankaya/b5aadb248f061929d0129cc5b9c6b889 to your computer and use it in GitHub Desktop.
Save farukcankaya/b5aadb248f061929d0129cc5b9c6b889 to your computer and use it in GitHub Desktop.
Rule Builder
rule = Rule.find_by_id(rule_id)
if rule
worker_ids = rule.workers_relation.pluck(:id)
rule.last_synched_at = Time.zone.now
rule.worker_ids = worker_ids
rule.workers_count = worker_ids.length
rule.save
# Re-Calculate later
self.class.set(wait: 1.hours).perform_later(rule_id)
end
end
def workers_relation
where, join_count = resolve(expression)
Worker.joins(:submissions)
.joins(join_dependency(join_count))
.where(submissions: { status: :accepted })
.where(where)
.group(:id)
.order(id: :asc)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment