With playframework, I'm trying to run a function to send a mail every day at 11PM but I don't know how to do.
I found many answers accros the internet but I haven't managed to adapt with Scala language, do you have a example of tutorial ?
Have a look at Akka Scheduler and Play! Scheduled jobs
EDIT:
I'll personally prefer Play! scheduler which uses cron. So in the example (copy/paste), you could create a Scala class similar to this:
import play.jobs.*;
/** Fire at 12pm (noon) every day **/
#On("0 0 12 * * ?")
public class Bootstrap extends Job {
public void doJob() {
Logger.info("Maintenance job ...");
...
}
}
I suggest you to use akka quartz scheduler https://github.com/enragedginger/akka-quartz-scheduler
Related
I'm trying to figure out how to run some code before and after all my cucumber tests run.
I've been tracking down a bug for a few days where some our processes create jobs on a server, and don't properly clean it up. It's easy to miss so ideally I don't want engineers to have to manually add a check to every test.
I was hoping there'd be a way to put a hook in before any tests ran to cache how many jobs exist on the server, then a hook at the end to ensure that the value hasn't changed.
I know this isn't really the best way to use cucumber, as that is more of a system test type thing to do, but doing it this way would be the best way to fit it into the existing infrastructure.
Use #BeforeClass and #AfterClass annotations in your run file.
#RunWith(Cucumber.class)
#Cucumber.Options(
format = {"json", "<the report file>"},
features = {"<the feature file>"},
strict = false,
glue = {"<package with steps classes>"})
public class TestRunFile {
#BeforeClass
public static void getJobNumbersOnServerBeforeStarting() {
//Implement logic
}
#AfterClass
public static void getJobNumbersOnServerAfterCompletion() {
//Implement logic
}
}
How about using tagged hooks.
#Before("#jobCheck")
public void beforeScenario() {
// actions
}
#After("#jobCheck")
public void afterScenario() {
// actions
}
And then for each scenario that requires this check, add #jobCheck before the Scenario definition as below.
Feature: Some feature description
#jobCheck
Scenario: It should process a sentence
// The steps
More on JVM hooks here: https://zsoltfabok.com/blog/2012/09/cucumber-jvm-hooks/
I am trying to add a cron job in moodle block.
I am following this tutorial on moodle 3.0 https://docs.moodle.org/dev/Blocks#Responding_to_Cron
When I run /admin/cron.php, my cron job does not execute.
Am I missing anything here?
The old way uses cron like this:
/blocks/yourblockname/block_yourblockname.php
class block_yourblockname extends block_base {
...
public function cron() {
// Your code.
}
and in /blocks/yourblockname/version.php
$plugin->cron = xxxx; // Cron interval in seconds. 0 means no cron.
The new way is to use scheduled tasks - https://docs.moodle.org/dev/Task_API
UPDATE: As mentioned by #Developer
If you change the cron value or add a new task then you will also need to increment the version number
$plugin->version = xxxx;
I'm using a GivenStories for executing Login scenario which is located in different story.
I was wondering if there is a way to use something similar in order to execute a logout story which is also located in different story than one I actually executing.
I know that I can do some tricks with #before/after annotations , but the question is if I can execute a "post" story
Thanks
Based on the jBehave annotation documentation a post story step can be implemented by annotating a step class method with #AfterStory (or #AfterStories if you want to execute only after all stories complete). The #AfterStory method will execute regardless of whether your executing story contains a step from the related step class (i.e. is guaranteed to execute after every story - see below for restricting to given stories).
The #BeforeStory and #AfterStory annotations allow the corresponding
methods to be executed before and after each story, either a
GivenStory or not:
#AfterStory // equivalent to #AfterStory(uponGivenStory=false)
public void afterStory() {
// ...
}
#AfterStory(uponGivenStory=true)
public void afterGivenStory() {
// ...
}
This is the answer I got from the jbehave dev channel.
Hi,
there is no such mechanism, but you could:
use the Lifecycle to execute steps (not stories) after the execution
of a scenario (executed after each scenario) have a final scenario
which invokes the given stories
I am working with JUnit and I have this idea which I want to implement.
I want to write a runner that will log the results of each test to an excel or a text file so that i can attach it in my reports.
What do i need to learn to get started
Two alternatives
Write a RunListener and use it like:
public void main(String... args) {
JUnitCore core= new JUnitCore();
core.addListener(new MyRunListener());
core.run(MyTestClass.class);
}
Write a RunListener again. But this time extend an org.junit.runner.Runner implementation and override its run method like
#Override
public void run(RunNotifier notifier) {
notifier.addListener(new MyRunNotifier());
super.run(notifier);
}
Second approach can also be used in tests with #RunWith(MyRunner.class) annotation.
I am working with a plugin in symfony 1.4, and would like to add a listener for a task from another plugin. When the user does php symfony doctrine:build I want my plugin to run a task of its own. Where/how do I register the listener? I did not have any success with http://www.symfony-project.org/gentle-introduction/1_4/en/17-Extending-Symfony
Thank you!
Actually you can hook your code to any symfony task. Have a look at sfBaseTask::doRun method. Any task, when is executed, emits 2 events: command.pre_command and command.post_command.
Create a class to store you code, for example:
class toolkitEvents
{
static public function commandPostEventHook(sfEvent $event)
{
$task = $event->getSubject();
if ($task->getFullName() === 'doctrine:build')
{
//do stuff or call another task
}
}
and connect this method to a dispatcher when initializing your plugin:
class yourPluginConfiguration extends sfPluginConfiguration
{
public function initialize()
{
$this->dispatcher->connect('command.post_command', array('toolkitEvents', 'commandPostEventHook'));
}
I don't think there is a suitable event for this (like the cache clear one).
My suggestion would be either to accept that it needs to be two tasks, or if you use build that often, create a wrapper task to call one first then the other - doctrine:build is a good example of how to do this. Or a bash/batch script!