Class: Pgbus::RecurringTask
- Defined in:
- app/models/pgbus/recurring_task.rb
Class Method Summary collapse
-
.sync_from_config!(tasks_hash) ⇒ Object
Sync static tasks from configuration.
Class Method Details
.sync_from_config!(tasks_hash) ⇒ Object
Sync static tasks from configuration. Creates new tasks, updates existing ones, removes stale ones.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/pgbus/recurring_task.rb', line 16 def self.sync_from_config!(tasks_hash) transaction do task_keys = tasks_hash.keys # Upsert all configured tasks tasks_hash.each do |key, | = .transform_keys(&:to_s) record = find_or_initialize_by(key: key) record.assign_attributes( class_name: ["class"], command: ["command"], schedule: ["schedule"], queue_name: ["queue"], arguments: ["args"], priority: .fetch("priority", 0).to_i, description: ["description"], static: true ) record.save! end # Remove static tasks no longer in config static_tasks.where.not(key: task_keys).delete_all end end |