Created
August 15, 2017 05:55
-
-
Save farukcankaya/b5aadb248f061929d0129cc5b9c6b889 to your computer and use it in GitHub Desktop.
Rule Builder
This file contains hidden or 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
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