Giter Site home page Giter Site logo

Comments (14)

jmettraux avatar jmettraux commented on June 2, 2024 1

Is there some kind of fallback scenario where that value might be true instead of the job instance?

Hello,

It's not a fallback, it's a temporary true value, to pre-reserve before assignation. IIRC.

https://github.com/jmettraux/rufus-scheduler/blob/master/lib/rufus/scheduler/jobs_core.rb#L311-L312

from rufus-scheduler.

jmettraux avatar jmettraux commented on June 2, 2024 1

"losing data" sounds scary.

There is also the case where the thread use by the job just ended and it pops in your loop because when the .threads(:active) array was established it serviced a job, but when you consider it, it might have ended. I would do something like

  schedule.work_threads(:active).each do |t|
    i = t[:rufus_scheduler_job].identifier rescue nil
    thread_usage[i] += 1 if i
  end

That should cover the nil and the true extra cases.

from rufus-scheduler.

jmettraux avatar jmettraux commented on June 2, 2024

Job#name

describe '#name' do
it 'returns the job name' do
j = @scheduler.schedule_in '10d', name: 'alice' do; end
expect(j.name).to eq('alice')
end
end

from rufus-scheduler.

jmettraux avatar jmettraux commented on June 2, 2024

Hello,

I have the impression the hacks are better at the level of your ruby-clock gem.

Regarding the name, how about

class Rufus::Scheduler::Job
  def full_name
    [ name, source_location.map(&:to_s).join(':') ].join(' ')
  end
end

which returns something like "alice /home/jmettraux/w/rufus-scheduler/spec/job_spec.rb:408" ?

It uses the #source_location method I added to Job.

Best regards.

from rufus-scheduler.

jjb avatar jjb commented on June 2, 2024

wow cool! thanks!

do you know if there's a way to access the job from schedule.work_threads(:active).first?

from rufus-scheduler.

jmettraux avatar jmettraux commented on June 2, 2024

Hello,

yes, you can do

scheduler.work_threads(:active).each_with_index do |t, i|
  puts "#{i}. work thread #{t.id} is active for job #{t[:rufus_scheduler_job].source_location}"
end

Is that sufficient?

from rufus-scheduler.

jjb avatar jjb commented on June 2, 2024

this is perfect - this code gives me exactly what i wanted

  job_code = schedule.work_threads(:active).map do |t|
    t[:rufus_scheduler_job].handler.source.split("\n")[1].strip
  end

from rufus-scheduler.

jmettraux avatar jmettraux commented on June 2, 2024

OK, give me one or two days to release with Job#source_location, then I will close this issue.

Best regards.

from rufus-scheduler.

jjb avatar jjb commented on June 2, 2024

Thanks, for now I don't need it for what I'm working on, so no time pressure here. I'll let you know what I come up with.

from rufus-scheduler.

jjb avatar jjb commented on June 2, 2024

Okay, I've made Rufus::Scheduler::Job#identifier jjb/ruby-clock#2

I'm going to implement this at work first to see if I want to update anything, so it will get merged and released in the next few days. Any feedback welcome!


edit: I did actually end up depending on the new source_location feature!

from rufus-scheduler.

jjb avatar jjb commented on June 2, 2024

just got a confusing error message from this code:

  schedule.work_threads(:active).each do |t|
    thread_usage[t[:rufus_scheduler_job].identifier] += 1
  end

undefined method `identifier' for true:TrueClass

it happened exactly once when my clock process started. Now that loop, which runs every 10 seconds, seems to be happy and functional.

Is there some kind of fallback scenario where that value might be true instead of the job instance?

from rufus-scheduler.

jjb avatar jjb commented on June 2, 2024

Gotcha, thanks! So it's only when the thread is starting up. so i think i can safely just next along when i see that and not risk losing any data

from rufus-scheduler.

jmettraux avatar jmettraux commented on June 2, 2024

3.8.0 released

Thanks!

from rufus-scheduler.

jjb avatar jjb commented on June 2, 2024

great! and thanks for the extra info about missing jobs

from rufus-scheduler.

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.