Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
{}[https://travis-ci.org/mashable/gaspar]
Gaspar is a recurring job ("cron") manager for Ruby daemons. It's primarily intended to be used with Rails + Sidekiq/Resque and friends.
Gaspar runs in-process, meaning there is no additional daemon to configure or maintain. Just define your jobs and they'll get fired by something, whether that's your Rails processes, Sidekiq workers, or whatnot. Of course, you can always run it in a separate daemon if you wanted, too.
By default, Gaspar does not run if you are running under Rails and Rails.env.test?
. Pass :permit_test_mode => true
to Gaspar.schedule
if you want Gaspar to run in test mode.
Add this line to your application's Gemfile:
gem 'gaspar'
And then execute:
$ bundle
Or install it yourself as:
$ gem install gaspar
Usage is straightforward. Jobs are defined in a DSL. At a minimum, you need to pass a Redis instance to Gaspar, which is used for synchronizing job locks. The redis instance should be threadsafe; if you haven't turned it off explicitly, thread safety should already be present.
Gaspar.configure(:logger => Rails.logger) do
every "5s", "Ping" do
Rails.logger.debug "ping"
end
end
Job definitions take one of several formats:
every [time], [job name] do
# Code to run
end
If you have Resque or Sidekiq installed, you can pass a worker class name as string or symbol (plus any args), and it'll be automatically enqueued when the job fires:
every [time], :DoStuffWorker, 1, 2, 3
# If you are using Resque, this will fire `Resque.enqueue(DoStuffWorker, 1, 2, 3)`
# If you are using Sidekiq, this will fire `DoStuffWorker.perform_async(1, 2, 3)`
Jobs also accept cron formats:
cron "15,30 * * * *" do
# Run stuff at 15 and 30 past the hour
end
Jobs are each run in their own individual thread, but you should keep your jobs as lightweight as possible, so best practices will generally mean firing off background workers. Jobs should never exceed 15 seconds runtime, as on process exit, Gaspar will delay for up to 15 seconds to allow currently-running jobs to terminate before they are abandoned. Additionally, jobs should be threadsafe.
Gaspar.configure(:logger => Rails.logger) do
every "10m", :UpdateStuffWorker
cron "0 * * * * ", :DailyUpdateWorker, "with", :some_options => true
every("1h") { HourlyUpdateWorker.perform_async }
end
Once you have Gaspar configured, you'll need to choose when to start it, and you'll pass a Redis connection for Gaspar to use. This is done separately from the configuration with the expectation that you won't want to run Gaspar for everything that boots your app, and you'll need to take care to close Gaspar (using Gaspar#retire
) pre-forking, and to start it post-forking (using Gaspar#start!
)
Gaspar.start!(Redis.new)
Since Gaspar uses a Redis connection, you should initialize it after your daemon forks. For example, to use it with Unicorn:
before_fork do |server, worker|
Gaspar.retire
end
after_fork do |server, worker|
Gaspar.start! Redis.new
end
Or with Passenger:
PhusionPassenger.on_event(:starting_worker_process) do |forked|
if forked
Gaspar.start! Redis.new
end
end
Finally, Gaspar will refuse to initialize if the process has a controlling TTY. This prevents it from running for, say, rake tasks and the like.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that gaspar demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.