Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Database Events #11

Closed
SirRawlins opened this issue Oct 7, 2016 · 7 comments
Closed

Support for Database Events #11

SirRawlins opened this issue Oct 7, 2016 · 7 comments

Comments

@SirRawlins
Copy link

I've got a bunch of clockwork tasks which are implemented as database events, as per the docs https://github.com/tomykaira/clockwork#use-with-database-events.

require 'clockwork'
require 'clockwork/database_events'
require File.expand_path('../../config/boot',        __FILE__)
require File.expand_path('../../config/environment', __FILE__)

module Clockwork

    # required to enable database syncing support
    Clockwork.manager = DatabaseEvents::Manager.new

    # Update all mailchimp publishers with the latest
    # details from the Mailchimp account.
    sync_database_events model: PublisherSubscriberSyncClock, every: 1.minute do |model_instance|
        # Sync the unsubscribers for the publisher
        model_instance.delay(:queue => 'publisher-subscriber-sync').sync_subscribers if model_instance.responds_to?(:sync_subscribers)
    end

end

And I'm trying to test against them in the following manor.

# Stage an email publisher in the database.
before(:each) { FactoryGirl.create_list(:email_publisher, 3) }

# Run the clock.
before(:each) { Clockwork::Test.run(file: "#{Rails.root}/lib/clock.rb", max_ticks: 10, tick_speed: 1.minute) }

it "Ran the sync job" do
    # Assert that the job was run.
    expect(Clockwork::Test.ran_job?('PublisherSubscriberSyncClock')).to be_truthy
end

# Reset the tests after each has run.
after(:each) { Clockwork::Test.clear! }

However these clocks don't appear to be run and my assertions fail. Even when inspecting the job history through Clockwork::Test.manager.send(:history).jobs they are not listed anywhere, the history is empty.

Traditional non-database jobs are run as expected however.

@kevin-j-m
Copy link
Owner

Thanks for reporting. To my knowledge, this library has not been tested against database events. I can't say confidently if the issue is with your test or the library.

@kevin-j-m
Copy link
Owner

kevin-j-m commented Oct 7, 2016

Again, @SirRawlins, I've never used database events with clockwork, but in looking through the documentation, could the issue be that the test does not have a persisted PublisherSubscriberSyncClock in the database to check against?

In the test snippet you provided, it looks like you set up EmailPublishers, which I'm guessing the job works against, but I don't see any PublisherSubscriberSyncClocks.

I could be misunderstanding the intended usage with database events, as I've never used them personally. Let me know if that helps at all though.

@SirRawlins
Copy link
Author

Thanks for getting back to me.

So the PublisherSubscriberSync class is just a clockwork wrapper for the
EmailPublisher class, I would post a code example but am away from my Mac
for the weekend.

The data generated by FactioryGirl should be sufficient. I think it's
another piece of the puzzle missing.

I can dig deeper in to things, just wanted to check I wasn't doing anything
foolish

I could also refactor my clocks to move away from database events and
handle things in another way.

Appreciate the help.

On 7 Oct 2016 9:55 pm, "Kevin Murphy" notifications@github.com wrote:

Again, @SirRawlins https://github.com/SirRawlins, I've never used
database events with clockwork, but in looking through the documentation,
could the issue be that the test does not have a persisted
PublisherSubscriberSyncClock in the database to check against?

In the test snippet you provided, it looks like you set up EmailPublishers,
which I'm guessing the job works against, but I don't see any
PublisherSubscriberSyncClocks.

Again, I could be misunderstanding the intended usage with database
events, as I've never used them personally. Let me know if that helps at
all though.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#11 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAtiK2tgp_t1jCXGpV7cSQjk2jRO_KTgks5qxrGqgaJpZM4KQ2Qb
.

@kevin-j-m
Copy link
Owner

kevin-j-m commented Oct 7, 2016

If you could post a sample/update when you're able to, I'm happy to help so I know where this stands with you and can track it.

I can't say I understand the correlation between PublisherSubscriberSyncClock and EmailPublisher as you've described, but if setting the EmailPublisher is sufficient for the PublisherSubscriberSyncClock to have events, does the FactoryGirl factory have some default values that set, for example, frequency/at/other clockwork values so clockwork adds a clockwork event?

If you run the same setup in a local environment outside of test, can you confirm that the events are triggered?

@kevin-j-m
Copy link
Owner

@SirRawlins how are things going with this? Let me know if you've made any progress or need any feedback.

@SirRawlins
Copy link
Author

Hi Kevin, I was hoping to look at this the past couple of days but simply
haven't had time to get back to it

Completely up to you as to whether you keep the issue open or close it off
as can't promise when i will get chance.

Appreciate you following up.

On 12 Oct 2016 6:37 pm, "Kevin Murphy" notifications@github.com wrote:

@SirRawlins https://github.com/SirRawlins how are things going with
this? Let me know if you've made any progress or need any feedback.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#11 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAtiK6KnDuLhXYZE3iWPsy38Yi1s5Pn_ks5qzRrKgaJpZM4KQ2Qb
.

@kevin-j-m
Copy link
Owner

I'll close this for now, but should you get the time to take a closer look and need to revisit it, please re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants