Laravel Scheduling custom settings
I am using the Laravel 5.7 and now I am facing the following problem:
I have a cronjobs table which contains many cronjob records. Let's take one for example:
Record one should be repeated every 50 minutes
.
I created function getMinutelyCronjobs
fetches from DB all the cronjobs whish has to be executed minutely.
I went this way: I created a class in Commands Minutely.php
where I get all this cronjobs in the handle()
function. When I initialized all the data in Minutely.php
class, I cann call this handle()
function using $schedule->command('cronjobs:minutely')->everyMinute();
.
The problem is, that every cronjob could have different minute_x
(recurrence, in my example 50
) and then the $schedule->command('cronjobs:minutely')->everyMinute();
should be $schedule->command('cronjobs:minutely')->everyMinute(50);
.
here is my getMinutelyCronjobs
function :
public static function getMinutelyCronjobs(){
$fields = ['id', 'protocol', 'script', 'minutes_frequency', 'login_user', 'login_password', 'email'];
return Cronjob::select($fields)->where('minutely', 1)
->orderBy('id', 'desc')
->get();
}
How could I implement this ? Thank you for your help.
php laravel laravel-5 scheduled-tasks
add a comment |
I am using the Laravel 5.7 and now I am facing the following problem:
I have a cronjobs table which contains many cronjob records. Let's take one for example:
Record one should be repeated every 50 minutes
.
I created function getMinutelyCronjobs
fetches from DB all the cronjobs whish has to be executed minutely.
I went this way: I created a class in Commands Minutely.php
where I get all this cronjobs in the handle()
function. When I initialized all the data in Minutely.php
class, I cann call this handle()
function using $schedule->command('cronjobs:minutely')->everyMinute();
.
The problem is, that every cronjob could have different minute_x
(recurrence, in my example 50
) and then the $schedule->command('cronjobs:minutely')->everyMinute();
should be $schedule->command('cronjobs:minutely')->everyMinute(50);
.
here is my getMinutelyCronjobs
function :
public static function getMinutelyCronjobs(){
$fields = ['id', 'protocol', 'script', 'minutes_frequency', 'login_user', 'login_password', 'email'];
return Cronjob::select($fields)->where('minutely', 1)
->orderBy('id', 'desc')
->get();
}
How could I implement this ? Thank you for your help.
php laravel laravel-5 scheduled-tasks
add a comment |
I am using the Laravel 5.7 and now I am facing the following problem:
I have a cronjobs table which contains many cronjob records. Let's take one for example:
Record one should be repeated every 50 minutes
.
I created function getMinutelyCronjobs
fetches from DB all the cronjobs whish has to be executed minutely.
I went this way: I created a class in Commands Minutely.php
where I get all this cronjobs in the handle()
function. When I initialized all the data in Minutely.php
class, I cann call this handle()
function using $schedule->command('cronjobs:minutely')->everyMinute();
.
The problem is, that every cronjob could have different minute_x
(recurrence, in my example 50
) and then the $schedule->command('cronjobs:minutely')->everyMinute();
should be $schedule->command('cronjobs:minutely')->everyMinute(50);
.
here is my getMinutelyCronjobs
function :
public static function getMinutelyCronjobs(){
$fields = ['id', 'protocol', 'script', 'minutes_frequency', 'login_user', 'login_password', 'email'];
return Cronjob::select($fields)->where('minutely', 1)
->orderBy('id', 'desc')
->get();
}
How could I implement this ? Thank you for your help.
php laravel laravel-5 scheduled-tasks
I am using the Laravel 5.7 and now I am facing the following problem:
I have a cronjobs table which contains many cronjob records. Let's take one for example:
Record one should be repeated every 50 minutes
.
I created function getMinutelyCronjobs
fetches from DB all the cronjobs whish has to be executed minutely.
I went this way: I created a class in Commands Minutely.php
where I get all this cronjobs in the handle()
function. When I initialized all the data in Minutely.php
class, I cann call this handle()
function using $schedule->command('cronjobs:minutely')->everyMinute();
.
The problem is, that every cronjob could have different minute_x
(recurrence, in my example 50
) and then the $schedule->command('cronjobs:minutely')->everyMinute();
should be $schedule->command('cronjobs:minutely')->everyMinute(50);
.
here is my getMinutelyCronjobs
function :
public static function getMinutelyCronjobs(){
$fields = ['id', 'protocol', 'script', 'minutes_frequency', 'login_user', 'login_password', 'email'];
return Cronjob::select($fields)->where('minutely', 1)
->orderBy('id', 'desc')
->get();
}
How could I implement this ? Thank you for your help.
php laravel laravel-5 scheduled-tasks
php laravel laravel-5 scheduled-tasks
edited Nov 28 '18 at 12:55
handkock
asked Nov 28 '18 at 11:55
handkockhandkock
3701316
3701316
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
If you can get by with running the task every hour instead of every 50 minutes, the first answer will work. If you need it to be specifically every 50 minutes, you can try something like this, which should run every 50 minutes instead of every 60.
EDIT:
You didn't give the details about the data you are pulling from your database relating to the jobs, but you should be able to just do something like this to schedule each job.
foreach ($jobs as $job) {
$schedule->command($job->command)->everyMinute()->when(function () {
$now = new DateTime;
$minutes = floatval($now->format('G'))*60 + floatval($now->format('i'));
return $minutes % $job->minutes == 0;
});
}
Take a look at my comment on the previous answer please, it is not quite what I need
– handkock
Nov 28 '18 at 12:18
I updated it slightly to assume you are looping through each job and that each job could have a different schedule. Unless I'm misunderstanding, I think that's what you wanted to accomplish.
– Thursday42
Nov 28 '18 at 12:28
Yup, I thought to do it that way, but I get the records in the strange Collections way which containstable:protected
,with:protected
and other model fields along with the records I need, do I know, what could be the problem ? When I call the same function in COntroller, I get the data in the right way(associative array)
– handkock
Nov 28 '18 at 12:42
I'm not sure what to say without seeing more data. Did you try this?foreach ($jobs->toArray() as $job)
Does that make any difference?
– Thursday42
Nov 28 '18 at 12:49
No,toArray()
function is not working. I am getting the records in this way textuploader.com/d3w24 , and I cannot retrieve data from this Collection properly. U can see mygetMinutelyRecords
function, which gives this collection in my question, Thanks!
– handkock
Nov 28 '18 at 12:52
|
show 2 more comments
everyMinute()
instead of use hourlyAt()
method
Run the task every hour at 50 mins past the hour
$schedule->command('cronjobs:minutely')->hourlyAt(50);
for more information read this article
The problem is, that that was explicitly said 50 here, but it is a variable x, so I should load for every cronjob its minutes_x in the schedule function
– handkock
Nov 28 '18 at 12:17
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53518917%2flaravel-scheduling-custom-settings%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you can get by with running the task every hour instead of every 50 minutes, the first answer will work. If you need it to be specifically every 50 minutes, you can try something like this, which should run every 50 minutes instead of every 60.
EDIT:
You didn't give the details about the data you are pulling from your database relating to the jobs, but you should be able to just do something like this to schedule each job.
foreach ($jobs as $job) {
$schedule->command($job->command)->everyMinute()->when(function () {
$now = new DateTime;
$minutes = floatval($now->format('G'))*60 + floatval($now->format('i'));
return $minutes % $job->minutes == 0;
});
}
Take a look at my comment on the previous answer please, it is not quite what I need
– handkock
Nov 28 '18 at 12:18
I updated it slightly to assume you are looping through each job and that each job could have a different schedule. Unless I'm misunderstanding, I think that's what you wanted to accomplish.
– Thursday42
Nov 28 '18 at 12:28
Yup, I thought to do it that way, but I get the records in the strange Collections way which containstable:protected
,with:protected
and other model fields along with the records I need, do I know, what could be the problem ? When I call the same function in COntroller, I get the data in the right way(associative array)
– handkock
Nov 28 '18 at 12:42
I'm not sure what to say without seeing more data. Did you try this?foreach ($jobs->toArray() as $job)
Does that make any difference?
– Thursday42
Nov 28 '18 at 12:49
No,toArray()
function is not working. I am getting the records in this way textuploader.com/d3w24 , and I cannot retrieve data from this Collection properly. U can see mygetMinutelyRecords
function, which gives this collection in my question, Thanks!
– handkock
Nov 28 '18 at 12:52
|
show 2 more comments
If you can get by with running the task every hour instead of every 50 minutes, the first answer will work. If you need it to be specifically every 50 minutes, you can try something like this, which should run every 50 minutes instead of every 60.
EDIT:
You didn't give the details about the data you are pulling from your database relating to the jobs, but you should be able to just do something like this to schedule each job.
foreach ($jobs as $job) {
$schedule->command($job->command)->everyMinute()->when(function () {
$now = new DateTime;
$minutes = floatval($now->format('G'))*60 + floatval($now->format('i'));
return $minutes % $job->minutes == 0;
});
}
Take a look at my comment on the previous answer please, it is not quite what I need
– handkock
Nov 28 '18 at 12:18
I updated it slightly to assume you are looping through each job and that each job could have a different schedule. Unless I'm misunderstanding, I think that's what you wanted to accomplish.
– Thursday42
Nov 28 '18 at 12:28
Yup, I thought to do it that way, but I get the records in the strange Collections way which containstable:protected
,with:protected
and other model fields along with the records I need, do I know, what could be the problem ? When I call the same function in COntroller, I get the data in the right way(associative array)
– handkock
Nov 28 '18 at 12:42
I'm not sure what to say without seeing more data. Did you try this?foreach ($jobs->toArray() as $job)
Does that make any difference?
– Thursday42
Nov 28 '18 at 12:49
No,toArray()
function is not working. I am getting the records in this way textuploader.com/d3w24 , and I cannot retrieve data from this Collection properly. U can see mygetMinutelyRecords
function, which gives this collection in my question, Thanks!
– handkock
Nov 28 '18 at 12:52
|
show 2 more comments
If you can get by with running the task every hour instead of every 50 minutes, the first answer will work. If you need it to be specifically every 50 minutes, you can try something like this, which should run every 50 minutes instead of every 60.
EDIT:
You didn't give the details about the data you are pulling from your database relating to the jobs, but you should be able to just do something like this to schedule each job.
foreach ($jobs as $job) {
$schedule->command($job->command)->everyMinute()->when(function () {
$now = new DateTime;
$minutes = floatval($now->format('G'))*60 + floatval($now->format('i'));
return $minutes % $job->minutes == 0;
});
}
If you can get by with running the task every hour instead of every 50 minutes, the first answer will work. If you need it to be specifically every 50 minutes, you can try something like this, which should run every 50 minutes instead of every 60.
EDIT:
You didn't give the details about the data you are pulling from your database relating to the jobs, but you should be able to just do something like this to schedule each job.
foreach ($jobs as $job) {
$schedule->command($job->command)->everyMinute()->when(function () {
$now = new DateTime;
$minutes = floatval($now->format('G'))*60 + floatval($now->format('i'));
return $minutes % $job->minutes == 0;
});
}
edited Nov 28 '18 at 12:27
answered Nov 28 '18 at 12:15
Thursday42Thursday42
1775
1775
Take a look at my comment on the previous answer please, it is not quite what I need
– handkock
Nov 28 '18 at 12:18
I updated it slightly to assume you are looping through each job and that each job could have a different schedule. Unless I'm misunderstanding, I think that's what you wanted to accomplish.
– Thursday42
Nov 28 '18 at 12:28
Yup, I thought to do it that way, but I get the records in the strange Collections way which containstable:protected
,with:protected
and other model fields along with the records I need, do I know, what could be the problem ? When I call the same function in COntroller, I get the data in the right way(associative array)
– handkock
Nov 28 '18 at 12:42
I'm not sure what to say without seeing more data. Did you try this?foreach ($jobs->toArray() as $job)
Does that make any difference?
– Thursday42
Nov 28 '18 at 12:49
No,toArray()
function is not working. I am getting the records in this way textuploader.com/d3w24 , and I cannot retrieve data from this Collection properly. U can see mygetMinutelyRecords
function, which gives this collection in my question, Thanks!
– handkock
Nov 28 '18 at 12:52
|
show 2 more comments
Take a look at my comment on the previous answer please, it is not quite what I need
– handkock
Nov 28 '18 at 12:18
I updated it slightly to assume you are looping through each job and that each job could have a different schedule. Unless I'm misunderstanding, I think that's what you wanted to accomplish.
– Thursday42
Nov 28 '18 at 12:28
Yup, I thought to do it that way, but I get the records in the strange Collections way which containstable:protected
,with:protected
and other model fields along with the records I need, do I know, what could be the problem ? When I call the same function in COntroller, I get the data in the right way(associative array)
– handkock
Nov 28 '18 at 12:42
I'm not sure what to say without seeing more data. Did you try this?foreach ($jobs->toArray() as $job)
Does that make any difference?
– Thursday42
Nov 28 '18 at 12:49
No,toArray()
function is not working. I am getting the records in this way textuploader.com/d3w24 , and I cannot retrieve data from this Collection properly. U can see mygetMinutelyRecords
function, which gives this collection in my question, Thanks!
– handkock
Nov 28 '18 at 12:52
Take a look at my comment on the previous answer please, it is not quite what I need
– handkock
Nov 28 '18 at 12:18
Take a look at my comment on the previous answer please, it is not quite what I need
– handkock
Nov 28 '18 at 12:18
I updated it slightly to assume you are looping through each job and that each job could have a different schedule. Unless I'm misunderstanding, I think that's what you wanted to accomplish.
– Thursday42
Nov 28 '18 at 12:28
I updated it slightly to assume you are looping through each job and that each job could have a different schedule. Unless I'm misunderstanding, I think that's what you wanted to accomplish.
– Thursday42
Nov 28 '18 at 12:28
Yup, I thought to do it that way, but I get the records in the strange Collections way which contains
table:protected
, with:protected
and other model fields along with the records I need, do I know, what could be the problem ? When I call the same function in COntroller, I get the data in the right way(associative array)– handkock
Nov 28 '18 at 12:42
Yup, I thought to do it that way, but I get the records in the strange Collections way which contains
table:protected
, with:protected
and other model fields along with the records I need, do I know, what could be the problem ? When I call the same function in COntroller, I get the data in the right way(associative array)– handkock
Nov 28 '18 at 12:42
I'm not sure what to say without seeing more data. Did you try this?
foreach ($jobs->toArray() as $job)
Does that make any difference?– Thursday42
Nov 28 '18 at 12:49
I'm not sure what to say without seeing more data. Did you try this?
foreach ($jobs->toArray() as $job)
Does that make any difference?– Thursday42
Nov 28 '18 at 12:49
No,
toArray()
function is not working. I am getting the records in this way textuploader.com/d3w24 , and I cannot retrieve data from this Collection properly. U can see my getMinutelyRecords
function, which gives this collection in my question, Thanks!– handkock
Nov 28 '18 at 12:52
No,
toArray()
function is not working. I am getting the records in this way textuploader.com/d3w24 , and I cannot retrieve data from this Collection properly. U can see my getMinutelyRecords
function, which gives this collection in my question, Thanks!– handkock
Nov 28 '18 at 12:52
|
show 2 more comments
everyMinute()
instead of use hourlyAt()
method
Run the task every hour at 50 mins past the hour
$schedule->command('cronjobs:minutely')->hourlyAt(50);
for more information read this article
The problem is, that that was explicitly said 50 here, but it is a variable x, so I should load for every cronjob its minutes_x in the schedule function
– handkock
Nov 28 '18 at 12:17
add a comment |
everyMinute()
instead of use hourlyAt()
method
Run the task every hour at 50 mins past the hour
$schedule->command('cronjobs:minutely')->hourlyAt(50);
for more information read this article
The problem is, that that was explicitly said 50 here, but it is a variable x, so I should load for every cronjob its minutes_x in the schedule function
– handkock
Nov 28 '18 at 12:17
add a comment |
everyMinute()
instead of use hourlyAt()
method
Run the task every hour at 50 mins past the hour
$schedule->command('cronjobs:minutely')->hourlyAt(50);
for more information read this article
everyMinute()
instead of use hourlyAt()
method
Run the task every hour at 50 mins past the hour
$schedule->command('cronjobs:minutely')->hourlyAt(50);
for more information read this article
answered Nov 28 '18 at 12:05
Jignesh JoisarJignesh Joisar
3,03021124
3,03021124
The problem is, that that was explicitly said 50 here, but it is a variable x, so I should load for every cronjob its minutes_x in the schedule function
– handkock
Nov 28 '18 at 12:17
add a comment |
The problem is, that that was explicitly said 50 here, but it is a variable x, so I should load for every cronjob its minutes_x in the schedule function
– handkock
Nov 28 '18 at 12:17
The problem is, that that was explicitly said 50 here, but it is a variable x, so I should load for every cronjob its minutes_x in the schedule function
– handkock
Nov 28 '18 at 12:17
The problem is, that that was explicitly said 50 here, but it is a variable x, so I should load for every cronjob its minutes_x in the schedule function
– handkock
Nov 28 '18 at 12:17
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53518917%2flaravel-scheduling-custom-settings%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown