add git job for queuing

This commit is contained in:
Donovan Daniels 2024-10-21 01:32:17 -05:00
parent 42ec01d2f5
commit e61efff10a
Signed by: Donovan_DMC
GPG Key ID: 907D29CBFD6157BA
9 changed files with 32 additions and 13 deletions

20
app/jobs/git_job.rb Normal file
View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
class GitJob < ApplicationJob
queue_as :git
good_job_control_concurrency_with(perform_limit: 1)
# used for locking
def perform(_identifier, *commands)
commands.each do |command|
system!(command)
end
end
private
def system!(*)
system(*, exception: true, chdir: base_path)
end
end

View File

@ -97,7 +97,7 @@ module DiscordInteractions
when 1 when 1
base = options.find { |o| o["name"] == sub[0] && o["type"] == DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND }.try(:[], "options") base = options.find { |o| o["name"] == sub[0] && o["type"] == DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND }.try(:[], "options")
when 2 when 2
base = options.find { |o| o["name"] == sub[0] && o["type"] == DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND_GROUP }.try(:[], "options").try(:find, &(->(o) { o["name"] == sub[1] && o["type"] == DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND })).try(:[], "options") base = options.find { |o| o["name"] == sub[0] && o["type"] == DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND_GROUP }.try(:[], "options").try(:find, &->(o) { o["name"] == sub[1] && o["type"] == DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND }).try(:[], "options")
else else
base = nil base = nil
end end

View File

@ -457,7 +457,7 @@ module DiscordInteractions
hash.each_with_object({}) do |(k, v), h| hash.each_with_object({}) do |(k, v), h|
if v.is_a?(Hash) if v.is_a?(Hash)
flatten_hash(v).map do |h_k, h_v| flatten_hash(v).map do |h_k, h_v|
h["#{k}.#{h_k}".to_sym] = h_v h[:"#{k}.#{h_k}"] = h_v
end end
else else
h[k] = v h[k] = v

View File

@ -39,7 +39,7 @@ class RateLimiter::InMemory < RateLimiter
private private
def consume(key, window, limit) def consume(key, window, limit)
(list[key] || { count: 0, expiry: nil }) => { count:, expiry: } list[key] || { count: 0, expiry: nil } => { count:, expiry: }
if expiry && expiry < Time.now.to_i if expiry && expiry < Time.now.to_i
list.delete(key) list.delete(key)

View File

@ -5,17 +5,13 @@ module StorageManager
def delete(path) def delete(path)
return unless exists?(path) return unless exists?(path)
super super
system!("git add #{base_path}#{path}") GitJob.perform_later("#{base_path}#{path}", "git add #{base_path}#{path}", "git commit -m \"Remove #{path[1..]}\"", "git push")
system!("git commit -m \"Remove #{path[1..]}\"")
system!("git push")
end end
def put(path, io) def put(path, io)
super super
if exists?(path) if exists?(path) # rubocop:disable Style/IfUnlessModifier
system!("git add #{base_path}#{path}") GitJob.perform_later("#{base_path}#{path}", "git add #{base_path}#{path}", "git commit -m \"Add #{path[1..]}\"", "git push")
system!("git commit -m \"Add #{path[1..]}\"")
system!("git push")
end end
end end

View File

@ -14,11 +14,11 @@ class ApplicationRecord < ActiveRecord::Base
options[:methods] ||= [] options[:methods] ||= []
options[:methods] += method_attributes options[:methods] += method_attributes
super(options) super
end end
def serializable_hash(*args) def serializable_hash(*)
hash = super(*args) hash = super
hash.transform_keys { |key| key.delete("?") } hash.transform_keys { |key| key.delete("?") }
end end

View File

@ -1,4 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Define an application-wide content security policy. # Define an application-wide content security policy.

View File

@ -1,4 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Define an application-wide HTTP permissions policy. For further # Define an application-wide HTTP permissions policy. For further

View File

@ -1,4 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
# This file should ensure the existence of records required to run the application in every environment (production, # This file should ensure the existence of records required to run the application in every environment (production,
# development, test). The code here should be idempotent so that it can be executed at any point in every environment. # development, test). The code here should be idempotent so that it can be executed at any point in every environment.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).