标签: task

在特定时刻调用 NodeJs 函数

有没有一种方法可以使用Node.Js自动化函数并在特定时刻调用它们?更准确地说,我想用 Node js 创建一个提醒。当我收到用户的日期时,我必须发送通知以提醒他/她某件事。

我知道 setTimeout() 函数,但是当我拥有大型用户数据库时,这真的是个好主意吗?

谢谢。

javascript task node.js

0
推荐指数
1
解决办法
1514
查看次数

要实现“抢占式”任务的操作系统,CPU 应支持哪些硬件功能?

例如,要实现像unix或NT这样的操作系统,支持基于时间片切换不同的任务,cpu应该有什么样的硬件支持?

intel 80286是否开始支持带有时钟中断的“抢占式”任务的执行?实现这一目标还需要哪些硬件功能?

operating-system cpu-architecture task multitasking preemptive

0
推荐指数
1
解决办法
1476
查看次数

如何在任务组中等待Intel TBB中的单个任务并杀死其他任务?

在英特尔 TBB 中,我尝试: 1. 创建一组任务 2. 让它们运行 3. 当其中一个任务完成时,我从中得到一些结果并杀死其他任务。

我怎样才能做到这一点 ?我只能看到 API 等待所有而不仅仅是单个......

谢谢。

c++ intel tbb task wait

0
推荐指数
1
解决办法
1353
查看次数

为 Django 项目中的可重用应用程序创建基于类的 Celery 任务

对于 Django 项目来说,创建基于函数的任务非常干净。只需在 django 应用程序中创建tasks.py并开始编写任务,就像这个示例一样,该示例取自官方celery文档:http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html

from __future__ import absolute_import, unicode_literals
from celery import shared_task

@shared_task
def add(x, y):
    return x + y


@shared_task
def mul(x, y):
    return x * y
Run Code Online (Sandbox Code Playgroud)

但有时基于函数的任务是紧密耦合的并且可重用性不高。所以我想创建基于类的芹菜任务,该任务记录在官方网站中。在遵循https://github.com/celery/celery/issues/3874之后,我可以创建示例任务,但我不确定它是否是创建基于类的任务的正确方法。

from __future__ import absolute_import, unicode_literals
from celery import shared_task, Task
import time
from celery import current_app


@shared_task
def add(x, y):
    time.sleep(5)
    return x + y


@shared_task
def mul(x, y):
    return x * y

# Sample class based task for testing
class AnotherTask(current_app.Task):
    name = 'tasks.another_task'
    def …
Run Code Online (Sandbox Code Playgroud)

python django task celery django-celery

0
推荐指数
1
解决办法
5948
查看次数

另一个不等待的等待

通常我不会发帖,而是阅读并找到答案。

\n\n

但这一次,尽管我发现了十几篇关于异步/等待问题的帖子,但似乎没有解决方案适合我的情况(或者我至少不明白)。

\n\n

我的代码真的很长,所以我不会把它完整地放在这里,但它看起来像这样:\n我有一个正在数据库中写入的任务:

\n\n
public async Task WatchSpool(Button buttonSend)\n{\n    LoadOptions();\n    //SpoolWatcher spoolWatcher = new SpoolWatcher(this, buttonSend);\n    SpoolWatcher spoolWatcher = new SpoolWatcher(this);\n    spoolWatcher.OnSpoolWatcherException += OnSpoolWatcherException;\n    Task thread = new Task(spoolWatcher.Run);\n    spoolWatcherMustStop = false;\n    thread.Start();\n    //spoolWatcher.Run();\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后另一个计算数据库中特定表中的记录数:

\n\n
public int CountWaitingRecords(string table)\n{\n    int WaitingRecords = 0;\n    try\n    {\n        using (SqliteConnection connexion = new SqliteConnection("Filename = spool.db"))\n        {\n            connexion.Open();\n            using (SqliteCommand cmd = new SqliteCommand("SELECT COUNT(*) AS Count FROM " + table, connexion))\n            {\n                SqliteDataReader rs = cmd.ExecuteReader();\n                rs.Read();\n\n                WaitingRecords …
Run Code Online (Sandbox Code Playgroud)

c# task async-await uwp

0
推荐指数
1
解决办法
233
查看次数

根据父任务的结果链接异步函数

我在这里想做的是,根据父任务执行,我尝试执行或取消后续的异步任务。我发现很难全神贯注于以下内容的执行并尝试以最优化的方式实现它。我正在寻找一种以最优化的方式编写此内容的方法。

另外,我很困惑为什么即使在抛出异常之后它仍然继续下一次迭代并等待任务找出抛出的异常。我找不到对此的解释。

 public static async Task<TOut> AndThen<TIn, TOut>(this Task<TIn> sourceTask, Func<TIn, Task<TOut>> sf, CancellationToken cancelToken)
 {
        return await sourceTask.ContinueWith(async st => {
            var res = await st; // Raising cancel request in here.
            cancelToken.ThrowIfCancellationRequested();
            return await sf(res);
        }, TaskContinuationOptions.NotOnFaulted & TaskContinuationOptions.NotOnCanceled).Unwrap();
 }
Run Code Online (Sandbox Code Playgroud)

c# task task-parallel-library async-await

0
推荐指数
1
解决办法
195
查看次数

在outlook中使用日历约会触发VBA宏

如何在 Outlook 中设置约会,使其通过约会提醒触发 VBA 宏?就我而言,我希望 Outlook 被安排在特定时间打开 Excel 文件。

有一些示例,但没有一个符合我的要求,因为大多数人使用 Outlook 任务而不是约会。

例如:https: //www.slipstick.com/developer/code-samples/running-outlook-macros-schedule/ 以及此Outlook 和 Excel VBA 任务计划程序

outlook vba task appointment

0
推荐指数
1
解决办法
4742
查看次数

如何允许异步任务运行给定的秒数?

所以我创建了一个任务处理程序。我想让它运行一段预定的保证时间,然后我想做一些我的事情,只有这样我才需要等待处理程序的结果。就像是:

var th = TaskCreator();
th.awaitFor(5000);
//do some work
var result = await th;
Run Code Online (Sandbox Code Playgroud)

那么异步任务如何运行给定的秒数呢?

c# task async-await

0
推荐指数
2
解决办法
514
查看次数

类型错误:“fn”必须可调用(Prefect - Python)

我开始学习一些 prefect + python,并且我从一开始就面临一个奇怪的错误,使用一个非常简单的脚本:

代码图片

我已经在两台不同的电脑上尝试过了。

python task prefect

0
推荐指数
1
解决办法
1086
查看次数

Task内部的回调会在主线程自动调用

曾几何时,在 Async/Await 出现之前,我们使用 URLSession dataTask 向服务器发出简单的请求。回调不会在主线程上自动调用,我们必须手动分派到主线程才能执行一些 UI 工作。例子:

DispatchQueue.main.async {
    // UI work
}
Run Code Online (Sandbox Code Playgroud)

忽略这一点将导致应用程序崩溃,因为我们尝试在与主队列不同的队列上更新 UI。

现在有了 Async/Await ,事情变得更容易了。我们仍然必须使用 调度到主队列MainActor

await MainActor.run {
 // UI work
}
Run Code Online (Sandbox Code Playgroud)

奇怪的是,即使我不使用MainActor任务中的代码似乎也在主线程上运行,并且更新 UI 似乎是安全的。

Task {
       let api = API(apiConfig: apiConfig)
        
       do {
              let posts = try await api.getPosts() // Checked this and the code of getPosts is running on another thread.
              self.posts = posts 
              self.tableView.reloadData()
              print(Thread.current.description)
          } catch {
              // Handle error
          }
}
Run Code Online (Sandbox Code Playgroud)

我预计我的代码会导致崩溃,因为理论上我试图更新表视图而不是从主线程,但日志显示我位于主线程上。日志print如下:

<_NSMainThread: …
Run Code Online (Sandbox Code Playgroud)

concurrency task async-await swift

0
推荐指数
1
解决办法
999
查看次数