Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 608673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:29:08+00:00 2026-05-13T17:29:08+00:00

I’m using Starling and Workling to process background tasks in my application, a Swoopo-style

  • 0

I’m using Starling and Workling to process background tasks in my application, a Swoopo-style auction site. In this case the background task is a notification system that monitors auctions and notifies the winner. The monitor is invoked upon creation of the auction object. My problem is that my monitoring code can’t find the auction it’s supposed to monitor. Here’s the code:

The unit test that fails:

class AuctionTest < ActiveSupport::TestCase
  test "are monitored when created" do
    auction = Auction.new(
      :name => "A TV",
      :markdown => "A large TV",
      :starting_bid => 0.01,
      :bid_increment => 0.01,
      :starts_at => Time.now(),
      :ends_at => Time.now() + 5.seconds,
      :active => true
    )
    auction.save
    Bid.place(@current_user, auction)

    sleep(10) #when bids are placed, time is added to the end of the auction so wait

    assert auction.won?
    assert_equal @current_user.id, auction.winner_id
  end
end

The worker code:

class AuctionsWorker < Workling::Base
  def monitor(options)
    active = true
    ends_at = options[:original_ends_at]
    while active
      auction = Auction.find(options[:auction_id]) #this is the record that cannot be found
      if auction.won?
        active = false
        winner = User.find(auction.high_bidder).id
        auction.update_attribute(:winner_id, winner)
      else
        until Time.now() >= ends_at
          sleep(1)
        end
      end
    end
  end
end

The code that calls the worker:

class Auction < ActiveRecord::Base
  def after_create
    AuctionsWorker.asynch_monitor(:auction_id => self.id, :original_ends_at => self.ends_at) if self.active?
  end
end

Every time I run the test, I receive an error telling me that the auction supplied to the worker can’t be found.

Does anyone have any ideas? I’m using rails 2.3.5, sqlite3 and the latest Starling, Workling, and all other associated gems on a Mac OSX 10.6.2 Macbook Pro if it helps.

Thank you for all input.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:29:08+00:00Added an answer on May 13, 2026 at 5:29 pm

    You should get downvoted for creating a “swoopo-style” auction, and I feel dirty for helping you.

    after_create() Is called after
    Base.save on new objects that haven‘t
    been saved yet (no record exists)

    so after_create is a bit of a misnomer – the record hasn’t really been created yet.

    http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html#M002142

    You could add your own id field and have the workling process search the db for that id, sleeping a few seconds every time it doesn’t find it (up to some preset failure limit).

    Alternatively – you could try one of the several after_commit plugins that are on github that get called after the database has been updated.

    Here’s one:

    http://github.com/delynn/after_commit

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can tell the compiler only three things, in three… May 14, 2026 at 5:08 pm
  • Editorial Team
    Editorial Team added an answer You can use .find() (any descendant), or .children() (only direct… May 14, 2026 at 5:08 pm
  • Editorial Team
    Editorial Team added an answer As I mentioned, it looks like there were known memory… May 14, 2026 at 5:08 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.