Giter Site home page Giter Site logo

Comments (5)

schnika avatar schnika commented on June 2, 2024 1

@dsusviela directly creating callbacks from an AR callback might not be the cleanest way to do it. However since sidekiq-cron is well tested, I would stub this dependency and just accept the fact, that when Sidekiq::Cron::Job.create is being called, that everything that comes after that works as expected.

If you want to have a working integration spec you can think about setting https://github.com/sds/mock_redis as your redis backend for sidekiq. That should work as well, right?

from sidekiq-cron.

markets avatar markets commented on June 2, 2024

Hi @dsusviela thanks for your words! really appreciated!

What do you exactly mean by "a problem"? Do you want to somehow mockup the redis object? This will require to implement some kind of "adapter" thing, as this code Sidekiq.redis is used in several places. Do you know if Sidekiq itself does something similar?

from sidekiq-cron.

dsusviela avatar dsusviela commented on June 2, 2024

Hey @markets!

Maybe I can give a more practical example:

Suppose I have a Rails App, that has a model named Task. I will write some code from memory so excuse me if its not really runnable. If you want I can give an actual runnable script.

class Task < ActiveRecord
  after_save :create_task

  def create_task
    Sidekiq::Cron::Job.create("some args here")
  end
end

Suppose now that I want to run the following test suite (in my case rspec):

describe Task do
  context "when creating a valid task" do
    it "creates a sidekiq cron job"
      # i know this matcher doesn't exist but bear with me
      expect(Task.create("take dog to the vet")).to_have_created_sidekiq_cron
    end
  end
end

Now if i go to localhost:3000/sidekiq/cron I can see the task "take dog to the vet".

In my opinion I should be able to configure the backend for sidekiq cron in an initializer file or I should be able to include a file like we do in normal sidekiq ie, sidekiq/rspec that solves this problem.

However maybe my whole approach is wrong, and the smell that I have comes from a different angle (like creating cron jobs from an AR callback).

from sidekiq-cron.

markets avatar markets commented on June 2, 2024

Would be nice if we can re-use any of those sidekiq provided helpers/classes to provide similar strategy for testing sidekiq-cron. Maybe we can't re-use it, but we can use it as inspiration to provide similar stuff. Happy to review any PR in this direction.

from sidekiq-cron.

stale avatar stale commented on June 2, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from sidekiq-cron.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.