Sha256: f5862d064b8ca9f93a866083bbc8f1da27d81a81ffbe7a66c98dd21143c3dcda

Contents?: true

Size: 996 Bytes

Versions: 2

Compression:

Stored size: 996 Bytes

Contents

module Legion::Extensions::Tasker
  module Runners
    module Updater
      include Legion::Extensions::Helpers::Lex

      def update_status(task_id:, **opts)
        task = Legion::Data::Model::Task[task_id]
        if task.nil? || task.values.nil?
          return { success: false, changed: false, task_id: task_id, message: 'task nil' }
        end

        log.unknown task.class

        update_hash = {}
        %i[status function_args payload results].each do |column|
          next unless opts.key? column

          update_hash[column] = if opts[column].is_a? String
                                  opts[column]
                                else
                                  to_json opts[column]
                                end
        end
        { success: true, changed: false, task_id: task_id } if update_hash.count.zero?
        task.update(update_hash)

        { success: true, changed: true, task_id: task_id, updates: update_hash }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lex-tasker-0.2.1 lib/legion/extensions/tasker/runners/updater.rb
lex-tasker-0.2.0 lib/legion/extensions/tasker/runners/updater.rb