[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-8023":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":22,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":16,"starSnapshotCount":16,"syncStatus":27,"lastSyncTime":28,"discoverSource":29},8023,"delayed_job","tobi\u002Fdelayed_job","tobi","Database backed asynchronous priority queue -- Extracted from Shopify ","http:\u002F\u002Ftobi.github.com\u002Fdelayed_job",null,"Ruby",2172,1238,23,37,0,1,61.38,"MIT License",false,"master",true,[],"2026-06-12 04:00:37","h1. Delayed::Job\n\nDelayed_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background. \n\nIt is a direct extraction from Shopify where the job table is responsible for a multitude of core tasks. Amongst those tasks are:\n\n* sending massive newsletters\n* image resizing\n* http downloads\n* updating smart collections\n* updating solr, our search server, after product changes\n* batch imports \n* spam checks \n\nh2. Setup\n\nThe library evolves around a delayed_jobs table which can be created by using:\n\u003Cpre>\u003Ccode>\n  script\u002Fgenerate delayed_job\n\u003C\u002Fcode>\u003C\u002Fpre>\n\nThe created table looks as follows: \n\n\u003Cpre>\u003Ccode>\n  create_table :delayed_jobs, :force => true do |table|\n    table.integer  :priority, :default => 0      # Allows some jobs to jump to the front of the queue\n    table.integer  :attempts, :default => 0      # Provides for retries, but still fail eventually.\n    table.text     :handler                      # YAML-encoded string of the object that will do work\n    table.string   :last_error                   # reason for last failure (See Note below)\n    table.datetime :run_at                       # When to run. Could be Time.now for immediately, or sometime in the future.\n    table.datetime :locked_at                    # Set when a client is working on this object\n    table.datetime :failed_at                    # Set when all retries have failed (actually, by default, the record is deleted instead)\n    table.string   :locked_by                    # Who is working on this object (if locked)\n    table.timestamps\n  end\n\u003C\u002Fcode>\u003C\u002Fpre>\n\nOn failure, the job is scheduled again in 5 seconds + N ** 4, where N is the number of retries.\n\nThe default @MAX_ATTEMPTS@ is @25@. After this, the job either deleted (default), or left in the database with \"failed_at\" set.\nWith the default of 25 attempts, the last retry will be 20 days later, with the last interval being almost 100 hours.\n\nThe default @MAX_RUN_TIME@ is @4.hours@. If your job takes longer than that, another computer could pick it up. It's up to you to\nmake sure your job doesn't exceed this time. You should set this to the longest time you think the job could take.\n\nBy default, it will delete failed jobs (and it always deletes successful jobs). If you want to keep failed jobs, set\n@Delayed::Job.destroy_failed_jobs = false@. The failed jobs will be marked with non-null failed_at.\n\nHere is an example of changing job parameters in Rails:\n\n\u003Cpre>\u003Ccode>\n  # config\u002Finitializers\u002Fdelayed_job_config.rb\n  Delayed::Job.destroy_failed_jobs = false\n  silence_warnings do\n    Delayed::Job.const_set(\"MAX_ATTEMPTS\", 3)\n    Delayed::Job.const_set(\"MAX_RUN_TIME\", 5.minutes)\n  end\n\u003C\u002Fcode>\u003C\u002Fpre>\n\nNote: If your error messages are long, consider changing last_error field to a :text instead of a :string (255 character limit).\n\n\nh2. Usage\n\nJobs are simple ruby objects with a method called perform. Any object which responds to perform can be stuffed into the jobs table.\nJob objects are serialized to yaml so that they can later be resurrected by the job runner. \n\n\u003Cpre>\u003Ccode>\n  class NewsletterJob \u003C Struct.new(:text, :emails)\n    def perform\n      emails.each { |e| NewsletterMailer.deliver_text_to_email(text, e) }\n    end    \n  end  \n  \n  Delayed::Job.enqueue NewsletterJob.new('lorem ipsum...', Customers.find(:all).collect(&:email))\n\u003C\u002Fcode>\u003C\u002Fpre>\n\nThere is also a second way to get jobs in the queue: send_later. \n\n\u003Cpre>\u003Ccode>\n  BatchImporter.new(Shop.find(1)).send_later(:import_massive_csv, massive_csv)\n\u003C\u002Fcode>\u003C\u002Fpre>\n\nThis will simply create a @Delayed::PerformableMethod@ job in the jobs table which serializes all the parameters you pass to it. There are some special smarts for active record objects\nwhich are stored as their text representation and loaded from the database fresh when the job is actually run later.\n                                                                                                                              \n                                                                                                                    \nh2. Running the jobs\n\nYou can invoke @rake jobs:work@ which will start working off jobs. You can cancel the rake task with @CTRL-C@. \n\nYou can also run by writing a simple @script\u002Fjob_runner@, and invoking it externally:\n  \n\u003Cpre>\u003Ccode>\n  #!\u002Fusr\u002Fbin\u002Fenv ruby\n  require File.dirname(__FILE__) + '\u002F..\u002Fconfig\u002Fenvironment'\n  \n  Delayed::Worker.new.start  \n\u003C\u002Fcode>\u003C\u002Fpre>\n\nWorkers can be running on any computer, as long as they have access to the database and their clock is in sync. You can even\nrun multiple workers on per computer, but you must give each one a unique name:\n\n\u003Cpre>\u003Ccode>\n  3.times do |n|\n    worker = Delayed::Worker.new\n    worker.name = 'worker-' + n.to_s\n    worker.start\n  end\t\n\u003C\u002Fcode>\u003C\u002Fpre>\n\nKeep in mind that each worker will check the database at least every 5 seconds.\n\nNote: The rake task will exit if the database has any network connectivity problems.\n\nh3. Cleaning up\n\nYou can invoke @rake jobs:clear@ to delete all jobs in the queue.\n\nh3. Changes\n\n* 1.7.0: Added failed_at column which can optionally be set after a certain amount of failed job attempts. By default failed job attempts are destroyed after about a month. \n\n* 1.6.0: Renamed locked_until to locked_at. We now store when we start a given job instead of how long it will be locked by the worker. This allows us to get a reading on how long a job took to execute.                    \n\n* 1.5.0: Job runners can now be run in parallel. Two new database columns are needed: locked_until and locked_by. This allows us to use   pessimistic locking instead of relying on row level locks. This enables us to run as many worker processes as we need to speed up queue processing.\n\n* 1.2.0: Added #send_later to Object for simpler job creation\n\n* 1.0.0: Initial release\n","Delayed::Job 是一个基于数据库的异步优先队列工具，从 Shopify 中提取而来。它支持后台执行耗时任务，如发送大量邮件、图片处理、HTTP 下载等。其核心功能包括任务优先级设置、自动重试机制（默认25次尝试）以及失败后的处理策略。通过创建 delayed_jobs 表来存储待处理的任务信息，用户可以根据需要调整任务的最大尝试次数和最长运行时间等参数。适用于需要在后台异步执行且可容忍一定延迟的任务场景，特别适合电商网站或其他需要批量处理数据的应用。",2,"2026-06-11 03:15:41","top_language"]