Giter Club home page Giter Club logo

Comments (6)

tanner0101 avatar tanner0101 commented on May 17, 2024 10

I don't think this is supported yet. Maybe this would be a good API:

app.jobs.schedule(SomeJob()).minutely().every(10)

from queues.

jnordberg avatar jnordberg commented on May 17, 2024 4

👍

Would be cool if the schedule builder was public as well so you can implement your own, e.g.:

app.jobs.schedule(SomeJob()).custom(SolarNoonScheduler(lat: 78.651, long: 376.990))

from queues.

Sherlouk avatar Sherlouk commented on May 17, 2024 2

Issue seems to be quiet but I too would love this functionality, my workaround is very much similar to Kevin's. Though I've made it a little more flexible in an extension 😄

extension Application.Queues {
    func scheduleEvery(_ job: ScheduledJob, minutes: Int) {
        for minuteOffset in stride(from: 0, to: 60, by: minutes) {
            schedule(job).hourly().at(.init(integerLiteral: minuteOffset))
        }
    }
}

from queues.

khoogheem avatar khoogheem commented on May 17, 2024 1

ok.. so I kinda found that this works. for doing something every 10 mins.. but surely we can come up with something easier:

    app.jobs.schedule(ApiPerformanceJob(app)).hourly().at(ScheduleBuilder.Minute(integerLiteral: 0))
    app.jobs.schedule(ApiPerformanceJob(app)).hourly().at(ScheduleBuilder.Minute(integerLiteral: 10))
    app.jobs.schedule(ApiPerformanceJob(app)).hourly().at(ScheduleBuilder.Minute(integerLiteral: 20))
    app.jobs.schedule(ApiPerformanceJob(app)).hourly().at(ScheduleBuilder.Minute(integerLiteral: 30))
    app.jobs.schedule(ApiPerformanceJob(app)).hourly().at(ScheduleBuilder.Minute(integerLiteral: 40))
    app.jobs.schedule(ApiPerformanceJob(app)).hourly().at(ScheduleBuilder.Minute(integerLiteral: 50))

from queues.

khoogheem avatar khoogheem commented on May 17, 2024

@tanner0101 That looks like it would make sense.. everything I was thinking about the other day.. just didn't convey what it should do.

from queues.

stephanmantler avatar stephanmantler commented on May 17, 2024

My temporary approach for running a job every 5 minutes:

struct MyJob : ScheduledJob {
  // start with 4 to ensure first run happens immediately
  static var inter: Int = 4

  func run(c: QueueContext) -> EventLoopFuture<Void> {
    // internal counter increments by one, modulo 5 (so wraps to 0 every five minutes)
    MyJob = (MyJob + 1) % 5
    if MyJob > 0 {
      return context.eventLoop.future()
    }
    // 
    // --- do actual work --
    ...
  }
}

from queues.

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.