Class: Jobs::Onceoff
Direct Known Subclasses
CleanUpPostTimings, CleanUpSidekiqStatistic, CleanUpUserExportTopics, ClearWidthAndHeight, CorrectMissingDualstackUrls, CreateTagsSearchIndex, FixEncodedCategorySlugs, FixEncodedTopicSlugs, FixFeaturedLinkForTopics, FixInvalidGravatarUploads, FixInvalidUploadExtensions, FixOutOfSyncUserUploadedAvatar, FixPostSearchDataAfterDefaultLocaleRename, FixPostsRead, FixPrimaryEmailsForStagedUsers, FixRetroAnniversary, FixS3Etags, GrantEmoji, GrantFirstReplyByEmail, GrantOnebox, InitCategoryTagStats, MigrateBadgeImageToUploads, MigrateCensoredWords, MigrateCustomEmojis, MigrateFeaturedLinks, MigrateTaggingPlugin, MigrateUploadExtensions, PostUploadsRecovery, RemoveOldAutoCloseJobs, RetroGrantAnniversary, RetroRecentTimeRead
Class Method Summary collapse
Instance Method Summary collapse
-
#execute(args) ⇒ Object
Pass ‘force: true` to force it happen again.
- #running_key_name ⇒ Object
Methods inherited from Base
acquire_cluster_concurrency_lock!, clear_cluster_concurrency_lock!, cluster_concurrency, cluster_concurrency_redis_key, delayed_perform, #error_context, get_cluster_concurrency, #last_db_duration, #log, #perform, #perform_immediately
Class Method Details
.enqueue_all ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/jobs/onceoff/onceoff.rb', line 31 def self.enqueue_all previously_ran = OnceoffLog.pluck(:job_name).uniq ObjectSpace .each_object(Class) .select { |klass| klass < self } .each do |klass| job_name = name_for(klass) Jobs.enqueue(job_name.underscore.to_sym) unless previously_ran.include?(job_name) end end |
.name_for(klass) ⇒ Object
6 7 8 |
# File 'app/jobs/onceoff/onceoff.rb', line 6 def self.name_for(klass) klass.name.sub(/\AJobs\:\:/, "") end |
Instance Method Details
#execute(args) ⇒ Object
Pass ‘force: true` to force it happen again
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/jobs/onceoff/onceoff.rb', line 15 def execute(args) job_name = self.class.name_for(self.class) has_lock = Discourse.redis.setnx(running_key_name, Time.now.to_i) # If we can't get a lock, just noop if args[:force] || has_lock begin return if OnceoffLog.where(job_name: job_name).exists? && !args[:force] execute_onceoff(args) OnceoffLog.create!(job_name: job_name) ensure Discourse.redis.del(running_key_name) if has_lock end end end |
#running_key_name ⇒ Object
10 11 12 |
# File 'app/jobs/onceoff/onceoff.rb', line 10 def running_key_name "#{self.class.name}:running" end |